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

Commit

Permalink
fix(modal): fix modal rendered promise
Browse files Browse the repository at this point in the history
- Fix timing of rendered promise to be after animation is complete

Closes #5401
Fixes #5331
  • Loading branch information
wesleycho committed Feb 3, 2016
1 parent e283cea commit 42fb486
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])


$q.when(animationPromise).then(function() {
// Notify {@link $modalStack} that modal is rendered.
var modal = $modalStack.getTop();
if (modal) {
$modalStack.modalRendered(modal.key);
}

/**
* If something within the freshly-opened modal already has focus (perhaps via a
* directive that causes focus). then no need to try and focus anything.
Expand All @@ -222,12 +228,6 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
}
}
});

// Notify {@link $modalStack} that modal is rendered.
var modal = $modalStack.getTop();
if (modal) {
$modalStack.modalRendered(modal.key);
}
});
}
};
Expand Down
36 changes: 36 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,42 @@ describe('$uibModal', function() {
close(modalInstance, 'closing in test', true);
});

it('should resolve rendered promise when animation is complete', function() {
var modalInstance = {
result: $q.defer(),
opened: $q.defer(),
closed: $q.defer(),
rendered: $q.defer(),
close: function (result) {
return $uibModalStack.close(modalInstance, result);
},
dismiss: function (reason) {
return $uibModalStack.dismiss(modalInstance, reason);
}
};
var rendered = false;
modalInstance.rendered.promise.then(function() {
rendered = true;
});

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

$rootScope.$digest();

expect(rendered).toBe(false);

$animate.flush();

expect(rendered).toBe(true);
});

it('should not throw an exception on a second dismiss', function() {
var modal = open({template: '<div>Content</div>'});

Expand Down

0 comments on commit 42fb486

Please sign in to comment.