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

Commit

Permalink
feat(mdMenu): add md-prevent-menu-close
Browse files Browse the repository at this point in the history
closes #5457, closes #4334
  • Loading branch information
trevorhreed authored and rschmukler committed Nov 9, 2015
1 parent 818652d commit e9bcec1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/components/menu/js/menuDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@
* <!-- menu-content -->
* </md-menu>
* </hljs>
* ### 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()`.
*
* <hljs lang="html">
* <md-menu-item>
* <md-button ng-click="doSomething()" aria-label="Do something" md-prevent-menu-close="md-prevent-menu-close">

This comment has been minimized.

Copy link
@topherfangio

topherfangio Nov 9, 2015

Contributor

Shouldn't this just be one of the following?

  1. An attribute <md-button md-prevent-menu-close>
  2. Or perhaps <md-button md-prevent-menu-close="true">

I feel like having it set to the string is confusing. Since the code doesn't actually check the value, I think option 1 would be more clear on it's capabilities.

* <md-icon md-menu-align-target md-svg-icon="call:phone"></md-icon>
* Do Something
* </md-button>
* </md-menu-item>
* </hljs>
*
* @usage
* <hljs lang="html">
Expand Down
4 changes: 2 additions & 2 deletions src/components/menu/js/menuServiceProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e9bcec1

Please sign in to comment.