Skip to content

Commit 193b77f

Browse files
refactor: lock menu-bar container width only when buttons overflow (#12801) (CP: 25.2) (#12804)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent d4d61f4 commit 193b77f

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

‎packages/menu-bar/src/vaadin-menu-bar-mixin.js‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,16 @@ export const MenuBarMixin = (superClass) =>
501501
/** @private */
502502
__setOverflowItems(buttons, overflow) {
503503
const container = this._container;
504-
505-
// Prevent the container from shrinking while buttons are being hidden.
506-
// The host has min-width: 0 so it can shrink inside flex/grid layouts.
507-
// Without this lock, hiding a button reduces the host width, which
508-
// shrinks the container (width: 100%), shifting all button positions
509-
// and causing a cascading collapse where every button appears to overflow.
510-
container.style.minWidth = `${container.offsetWidth}px`;
511-
512-
if (container.offsetWidth < container.scrollWidth) {
504+
// Read before any write, so a menu bar that fits forces no layout
505+
const width = container.offsetWidth;
506+
507+
if (width < container.scrollWidth) {
508+
// Prevent the container from shrinking while buttons are being hidden.
509+
// The host has min-width: 0 so it can shrink inside flex/grid layouts.
510+
// Without this lock, hiding a button reduces the host width, which
511+
// shrinks the container (width: 100%), shifting all button positions
512+
// and causing a cascading collapse where every button appears to overflow.
513+
container.style.minWidth = `${width}px`;
513514
this._hasOverflow = true;
514515

515516
const isRTL = this.__isRTL;
@@ -538,9 +539,9 @@ export const MenuBarMixin = (superClass) =>
538539

539540
const items = buttons.filter((b) => !remaining.includes(b)).map((b) => b.item);
540541
this.__updateOverflow(items);
541-
}
542542

543-
container.style.minWidth = '';
543+
container.style.minWidth = '';
544+
}
544545
}
545546

546547
/** @private */

‎packages/menu-bar/test/dom/__snapshots__/menu-bar.test.snap.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,7 @@ snapshots["menu-bar overlay"] =
187187
/* end snapshot menu-bar overlay */
188188

189189
snapshots["menu-bar shadow"] =
190-
`<div
191-
part="container"
192-
style=""
193-
>
190+
`<div part="container">
194191
<slot>
195192
</slot>
196193
<slot name="overflow">

0 commit comments

Comments
 (0)