Improvement (combobox): respect minimum popover width when trigger is narrow

Merged
KA
5mo ago
+4-2

Description

When a RubyUI::Combobox trigger is narrower than the popover's natural content (e.g. a short trigger label like "Status"), the popover shrinks to match the trigger width and cuts off the ComboboxSearchInput placeholder.

updatePopoverWidth currently sets popover.style.width = trigger.offsetWidth + "px" unconditionally, coupling the popover's width to the trigger's width 1:1. The popover content has its own natural minimum that's independent of the trigger.

This PR introduces a minPopoverWidth Stimulus value (default 240) and applies it as a floor inside updatePopoverWidth

The change is monotonic: it only expands popovers that would otherwise be narrower than the floor. Triggers wider than 240px are unaffected (no regression). resize@window already calls updatePopoverWidth, so the floor holds after viewport changes without any new event listeners.

Consumers can override the floor per-instance via the standard Stimulus values API:

render RubyUI::Combobox.new(data: { "ruby-ui--combobox-min-popover-width-value": 320 })
  ...
end 
BeforeAfter
Captura de Tela 2026-05-21 às 16 51 13 | Captura de Tela 2026-05-21 às 16 56 50

Summary by cubic

Prevents RubyUI::Combobox popovers from shrinking below a sensible width when the trigger is narrow, avoiding cut-off placeholders and cramped content.

  • Bug Fixes
    • Added minPopoverWidth Stimulus value (default 240) and apply it as a floor in updatePopoverWidth.
    • Popover width is now max(trigger width, minPopoverWidth) and still updates on window resize.
    • Per-instance overrides supported via ruby-ui--combobox-min-popover-width-value.