@@ -112,6 +112,60 @@ describe('createMenu', () => {
112112 expect ( menu . navigationInput . current . direction ) . toBe ( 'forward' ) ;
113113 } ) ;
114114
115+ it ( 'syncs viewport size when opening after the root view connects later than the menu host' , async ( ) => {
116+ const { menu } = createTestMenu ( ) ;
117+ const content = document . createElement ( 'div' ) ;
118+ const rootView = document . createElement ( 'div' ) ;
119+
120+ content . style . setProperty ( 'min-width' , '11rem' ) ;
121+ document . body . append ( content ) ;
122+ menu . setContentElement ( content ) ;
123+
124+ expect ( content . style . getPropertyValue ( '--media-menu-width' ) ) . toBe ( '' ) ;
125+ expect ( content . style . getPropertyValue ( '--media-menu-height' ) ) . toBe ( '' ) ;
126+
127+ rootView . setAttribute ( 'data-menu-view' , '' ) ;
128+ rootView . setAttribute ( 'data-menu-view-id' , 'root' ) ;
129+ rootView . textContent = 'Speed\nCaptions' ;
130+
131+ function isMeasuringOpenRoot ( ) : boolean {
132+ return (
133+ rootView . hasAttribute ( 'data-open' ) &&
134+ rootView . style . getPropertyValue ( 'display' ) === 'block' &&
135+ rootView . style . getPropertyValue ( 'width' ) === 'max-content'
136+ ) ;
137+ }
138+
139+ rootView . getBoundingClientRect = vi . fn ( ( ) =>
140+ isMeasuringOpenRoot ( )
141+ ? { width : 180 , height : 74 , top : 0 , left : 0 , right : 180 , bottom : 74 , x : 0 , y : 0 , toJSON : ( ) => ( { } ) }
142+ : { width : 0 , height : 0 , top : 0 , left : 0 , right : 0 , bottom : 0 , x : 0 , y : 0 , toJSON : ( ) => ( { } ) }
143+ ) ;
144+
145+ Object . defineProperty ( rootView , 'scrollWidth' , {
146+ configurable : true ,
147+ get : ( ) => ( isMeasuringOpenRoot ( ) ? 180 : 0 ) ,
148+ } ) ;
149+
150+ Object . defineProperty ( rootView , 'scrollHeight' , {
151+ configurable : true ,
152+ get : ( ) => ( isMeasuringOpenRoot ( ) ? 74 : 0 ) ,
153+ } ) ;
154+
155+ content . append ( rootView ) ;
156+
157+ menu . open ( ) ;
158+
159+ await vi . waitFor ( ( ) => {
160+ expect ( content . style . getPropertyValue ( '--media-menu-width' ) ) . toBe ( '180px' ) ;
161+ expect ( content . style . getPropertyValue ( '--media-menu-height' ) ) . toBe ( '74px' ) ;
162+ } ) ;
163+
164+ menu . setContentElement ( null ) ;
165+ menu . destroy ( ) ;
166+ content . remove ( ) ;
167+ } ) ;
168+
115169 it ( 'resets the root panel transition after close when a submenu was open' , async ( ) => {
116170 const onOpenChangeComplete = vi . fn ( ) ;
117171 const { menu } = createTestMenu ( { onOpenChangeComplete } ) ;
0 commit comments