Skip to content

[menu-bar] Overflow button is clipped out of a split layout pane on first render #12816

Closed

Description

@web-padawan

Description

A menu bar inside a split layout leaves its overflow button outside the pane on the first render.
The pane clips the button, so the collapsed items cannot be reached at all.

Image

Dragging the splitter by one pixel fixes it:

menu-bar-render.mp4

Trigger: the pane is sized by its content. vaadin-split-layout gives its children flex: 1 1 auto, so the pane basis follows the menu bar content.

This is not specific to split layout. Any content sized flex parent shows it, for example:

<div style="display: flex"><div style="width: 100%"></div><vaadin-menu-bar></vaadin-menu-bar></div>

Reported on #3274 by @knoobie and @DiegoCardoso after that issue was closed.

Expected outcome

The overflow button stays inside the menu bar, so the collapsed items are reachable without touching the splitter.

Minimal reproducible example

<vaadin-split-layout>
  <div><vaadin-menu-bar></vaadin-menu-bar></div>
  <div>Resize the splitter to show the overflow button</div>
</vaadin-split-layout>

<script type="module">
  import '@vaadin/menu-bar';
  import '@vaadin/split-layout';

  document.querySelector('vaadin-menu-bar').items = [
    'View',
    'Edit',
    'Share',
    'Move',
    'Duplicate',
    'Archive',
  ].map((text) => ({ text, children: [{ text: `${text} all` }] }));
</script>

Steps to reproduce

  1. Open the snippet above in a window about 600px wide.
  2. Look at the menu bar. Four buttons are visible and the overflow button is missing.
  3. Drag the splitter by one pixel.
  4. The overflow button appears and one more item collapses.

Root cause

__setOverflowItems restores every button before it measures, so it measures a width that the menu bar only has while nothing is collapsed. Hiding a button gives it position: absolute, which lowers the max content width of the host, which lowers the pane flex basis, which shrinks the host. The decision is therefore made against a width that no longer holds once the writes land.

Instrumented on the snippet above, at a 600px window:

at gate      host=348.8   all buttons span=480.2
after writes host=294.2
first render collapsed=2  overflow button 36px wide, 39px outside the host

at gate      host=276.2   (after a drag, the pane has a fixed basis)
after writes host=276.2
after drag   collapsed=3  overflow button 0px outside the host

Repeated detections do not converge. Each one restores the buttons first, measures 348.8px again, and reaches the same answer. Removing the container width lock added in #11358 changes nothing here, so the lock is not the cause.

Proposed solution

Either keep hiding from the current state when the host shrinks after the writes, instead of restoring every button and measuring again, or stop the intrinsic width of the host from depending on the collapse state. The second one is close to the alternative @rolfsmeds sketched in #6876. Whichever is chosen must not bring back the runaway collapse of #11269 that the container lock prevents.

Environment

Vaadin version(s): 25.1
OS: any

Browsers

Issue is not browser related

Activity

  1. self-assigned this
    on Sep 22, 2026
  2. web-padawan commented on Sep 23, 2026

    @web-padawan
    MemberAuthor

    Claude proposed a fix using contain: inline-size and contain-intrinsic-inline-size: var(--_vaadin-menu-bar-content-width).

    Prototype branch: https://github.com/vaadin/web-components/compare/proto/menu-bar-inline-size

  3. web-padawan commented on Sep 24, 2026

    @web-padawan
    MemberAuthor

    🤖 AI-generated

    Summary

    TL;DR

    Suggested fix is behavior altering change worth landing in 25.4.

    Why there is no simple fix

    The menu bar hides the buttons that do not fit its width. Hidden buttons do not count toward its content width. A parent that takes its width from content then gives the menu bar less room. The earlier decision no longer holds. A new measurement repeats the same answer, because the restored buttons restore the old width. More hidden buttons do not help either, because the parent shrinks after every hide. In a shared row the menu bar always receives less than its content needs.

    Why a splitter drag fixes it

    A drag sets flex: 1 1 <px> on both panes. The pane then has a fixed basis. The parent no longer takes its width from content, and the loop stops.

    Proposed fix

    1. Add the has-overflow attribute when the menu bar has collapsed buttons.
    2. Store the width of the menu bar with every button in flow in --_vaadin-menu-bar-content-width.
    3. Apply this CSS on the host. Safari 17, the minimum for Vaadin 25, supports both properties.
    :host([has-overflow]) {
      contain: inline-size !important;
      contain-intrinsic-inline-size: var(--_vaadin-menu-bar-content-width);
    }

    The !important keeps the fix active when an application sets contain on the host.

    Potential impact

    Fixed

    Changed

    • A collapsed menu bar keeps the width it had with every button in flow. A parent that takes its width from content no longer shrinks it around the kept buttons.
    • Up to one button of empty space stays inside the menu bar in those parents. Measured: 115 px in a grid auto 1fr column, 107 px in a flex row next to a button, 106 px in a centered toolbar, 111 px in a shrink to fit host.
    • With theme="end-aligned" the empty space is at the start.
    • Five visual baselines change: single overflow button in an inline block wrapper, in base, Lumo and Aura.
    • Themes and tests can see has-overflow as a state attribute.

    Unchanged

    • Menu bars with a fixed width, and menu bars whose buttons all fit.
    • Which buttons collapse: the same set on every measured step in base, Lumo, Firefox and WebKit.
    • Forced layouts per detection.

    Known limitations

    • A font that loads after a collapse does not start a new detection in a collapsed menu bar. Fixed width menu bars have the same limit today.
    • The menu bar does not detect a size change of a sibling with flex-shrink: 0 (fix: observe parent resize to detect overflow #3824).

    Note

    has-overflow is a new state attribute, already used by Breadcrumbs and Avatar Group.

    Workarounds

    The loop needs a parent that takes its width from the menu bar content. Any basis that does not come from the content stops it. Measured on main over 81 widths, none of these clip the overflow button.

    • Split layout: set a splitter position, for example splitLayout.setSplitterPosition(50) in Flow or style="flex: 1 1 50%" on both panes in HTML. A percentage width on the first pane works as well.
    • Full width sibling in a flex row: set flex-shrink: 0 on the menu bar. The menu bar then keeps every button and overflows the row when the row is too narrow.
    • Two menu bars in one row: set flex: 1 1 0 on both. Each gets half of the row, so the menu bar with more items collapses first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions