@@ -116,10 +116,10 @@ export const ItemsMixin = (superClass) =>
116116 /** @protected */
117117 __forwardFocus ( ) {
118118 const overlay = this . _overlayElement ;
119- const child = overlay . getFirstChild ( ) ;
119+ const child = overlay . _contentRoot . firstElementChild ;
120120 // If parent item is not focused, do not focus submenu
121121 if ( overlay . parentOverlay ) {
122- const parent = overlay . parentOverlay . querySelector ( '[expanded]' ) ;
122+ const parent = overlay . parentOverlay . _contentRoot . querySelector ( '[expanded]' ) ;
123123 if ( parent && parent . hasAttribute ( 'focused' ) && child ) {
124124 child . focus ( ) ;
125125 } else {
@@ -253,10 +253,20 @@ export const ItemsMixin = (superClass) =>
253253 // Open a submenu on click event when a touch device is used.
254254 // On desktop, a submenu opens on hover.
255255 overlay . addEventListener ( isTouch ? 'click' : 'mouseover' , ( event ) => {
256+ // Ignore events from the submenus
257+ if ( event . composedPath ( ) . includes ( this . _subMenu ) ) {
258+ return ;
259+ }
260+
256261 this . __showSubMenu ( event ) ;
257262 } ) ;
258263
259264 overlay . addEventListener ( 'keydown' , ( event ) => {
265+ // Ignore events from the submenus
266+ if ( event . composedPath ( ) . includes ( this . _subMenu ) ) {
267+ return ;
268+ }
269+
260270 const { key } = event ;
261271 const isRTL = this . __isRTL ;
262272
@@ -288,10 +298,6 @@ export const ItemsMixin = (superClass) =>
288298 subMenu . _modeless = true ;
289299 subMenu . openOn = 'opensubmenu' ;
290300
291- // Sub-menu doesn't have a target to wrap,
292- // so there is no need to keep it visible.
293- subMenu . setAttribute ( 'hidden' , '' ) ;
294-
295301 // Close sub-menu when the parent menu closes.
296302 this . addEventListener ( 'opened-changed' , ( event ) => {
297303 if ( ! event . detail . value ) {
@@ -366,7 +372,7 @@ export const ItemsMixin = (superClass) =>
366372 const { children } = item . _item ;
367373
368374 // Check if the sub-menu was focused before closing it.
369- const child = subMenu . _overlayElement . getFirstChild ( ) ;
375+ const child = subMenu . _overlayElement . _contentRoot . firstElementChild ;
370376 const isSubmenuFocused = child && child . focused ;
371377
372378 if ( subMenu . items !== children ) {
@@ -394,7 +400,7 @@ export const ItemsMixin = (superClass) =>
394400
395401 /** @protected */
396402 __getListBox ( ) {
397- return this . _overlayElement . querySelector ( `${ this . _tagNamePrefix } -list-box` ) ;
403+ return this . _overlayElement . _contentRoot . querySelector ( `${ this . _tagNamePrefix } -list-box` ) ;
398404 }
399405
400406 /**
@@ -406,15 +412,12 @@ export const ItemsMixin = (superClass) =>
406412 __itemsRenderer ( root , menu ) {
407413 this . __initMenu ( root , menu ) ;
408414
409- const subMenu = root . querySelector ( this . constructor . is ) ;
410- subMenu . closeOn = menu . closeOn ;
411-
412- const listBox = this . __getListBox ( ) ;
413- listBox . innerHTML = '' ;
415+ this . _subMenu . closeOn = menu . closeOn ;
416+ this . _listBox . innerHTML = '' ;
414417
415418 menu . items . forEach ( ( item ) => {
416419 const component = this . __createComponent ( item ) ;
417- listBox . appendChild ( component ) ;
420+ this . _listBox . appendChild ( component ) ;
418421 } ) ;
419422 }
420423
@@ -455,8 +458,9 @@ export const ItemsMixin = (superClass) =>
455458 root . appendChild ( listBox ) ;
456459
457460 const subMenu = this . __initSubMenu ( ) ;
461+ subMenu . slot = 'submenu' ;
458462 this . _subMenu = subMenu ;
459- root . appendChild ( subMenu ) ;
463+ this . appendChild ( subMenu ) ;
460464
461465 requestAnimationFrame ( ( ) => {
462466 this . __openListenerActive = true ;
0 commit comments