Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(modal): restore broken stacked modals
Browse files Browse the repository at this point in the history
Closes #6103
Closes #6104
  • Loading branch information
fpipita authored and wesleycho committed Jul 21, 2016
1 parent 6bfb4cd commit c61d16a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
'size': modal.size,
'index': topModalIndex,
'animate': 'animate',
'ng-style': '{\'z-index\': 1050 + index*10, display: \'block\'}',
'ng-style': '{\'z-index\': 1050 + $$topModalIndex*10, display: \'block\'}',
'tabindex': -1,
'uib-modal-animation-class': 'fade',
'modal-in-class': 'in'
Expand All @@ -521,6 +521,11 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p
}

appendToElement.addClass(modalBodyClass);
if (modal.scope) {
// we need to explicitly add the modal index to the modal scope
// because it is needed by ngStyle to compute the zIndex property.
modal.scope.$$topModalIndex = topModalIndex;
}
$animate.enter($compile(angularDomEl)(modal.scope), appendToElement);

openedWindows.top().value.modalDomEl = angularDomEl;
Expand Down
98 changes: 98 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,104 @@ describe('$uibModal', function() {
expect(modal3Index).toEqual(2);
expect(modal2Index).toBeLessThan(modal3Index);
});

it('should have top modal with highest z-index', function() {
var modal2zIndex = null;
var modal3zIndex = null;

var modal1Instance = {
result: $q.defer(),
opened: $q.defer(),
closed: $q.defer(),
rendered: $q.defer(),
close: function(result) {
return $uibModalStack.close(modal1Instance, result);
},
dismiss: function(reason) {
return $uibModalStack.dismiss(modal1Instance, reason);
}
};
var modal2Instance = {
result: $q.defer(),
opened: $q.defer(),
closed: $q.defer(),
rendered: $q.defer(),
close: function(result) {
return $uibModalStack.close(modal2Instance, result);
},
dismiss: function(reason) {
return $uibModalStack.dismiss(modal2Instance, reason);
}
};
var modal3Instance = {
result: $q.defer(),
opened: $q.defer(),
closed: $q.defer(),
rendered: $q.defer(),
close: function(result) {
return $uibModalStack.close(modal3Instance, result);
},
dismiss: function(reason) {
return $uibModalStack.dismiss(modal3Instance, reason);
}
};

var modal1 = $uibModalStack.open(modal1Instance, {
appendTo: angular.element(document.body),
scope: $rootScope.$new(),
deferred: modal1Instance.result,
renderDeferred: modal1Instance.rendered,
closedDeferred: modal1Instance.closed,
content: '<div>Modal1</div>'
});

$rootScope.$digest();
$animate.flush();
expect($document).toHaveModalsOpen(1);

expect(+$uibModalStack.getTop().value.modalDomEl[0].style.zIndex).toBe(1050);

var modal2 = $uibModalStack.open(modal2Instance, {
appendTo: angular.element(document.body),
scope: $rootScope.$new(),
deferred: modal2Instance.result,
renderDeferred: modal2Instance.rendered,
closedDeferred: modal2Instance.closed,
content: '<div>Modal2</div>'
});

modal2Instance.rendered.promise.then(function() {
modal2zIndex = +$uibModalStack.getTop().value.modalDomEl[0].style.zIndex;
});

$rootScope.$digest();
$animate.flush();
expect($document).toHaveModalsOpen(2);

expect(modal2zIndex).toBe(1060);
close(modal1Instance);
expect($document).toHaveModalsOpen(1);

var modal3 = $uibModalStack.open(modal3Instance, {
appendTo: angular.element(document.body),
scope: $rootScope.$new(),
deferred: modal3Instance.result,
renderDeferred: modal3Instance.rendered,
closedDeferred: modal3Instance.closed,
content: '<div>Modal3</div>'
});

modal3Instance.rendered.promise.then(function() {
modal3zIndex = +$uibModalStack.getTop().value.modalDomEl[0].style.zIndex;
});

$rootScope.$digest();
$animate.flush();
expect($document).toHaveModalsOpen(2);

expect(modal3zIndex).toBe(1070);
expect(modal2zIndex).toBeLessThan(modal3zIndex);
});
});

describe('modal.closing event', function() {
Expand Down

6 comments on commit c61d16a

@e-cloud
Copy link

@e-cloud e-cloud commented on c61d16a Aug 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a blocking bug, should it be release ASAP?

@icfantv
Copy link
Contributor

@icfantv icfantv commented on c61d16a Aug 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and probably, but both @wesleycho and I are out of town and the rest of the team is heavily focused on ng-bootstrap.

@wesleycho
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been out on a trip to Europe for the past 1 1/2 weeks - I don't get back until Sunday/Monday, and I may need a day or two after. I do intend on getting to work on the issues that have piled up since then though.

@icfantv
Copy link
Contributor

@icfantv icfantv commented on c61d16a Aug 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@e-cloud this has been released, FYI. 2.0.1.

@e-cloud
Copy link

@e-cloud e-cloud commented on c61d16a Aug 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks for your commitment.

@pencilcheck
Copy link

@pencilcheck pencilcheck commented on c61d16a Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on 2.2.0 and this issue still persist


nvm, it fixed itself

Please sign in to comment.