Repository navigation
fix(ui): improve ComboBox search query state management - #2030
Conversation
🦋 Changeset detectedLatest commit: 86dcdb4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
A controlled reset can still display a default value or leave the input reporting an open menu, and the new tests do not exercise query clearing.
Review effort: Balanced
Findings: 2
Open (4)
What changed in this PR
This PR updates the shared ComboBox to clear stale search queries after selection and when a controlled value is cleared.
Changes:
- Clear the internal query after selection or a controlled-value reset.
- Add controlled and uncontrolled ComboBox tests.
- Add a patch changeset.
| File | Description |
|---|---|
packages/ui-components/src/components/ComboBox/ComboBox.test.tsx |
Adds state-management tests. |
packages/ui-components/src/components/ComboBox/ComboBox.component.tsx |
Adds query and dropdown reset logic. |
.changeset/fix-combobox-query-clearing.md |
Records the patch release. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
f9848dc to
1af4a4f
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Initially empty controlled values can display defaults, and external resets do not close an open dropdown.
2 open findings
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
2b2f1bb to
d28b947
Compare
249ace9 to
ed73126
Compare
ed73126 to
462fd0f
Compare
462fd0f to
b001d40
Compare
Clear search query after option selection and when controlled value becomes empty to prevent stale search terms from persisting. This ensures proper synchronization between internal query state and parent component filter state, improving the user experience when working with controlled ComboBox components. Changes: - Clear search query after option selection - Clear query and close dropdown when value prop becomes empty - Add comprehensive tests for controlled/uncontrolled scenarios Signed-off-by: Arturo Reuschenbach Puncernau <artie.reuschenbach-puncernau@sap.com> Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
…e handling - Honor explicitly cleared controlled values over defaultValue by tracking controlled mode and using effectiveValue calculation - Remove problematic setIsOpen(false) that caused aria-expanded desync with Headless UI internal state - Only clear query when value transitions from truthy to falsy (not on init) - Add comprehensive tests for controlled/uncontrolled query reset behavior Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
- Change isControlled detection from `value !== ""` to `value !== undefined` - Remove default value for `value` prop to preserve undefined vs empty distinction - This ensures `<ComboBox value="" defaultValue="x">` shows empty, not default - Add test for initially empty controlled value scenario Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
…s open - Blur the input element to properly close Headless UI's Combobox - This ensures aria-expanded syncs correctly with actual open state - Add test verifying dropdown closes on external value clear Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
…h a proper event object Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
Signed-off-by: Arturo Reuschenbach Puncernau <reuschenbach@gmail.com>
b001d40 to
86dcdb4
Compare


Summary
Fix ComboBox controlled value clearing and search query state management. This is a focused subset of the changes from PR #2010, excluding the forwardRef and onKeyDown features to simplify the implementation.
Changes Made
valueprop is explicitly set to""value === "") to distinguish intentional reset from prop removal (undefined)isControlledinline instead of using state to avoid one-way ratchet behaviorinputRefinstead ofdocument.getElementByIdfor blur (works in shadow DOM)onInputChangewith a proper event object when query is programmatically cleared, keeping internal and external search state in syncRelated Issues
Screenshots (if applicable)
N/A - No visual changes
Testing Instructions
pnpm ipnpm test- verify ComboBox tests passKnown Limitations
The following items are lower priority and can be addressed in follow-up issues:
blur()call firesonBlurand moves keyboard focus. Consumers should not rely ononBlurfor user-driven-only logic.value=""anddefaultValueare provided, the ComboBox now shows empty instead of falling back todefaultValue. This is correct sincedefaultValueis documented as uncontrolled-mode only.Checklist
PR Manifesto
Review the PR Manifesto for best practises.