diff --git a/src/modal/modal.js b/src/modal/modal.js index 88aee826d9..a4668aed22 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -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' @@ -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; diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index 84fd7cf381..2ea386c8e2 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -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: '