@@ -337,6 +337,125 @@ describe('overflow', () => {
337337 } ) ;
338338 } ) ;
339339
340+ describe ( 'layout combinations' , ( ) => {
341+ const items = [ { text : 'Item 1' } , { text : 'Item 2' } , { text : 'Item 3' } , { text : 'Item 4' } , { text : 'Item 5' } ] ;
342+
343+ async function initMenuBar ( container ) {
344+ const menu = container . querySelector ( 'vaadin-menu-bar' ) ;
345+ menu . items = items ;
346+ await nextResize ( menu ) ;
347+ const buttons = menu . _buttons ;
348+ const overflow = buttons [ buttons . length - 1 ] ;
349+ return { menu, buttons, overflow } ;
350+ }
351+
352+ describe ( 'flex row with sibling' , ( ) => {
353+ let container , overflow ;
354+
355+ beforeEach ( async ( ) => {
356+ container = fixtureSync ( `
357+ <div style="display: flex; width: ${ BUTTON_WIDTH * 5 } px">
358+ <vaadin-menu-bar style="width: 100%"></vaadin-menu-bar>
359+ <div style="min-width: ${ BUTTON_WIDTH * 2 } px">Sibling</div>
360+ </div>
361+ ` ) ;
362+ overflow = ( await initMenuBar ( container ) ) . overflow ;
363+ } ) ;
364+
365+ it ( 'should collapse items into overflow when sibling takes space' , ( ) => {
366+ expect ( overflow . hasAttribute ( 'hidden' ) ) . to . be . false ;
367+ expect ( overflow . item . children . length ) . to . be . greaterThan ( 0 ) ;
368+ expect ( overflow . item . children . length ) . to . be . lessThan ( items . length ) ;
369+ } ) ;
370+ } ) ;
371+
372+ describe ( 'css grid with sibling' , ( ) => {
373+ let container , overflow ;
374+
375+ beforeEach ( async ( ) => {
376+ container = fixtureSync ( `
377+ <div style="display: grid; grid-template-columns: 1fr ${ BUTTON_WIDTH * 2 } px; width: ${ BUTTON_WIDTH * 5 } px">
378+ <vaadin-menu-bar></vaadin-menu-bar>
379+ <div>Sibling</div>
380+ </div>
381+ ` ) ;
382+ overflow = ( await initMenuBar ( container ) ) . overflow ;
383+ } ) ;
384+
385+ it ( 'should collapse items into overflow' , ( ) => {
386+ expect ( overflow . hasAttribute ( 'hidden' ) ) . to . be . false ;
387+ expect ( overflow . item . children . length ) . to . be . greaterThan ( 0 ) ;
388+ expect ( overflow . item . children . length ) . to . be . lessThan ( items . length ) ;
389+ } ) ;
390+ } ) ;
391+
392+ describe ( 'flex row-reverse with no width on menu-bar' , ( ) => {
393+ let container , menu , buttons , overflow ;
394+
395+ beforeEach ( async ( ) => {
396+ container = fixtureSync ( `
397+ <div style="display: flex; flex-direction: row-reverse; width: ${ BUTTON_WIDTH * 5 } px">
398+ <div style="min-width: ${ BUTTON_WIDTH * 2 } px">Sibling</div>
399+ <vaadin-menu-bar></vaadin-menu-bar>
400+ </div>
401+ ` ) ;
402+ ( { menu, buttons, overflow } = await initMenuBar ( container ) ) ;
403+ } ) ;
404+
405+ it ( 'should collapse items into overflow' , ( ) => {
406+ expect ( overflow . hasAttribute ( 'hidden' ) ) . to . be . false ;
407+ expect ( overflow . item . children . length ) . to . be . greaterThan ( 0 ) ;
408+ expect ( overflow . item . children . length ) . to . be . lessThan ( items . length ) ;
409+ } ) ;
410+
411+ it ( 'should restore items when container width increases' , async ( ) => {
412+ container . style . width = `${ BUTTON_WIDTH * 8 } px` ;
413+ await nextResize ( menu ) ;
414+ buttons . slice ( 0 , - 1 ) . forEach ( ( btn ) => assertVisible ( btn ) ) ;
415+ expect ( overflow . hasAttribute ( 'hidden' ) ) . to . be . true ;
416+ } ) ;
417+ } ) ;
418+
419+ describe ( 'gradual collapse in flex container' , ( ) => {
420+ let container , menu , buttons , overflow ;
421+
422+ beforeEach ( async ( ) => {
423+ // Reproduces the layout from https://github.com/vaadin/web-components/issues/11269:
424+ // a flex container with a menu-bar (no explicit width) and a sibling.
425+ // Without the containerWidth snapshot fix, hiding a button causes
426+ // the host to shrink (min-width: 0), which shrinks the container,
427+ // causing cascading collapse where ALL items end up in overflow.
428+ container = fixtureSync ( `
429+ <div style="display: flex; width: ${ BUTTON_WIDTH * 3.5 } px">
430+ <vaadin-menu-bar></vaadin-menu-bar>
431+ <button>Sibling</button>
432+ </div>
433+ ` ) ;
434+ menu = container . querySelector ( 'vaadin-menu-bar' ) ;
435+ menu . items = [
436+ { text : 'Item 1' } ,
437+ { text : 'Item 2' } ,
438+ { text : 'Item 3' } ,
439+ { text : 'Item 4' } ,
440+ { text : 'Item 5' } ,
441+ { text : 'Item 6' } ,
442+ ] ;
443+ await nextResize ( menu ) ;
444+ buttons = menu . _buttons ;
445+ overflow = buttons . at ( - 1 ) ;
446+ } ) ;
447+
448+ it ( 'should not collapse all items at once' , ( ) => {
449+ const visibleButtons = buttons . filter (
450+ ( btn ) => btn !== overflow && getComputedStyle ( btn ) . visibility !== 'hidden' ,
451+ ) ;
452+ expect ( visibleButtons . length ) . to . be . greaterThan ( 0 ) ;
453+ expect ( overflow . item . children . length ) . to . be . greaterThan ( 0 ) ;
454+ expect ( overflow . item . children . length ) . to . be . lessThan ( menu . items . length ) ;
455+ } ) ;
456+ } ) ;
457+ } ) ;
458+
340459 describe ( 'parent resize' , ( ) => {
341460 let container , text , menu , buttons ;
342461
0 commit comments