This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Commit 8609318 1 parent 86e9bf0 commit 8609318 Copy full SHA for 8609318
File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -284,7 +284,12 @@ function MenuProvider($$interimElementProvider) {
284
284
285
285
if ( positionMode . top == 'target' || positionMode . left == 'target' || positionMode . left == 'target-right' ) {
286
286
// 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 ;
288
293
alignTarget = alignTarget . querySelector ( '[md-menu-align-target]' ) || alignTarget ;
289
294
alignTargetRect = alignTarget . getBoundingClientRect ( ) ;
290
295
@@ -363,6 +368,18 @@ function MenuProvider($$interimElementProvider) {
363
368
pos . top = Math . max ( Math . min ( pos . top , bounds . bottom - containerNode . offsetHeight ) , bounds . top ) ;
364
369
pos . left = Math . max ( Math . min ( pos . left , bounds . right - containerNode . offsetWidth ) , bounds . left ) ;
365
370
}
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
+ }
366
383
}
367
384
}
368
385
}
You can’t perform that action at this time.
0 commit comments