[WC-3406]: Fix combobox menu jumping#2318
Draft
yordan-st wants to merge 8 commits into
Draft
Conversation
4a0b45c to
e05b04a
Compare
…hen space is tight
e05b04a to
8443d61
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request type
Bug fix (non-breaking change which fixes an issue)
Also includes:
@floating-ui/reactadded tocombobox-web)Description
The Combobox dropdown menu jumped around while open. Near the bottom of the viewport
it flickered between rendering above and below the input, and changing the number of
visible options (e.g. by typing to filter) made it flip placement mid-interaction.
Root cause: menu positioning was hand-rolled in
hooks/useMenuStyle.ts.getMenuPosition()chose top-vs-bottom placement from the measured menu height, and thatsame
menuHeightwas a dependency of the positioning effect — so placing the menu changedits height, which re-ran the effect, which recomputed placement, which changed the height
again.
Fix: replace the hand-rolled logic with floating-ui via a new
useFloatingMenuhook:strategy: "fixed",placement: "bottom-start",whileElementsMounted: autoUpdateoffset(4)→flip({ crossAxis: false, fallbackStrategy: "bestFit", padding: 8 })→
size({ padding: 8 })— thesizemiddleware sets the menu width to the input width andcaps
maxHeighttomin(availableHeight, 320)overflowing or flipping
alwaysOpen(keepMenuOpen) mode is unchanged — it renders inline (position: relative)and does not use floating positioning
Also: deleted
useMenuStyle.ts, reworked the menu SCSS so the wrapper is a flex column andthe option list fills + scrolls inside the (possibly shrunk) wrapper, and made the
Single/Multi selection wiring consistent.
Known limitations (out of scope, documented in the OpenSpec change):
position: fixed, a transformed/filter/containancestor canstill mis-anchor the menu (same as the old code, not a regression).
shiftmiddleware (menu width is pinned to the anchor, so horizontal overflow can'toccur in practice).
What should be covered while testing?
Open the Combobox in the New Country popup (or any combobox), then:
(below by default, above only when there's genuinely no room) and stays there. It must
NOT flicker between above and below.
matching options. The menu re-anchors smoothly and must NOT flip above↔below as the
option count changes.
internally; the menu bottom stays on screen (~8px from the edge) instead of overflowing.
visible when the menu shrinks; only the option list scrolls.
mode) still renders inline in the document flow, not floating.
as before.