Skip to content

Dropdown: menu auto-width clips items with rich slotted content #4135

Description

@Spark450

Description

The Dropdown menu's auto-calculated width clips items with rich slotted content (see #1351). getLongestChildWidth in Dropdown.svelte sizes the menu from option.label || (option.hasSlotContent ? option.filter : "") || option.value, measured in ch. A slotted item almost always has a label set (it's shown in the input on selection), so option.label || short-circuits and the slot-text fallback never runs. The menu ends up sized to the label instead of the rendered content, and wider content clips because the menu's overflow-x is auto rather than wrapping.

Measured example: an item with a 13-character label but a 22-character line of slotted content rendered at li clientWidth 185px against scrollWidth 201px — a 16px clip.

This also conflicts with the existing "don't truncate labels" guidance, which says longer text should wrap rather than clip.

A real fix likely needs to measure rendered content width after slot distribution rather than relying on a character-count proxy, since there's no single text value that represents multi-line rich content well (the label is too narrow, the full joined slot text is usually too wide because it spans multiple visual lines). Setting an explicit width on the dropdown is a working escape hatch in the meantime.

Steps to Reproduce

  1. Render a filterable or non-filterable Dropdown with GoabDropdownItem items that have rich slotted content (e.g. name + role + location on separate lines) and a short label
  2. Open the dropdown menu
  3. Observe that the menu width is calculated from the label length, not the rendered content
  4. Observe the slotted content's widest line clipping against the menu's right edge, with overflow-x: auto rather than wrapping

Acceptance Criteria

  • Dropdown menu width accounts for the rendered width of slotted item content, not just the label length
  • Rich item content no longer clips at default (auto) width
  • Behavior is verified with a browser test that measures real rendered slot content, since text-length heuristics can't be trusted here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status
    🔖 Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions