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

fix(modal): fix modal rendered promise #5401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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