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

Commit

Permalink
fix(dialog): register close listeners before animation
Browse files Browse the repository at this point in the history
* Registering the close listeners before the animation has started improves the UX.
  If the user presses escape before the dialog is actually open, it feels like a freeze and non-response.

Fixes #9096.

Closes #9120
  • Loading branch information
devversion authored and ThomasBurleson committed Jul 24, 2016
1 parent 0356bed commit b875dc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/dialog/dialog.js
Expand Up @@ -707,10 +707,10 @@ function MdDialogProvider($$interimElementProvider) {
captureParentAndFromToElements(options);
configureAria(dialogElement, options);
showBackdrop(scope, element, options);
activateListeners(element, options);

return dialogPopIn(element, options)
.then(function() {
activateListeners(element, options);
lockScreenReader(element, options);
warnDeprecatedActions();
focusOnOpen();
Expand Down
25 changes: 25 additions & 0 deletions src/components/dialog/dialog.spec.js
Expand Up @@ -979,6 +979,31 @@ describe('$mdDialog', function() {
expect(parent.find('md-dialog').length).toBe(0);
}));

it('should close on escape before the animation started',
inject(function($mdDialog, $rootScope, $rootElement, $timeout, $animate, $mdConstant) {
var parent = angular.element('<div>');

$mdDialog.show({
template: '<md-dialog></md-dialog>',
parent: parent,
escapeToClose: true
});

$rootScope.$apply();

expect(parent.find('md-dialog').length).toBe(1);

parent.triggerHandler({
type: 'keydown',
keyCode: $mdConstant.KEY_CODE.ESCAPE
});
$timeout.flush();

runAnimation();

expect(parent.find('md-dialog').length).toBe(0);
}));

it('should escapeToClose == false', inject(function($mdDialog, $rootScope, $rootElement, $timeout, $animate, $mdConstant) {
var parent = angular.element('<div>');
$mdDialog.show({
Expand Down

0 comments on commit b875dc5

Please sign in to comment.