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

Commit

Permalink
fix(menu): fix menu positioning when using display:none items
Browse files Browse the repository at this point in the history
closes #3444
  • Loading branch information
rschmukler committed Jul 12, 2015
1 parent 86e9bf0 commit 8609318
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/menu/menu-interim-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ function MenuProvider($$interimElementProvider) {

if (positionMode.top == 'target' || positionMode.left == 'target' || positionMode.left == 'target-right') {
// TODO: Allow centering on an arbitrary node, for now center on first menu-item's child
alignTarget = openMenuNode.firstElementChild.firstElementChild || openMenuNode.firstElementChild;
alignTarget = firstVisibleChild();
if (!alignTarget) {
throw Error('Error positioning menu. No visible children.');
}

alignTarget = alignTarget.firstElementChild || alignTarget;
alignTarget = alignTarget.querySelector('[md-menu-align-target]') || alignTarget;
alignTargetRect = alignTarget.getBoundingClientRect();

Expand Down Expand Up @@ -363,6 +368,18 @@ function MenuProvider($$interimElementProvider) {
pos.top = Math.max(Math.min(pos.top, bounds.bottom - containerNode.offsetHeight), bounds.top);
pos.left = Math.max(Math.min(pos.left, bounds.right - containerNode.offsetWidth), bounds.left);
}

/**
* Gets the first visible child in the openMenuNode
* Necessary incase menu nodes are being dynamically hidden
*/
function firstVisibleChild() {
for (var i = 0; i < openMenuNode.children.length; ++i) {
if (window.getComputedStyle(openMenuNode.children[i]).display != 'none') {
return openMenuNode.children[i];
}
}
}
}
}
}

0 comments on commit 8609318

Please sign in to comment.