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

Commit 60e2393

Browse files
Florian Scholzjosephperrott
authored andcommitted
fix(md-menu): allow nested md-menu-content (#11103)
1 parent 7e5b7f4 commit 60e2393

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/components/menu/js/menuDirective.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ function MenuDirective($mdUtil) {
179179
templateElement.addClass('md-menu');
180180

181181
var triggerEl = templateElement.children()[0];
182-
var contentEl = templateElement.children()[1];
183-
184182
var prefixer = $mdUtil.prefixer();
185183

186184
if (!prefixer.hasAttribute(triggerEl, 'ng-click')) {
@@ -198,8 +196,8 @@ function MenuDirective($mdUtil) {
198196
throw Error(INVALID_PREFIX + 'Expected the menu to have a trigger element.');
199197
}
200198

201-
if (!contentEl || contentEl.nodeName !== 'MD-MENU-CONTENT') {
202-
throw Error(INVALID_PREFIX + 'Expected the menu to contain a `md-menu-content` element.');
199+
if (templateElement.children().length !== 2) {
200+
throw Error(INVALID_PREFIX + 'Expected two children elements. The second element must have a `md-menu-content` element.');
203201
}
204202

205203
// Default element for ARIA attributes has the ngClick or ngMouseenter expression

src/components/menu/menu.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ describe('material.components.menu', function() {
5151
expect(createInvalidMenu).toThrow();
5252
}));
5353

54+
it('nested md-menu-content should be allowed', inject(function($compile, $rootScope) {
55+
function createValidMenu() {
56+
$compile(
57+
'<md-menu>' +
58+
' <button ng-click="null">Trigger Element</button>' +
59+
' <some-custom-element>' +
60+
' <md-menu-content>Menu Content</md-menu-content>' +
61+
' </some-custom-element>' +
62+
'</md-menu>'
63+
)($rootScope);
64+
}
65+
66+
expect(createValidMenu).not.toThrow();
67+
}));
68+
5469
it('specifies button type', inject(function($compile, $rootScope) {
5570
var menu = setup()[0];
5671
expect(menu.firstElementChild.getAttribute('type')).toBe('button');

0 commit comments

Comments
 (0)