Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(menu): cleanup click listeners on close
Browse files Browse the repository at this point in the history
  • Loading branch information
rschmukler committed Jul 16, 2015
1 parent e9b4de5 commit 9b57c2e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/menu/menu-interim-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function MenuProvider($$interimElementProvider) {
return animator
.waitTransitionEnd(element, {timeout: 370})
.then( function(response) {
activateInteraction();
opts.cleanupInteraction = activateInteraction();
return response;
});

Expand Down Expand Up @@ -149,7 +149,7 @@ function MenuProvider($$interimElementProvider) {
});

// Close menu on menu item click, if said menu-item is not disabled
opts.menuContentEl[0].addEventListener('click', function(e) {
var captureClickListener = function(e) {
var target = e.target;
// Traverse up the event until we get to the menuContentEl to see if
// there is an ng-click and that the ng-click is not disabled
Expand Down Expand Up @@ -181,12 +181,20 @@ function MenuProvider($$interimElementProvider) {
}
return false;
}
}, true);
};
opts.menuContentEl[0].addEventListener('click', captureClickListener, true);

// kick off initial focus in the menu on the first element
var focusTarget = opts.menuContentEl[0].querySelector('[md-menu-focus-target]');
if (!focusTarget) focusTarget = opts.menuContentEl[0].firstElementChild.firstElementChild;
focusTarget.focus();

return function cleanupInteraction() {
element.removeClass('md-clickable');
opts.backdrop.off('click');
opts.menuContentEl.off('keydown');
opts.menuContentEl[0].removeEventListener('click', captureClickListener, true);
};
}
}

Expand Down Expand Up @@ -239,8 +247,9 @@ function MenuProvider($$interimElementProvider) {
*/
function onRemove(scope, element, opts) {
opts.isRemoved = true;
element.addClass('md-leave')
.removeClass('md-clickable');
element.addClass('md-leave');

opts.cleanupInteraction();

// Disable resizing handlers
angular.element($window).off('resize', opts.resizeFn);
Expand Down

0 comments on commit 9b57c2e

Please sign in to comment.