From e9bcec1bc42ff7a94553931310f6450e5eb6acda Mon Sep 17 00:00:00 2001 From: Trevor Date: Fri, 30 Oct 2015 09:14:46 -0600 Subject: [PATCH] feat(mdMenu): add md-prevent-menu-close closes #5457, closes #4334 --- src/components/menu/js/menuDirective.js | 17 +++++++++++++++++ src/components/menu/js/menuServiceProvider.js | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/menu/js/menuDirective.js b/src/components/menu/js/menuDirective.js index 5f6227eb7f3..a80614397ed 100644 --- a/src/components/menu/js/menuDirective.js +++ b/src/components/menu/js/menuDirective.js @@ -102,6 +102,23 @@ * * * + + * ### Preventing close + * + * Sometimes you would like to be able to click on a menu item without having the menu + * close. To do this, ngMaterial exposes the `md-prevent-menu-close` attribute which + * can be added to a button inside a menu to stop the menu from automatically closing. + * You can then close the menu programatically by injecting `$mdMenu` and calling + * `$mdMenu.hide()`. + * + * + * + * + * + * Do Something + * + * + * * * @usage * diff --git a/src/components/menu/js/menuServiceProvider.js b/src/components/menu/js/menuServiceProvider.js index ee209600930..8c936b3687d 100644 --- a/src/components/menu/js/menuServiceProvider.js +++ b/src/components/menu/js/menuServiceProvider.js @@ -291,8 +291,8 @@ function MenuProvider($$interimElementProvider) { // there is an ng-click and that the ng-click is not disabled do { if (target == opts.menuContentEl[0]) return; - if (hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) || - target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') { + if ((hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) || + target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') && !hasAnyAttribute(target, ['md-prevent-menu-close'])) { var closestMenu = $mdUtil.getClosest(target, 'MD-MENU'); if (!target.hasAttribute('disabled') && (!closestMenu || closestMenu == opts.parent[0])) { close();