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

Commit e9bcec1

Browse files
trevorhreedrschmukler
authored andcommitted
feat(mdMenu): add md-prevent-menu-close
closes #5457, closes #4334
1 parent 818652d commit e9bcec1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/components/menu/js/menuDirective.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@
102102
* <!-- menu-content -->
103103
* </md-menu>
104104
* </hljs>
105+
106+
* ### Preventing close
107+
*
108+
* Sometimes you would like to be able to click on a menu item without having the menu
109+
* close. To do this, ngMaterial exposes the `md-prevent-menu-close` attribute which
110+
* can be added to a button inside a menu to stop the menu from automatically closing.
111+
* You can then close the menu programatically by injecting `$mdMenu` and calling
112+
* `$mdMenu.hide()`.
113+
*
114+
* <hljs lang="html">
115+
* <md-menu-item>
116+
* <md-button ng-click="doSomething()" aria-label="Do something" md-prevent-menu-close="md-prevent-menu-close">
117+
* <md-icon md-menu-align-target md-svg-icon="call:phone"></md-icon>
118+
* Do Something
119+
* </md-button>
120+
* </md-menu-item>
121+
* </hljs>
105122
*
106123
* @usage
107124
* <hljs lang="html">

src/components/menu/js/menuServiceProvider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ function MenuProvider($$interimElementProvider) {
291291
// there is an ng-click and that the ng-click is not disabled
292292
do {
293293
if (target == opts.menuContentEl[0]) return;
294-
if (hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) ||
295-
target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') {
294+
if ((hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) ||
295+
target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') && !hasAnyAttribute(target, ['md-prevent-menu-close'])) {
296296
var closestMenu = $mdUtil.getClosest(target, 'MD-MENU');
297297
if (!target.hasAttribute('disabled') && (!closestMenu || closestMenu == opts.parent[0])) {
298298
close();

0 commit comments

Comments
 (0)