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

Commit d577afd

Browse files
Splaktarmmalerba
authored andcommitted
feat(menu-bar): support md-prevent-menu-close on checkbox/radio items (#11710)
Fixes #11707
1 parent 952a035 commit d577afd

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/components/menuBar/js/menuBarDirective.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @restrict E
66
* @description
77
*
8-
* Menu bars are containers that hold multiple menus. They change the behavior and appearence
8+
* Menu bars are containers that hold multiple menus. They change the behavior and appearance
99
* of the `md-menu` directive to behave similar to an operating system provided menu.
1010
*
1111
* @usage
@@ -42,12 +42,17 @@
4242
*
4343
* ## Menu Bar Controls
4444
*
45-
* You may place `md-menu-items` that function as controls within menu bars.
45+
* You may place `md-menu-item`s that function as controls within menu bars.
4646
* There are two modes that are exposed via the `type` attribute of the `md-menu-item`.
4747
* `type="checkbox"` will function as a boolean control for the `ng-model` attribute of the
4848
* `md-menu-item`. `type="radio"` will function like a radio button, setting the `ngModel`
4949
* to the `string` value of the `value` attribute. If you need non-string values, you can use
50-
* `ng-value` to provide an expression (this is similar to how angular's native `input[type=radio]` works.
50+
* `ng-value` to provide an expression (this is similar to how angular's native `input[type=radio]`
51+
* works.
52+
*
53+
* If you want either to disable closing the opened menu when clicked, you can add the
54+
* `md-prevent-menu-close` attribute to the `md-menu-item`. The attribute will be forwarded to the
55+
* `button` element that is generated.
5156
*
5257
* <hljs lang="html">
5358
* <md-menu-bar>
@@ -56,11 +61,13 @@
5661
* Sample Menu
5762
* </button>
5863
* <md-menu-content>
59-
* <md-menu-item type="checkbox" ng-model="settings.allowChanges">Allow changes</md-menu-item>
64+
* <md-menu-item type="checkbox" ng-model="settings.allowChanges" md-prevent-menu-close>
65+
* Allow changes
66+
* </md-menu-item>
6067
* <md-menu-divider></md-menu-divider>
6168
* <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 1</md-menu-item>
62-
* <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 2</md-menu-item>
63-
* <md-menu-item type="radio" ng-model="settings.mode" ng-value="1">Mode 3</md-menu-item>
69+
* <md-menu-item type="radio" ng-model="settings.mode" ng-value="2">Mode 2</md-menu-item>
70+
* <md-menu-item type="radio" ng-model="settings.mode" ng-value="3">Mode 3</md-menu-item>
6471
* </md-menu-content>
6572
* </md-menu>
6673
* </md-menu-bar>

src/components/menuBar/js/menuItemDirective.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@ function MenuItemDirective($mdUtil, $mdConstant, $$mdSvgRegistry) {
1515

1616
// Note: This allows us to show the `check` icon for the md-menu-bar items.
1717
// The `md-in-menu-bar` class is set by the mdMenuBar directive.
18-
if ((type == 'checkbox' || type == 'radio') && templateEl.hasClass(inMenuBarClass)) {
18+
if ((type === 'checkbox' || type === 'radio') && templateEl.hasClass(inMenuBarClass)) {
1919
var text = templateEl[0].textContent;
2020
var buttonEl = angular.element('<md-button type="button"></md-button>');
2121
var iconTemplate = '<md-icon md-svg-src="' + $$mdSvgRegistry.mdChecked + '"></md-icon>';
2222

2323
buttonEl.html(text);
2424
buttonEl.attr('tabindex', '0');
2525

26+
if (angular.isDefined(templateAttrs.mdPreventMenuClose)) {
27+
buttonEl.attr('md-prevent-menu-close', templateAttrs.mdPreventMenuClose);
28+
}
29+
2630
templateEl.html('');
2731
templateEl.append(angular.element(iconTemplate));
2832
templateEl.append(buttonEl);
2933
templateEl.addClass('md-indent').removeClass(inMenuBarClass);
3034

31-
setDefault('role', type == 'checkbox' ? 'menuitemcheckbox' : 'menuitemradio', buttonEl);
35+
setDefault('role', type === 'checkbox' ? 'menuitemcheckbox' : 'menuitemradio', buttonEl);
3236
moveAttrToButton('ng-disabled');
3337

3438
} else {

0 commit comments

Comments
 (0)