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

Commit 560474f

Browse files
devversionThomasBurleson
authored andcommitted
fix(menu): type checkbox should not affect a normal menu item.
* Currently we always wrap the menu-item content inside of a button, if the menu-item has an attribute with `type[checkbox|radio]`. This logic was originally designed for the `md-menu-bar` component, and not for the normal `md-menu`. This caused confusion for developers and should be removed. * Also removed a part of code, which was a duplicate and even not reachable, because the same code returned / exited above. Fixes #8110 Closes #8117
1 parent da02ea2 commit 560474f

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

src/components/menu/js/menuServiceProvider.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,6 @@ function MenuProvider($$interimElementProvider) {
318318
}
319319
}
320320

321-
opts.menuContentEl[0].addEventListener('click', captureClickListener, true);
322-
323-
return function cleanupInteraction() {
324-
element.removeClass('_md-clickable');
325-
opts.menuContentEl.off('keydown');
326-
opts.menuContentEl[0].removeEventListener('click', captureClickListener, true);
327-
};
328321
}
329322
}
330323

src/components/menuBar/js/menuItemDirective.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ angular
44
.directive('mdMenuItem', MenuItemDirective);
55

66
/* @ngInject */
7-
function MenuItemDirective() {
7+
function MenuItemDirective($mdUtil) {
88
return {
99
require: ['mdMenuItem', '?ngModel'],
1010
priority: 210, // ensure that our post link runs after ngAria
1111
compile: function(templateEl, templateAttrs) {
12-
if (templateAttrs.type == 'checkbox' || templateAttrs.type == 'radio') {
12+
13+
// Note: This allows us to show the `check` icon for the md-menu-bar items.
14+
if (isInsideMenuBar() && (templateAttrs.type == 'checkbox' || templateAttrs.type == 'radio')) {
1315
var text = templateEl[0].textContent;
1416
var buttonEl = angular.element('<md-button type="button"></md-button>');
1517
buttonEl.html(text);
@@ -24,7 +26,7 @@ function MenuItemDirective() {
2426
angular.forEach(['ng-disabled'], moveAttrToButton);
2527

2628
} else {
27-
setDefault('role', 'menuitem', templateEl[0].querySelector('md-button,button,a'));
29+
setDefault('role', 'menuitem', templateEl[0].querySelector('md-button, button, a'));
2830
}
2931

3032

@@ -51,6 +53,10 @@ function MenuItemDirective() {
5153
templateEl[0].removeAttribute(attr);
5254
}
5355
}
56+
57+
function isInsideMenuBar() {
58+
return !!$mdUtil.getClosest(templateEl, 'md-menu-bar', true);
59+
}
5460
},
5561
controller: 'MenuItemController'
5662
};

src/components/menuBar/menu-bar.spec.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,18 @@ describe('material.components.menuBar', function() {
342342
function setup(attrs) {
343343
attrs = attrs || '';
344344

345-
var template = '<md-menu-item type="checkbox" ' + attrs + '>Test Item</md-menu-item>'
345+
var template = '<md-menu-item type="checkbox" ' + attrs + '>Test Item</md-menu-item>';
346346

347347
var checkboxMenuItem;
348348
inject(function($compile, $rootScope) {
349-
checkboxMenuItem = $compile(template)($rootScope);
349+
// We need to have a `md-menu-bar` as a parent of our menu item, because the menu-item
350+
// is only wrapping and indenting the content if it's inside of a menu bar.
351+
var menuBarMock = angular.element('<md-menu-bar>');
352+
var itemEl = angular.element(template);
353+
354+
menuBarMock.append(itemEl);
355+
checkboxMenuItem = $compile(itemEl)($rootScope);
356+
350357
$rootScope.$digest();
351358
});
352359
return checkboxMenuItem;
@@ -398,11 +405,18 @@ describe('material.components.menuBar', function() {
398405
function setup(attrs) {
399406
attrs = attrs || '';
400407

401-
var template = '<md-menu-item type="radio" ' + attrs + '>Test Item</md-menu-item>'
408+
var template = '<md-menu-item type="radio" ' + attrs + '>Test Item</md-menu-item>';
402409

403410
var radioMenuItem;
404411
inject(function($compile, $rootScope) {
405-
radioMenuItem = $compile(template)($rootScope);
412+
// We need to have a `md-menu-bar` as a parent of our menu item, because the menu-item
413+
// is only wrapping and indenting the content if it's inside of a menu bar.
414+
var menuBarMock = angular.element('<md-menu-bar>');
415+
var itemEl = angular.element(template);
416+
417+
menuBarMock.append(itemEl);
418+
radioMenuItem = $compile(itemEl)($rootScope);
419+
406420
$rootScope.$digest();
407421
});
408422
return radioMenuItem;

0 commit comments

Comments
 (0)