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

Commit 8609318

Browse files
committed
fix(menu): fix menu positioning when using display:none items
closes #3444
1 parent 86e9bf0 commit 8609318

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/components/menu/menu-interim-element.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ function MenuProvider($$interimElementProvider) {
284284

285285
if (positionMode.top == 'target' || positionMode.left == 'target' || positionMode.left == 'target-right') {
286286
// TODO: Allow centering on an arbitrary node, for now center on first menu-item's child
287-
alignTarget = openMenuNode.firstElementChild.firstElementChild || openMenuNode.firstElementChild;
287+
alignTarget = firstVisibleChild();
288+
if (!alignTarget) {
289+
throw Error('Error positioning menu. No visible children.');
290+
}
291+
292+
alignTarget = alignTarget.firstElementChild || alignTarget;
288293
alignTarget = alignTarget.querySelector('[md-menu-align-target]') || alignTarget;
289294
alignTargetRect = alignTarget.getBoundingClientRect();
290295

@@ -363,6 +368,18 @@ function MenuProvider($$interimElementProvider) {
363368
pos.top = Math.max(Math.min(pos.top, bounds.bottom - containerNode.offsetHeight), bounds.top);
364369
pos.left = Math.max(Math.min(pos.left, bounds.right - containerNode.offsetWidth), bounds.left);
365370
}
371+
372+
/**
373+
* Gets the first visible child in the openMenuNode
374+
* Necessary incase menu nodes are being dynamically hidden
375+
*/
376+
function firstVisibleChild() {
377+
for (var i = 0; i < openMenuNode.children.length; ++i) {
378+
if (window.getComputedStyle(openMenuNode.children[i]).display != 'none') {
379+
return openMenuNode.children[i];
380+
}
381+
}
382+
}
366383
}
367384
}
368385
}

0 commit comments

Comments
 (0)