@@ -12,9 +12,9 @@ const attachedInstances = new Set();
1212 * @private
1313 */
1414const getAttachedInstances = ( ) =>
15- [ ...attachedInstances ]
16- . filter ( ( el ) => el instanceof HTMLElement && el . _hasOverlayStackMixin && ! el . hasAttribute ( 'closing' ) )
17- . sort ( ( a , b ) => a . __zIndex - b . __zIndex || 0 ) ;
15+ [ ...attachedInstances ] . filter (
16+ ( el ) => el instanceof HTMLElement && el . _hasOverlayStackMixin && ! el . hasAttribute ( 'closing' ) ,
17+ ) ;
1818
1919/**
2020 * Returns all attached overlay instances excluding notification container,
@@ -87,16 +87,27 @@ export const OverlayStackMixin = (superClass) =>
8787 * Brings the overlay as visually the frontmost one.
8888 */
8989 bringToFront ( ) {
90+ // Update z-index to be the highest among all attached overlays
91+ // TODO: Can be removed after switching all overlays to be based on native popover
9092 let zIndex = '' ;
9193 const frontmost = getAttachedInstances ( )
9294 . filter ( ( o ) => o !== this )
9395 . pop ( ) ;
9496 if ( frontmost ) {
95- const frontmostZIndex = frontmost . __zIndex ;
97+ const frontmostZIndex = parseFloat ( getComputedStyle ( frontmost ) . zIndex ) ;
9698 zIndex = frontmostZIndex + 1 ;
9799 }
98100 this . style . zIndex = zIndex ;
99- this . __zIndex = zIndex || parseFloat ( getComputedStyle ( this ) . zIndex ) ;
101+
102+ // Update stacking order of native popover-based overlays
103+ if ( this . matches ( ':popover-open' ) ) {
104+ this . hidePopover ( ) ;
105+ this . showPopover ( ) ;
106+ }
107+
108+ // Update order of attached instances
109+ this . _removeAttachedInstance ( ) ;
110+ this . _appendAttachedInstance ( ) ;
100111
101112 // If there is a nested overlay, call `bringToFront()` for it as well.
102113 if ( overlayMap . has ( this ) ) {
0 commit comments