Repository navigation
[select] Skip disabled items in typeahead and fix multiple-mode serialization - #5025
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,437.40 ms +74.63 ms(+5.5%) | Renders: 78 (+0)
12 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
2d54c1b to
7e3f5fc
Compare
7e3f5fc to
691843e
Compare
…lization Bugs: typeahead now skips disabled items while matching, so a single keypress advances to the next selectable item (like native <select> and arrow-key navigation) in both open and closed states — via a new opt-in 'isIndexDisabled' predicate on useTypeahead (Menu/Combobox don't pass it, so they're unchanged); multiple mode no longer passes the whole value array to itemToStringValue (the shared input is nameless); maxHeight:'auto' (invalid no-op) -> 'none' in align mode; trigger callback refs no longer fire twice; empty multiple array compares as undefined (not raw []) for custom isItemEqualToValue. Cleanup: remove write-only keyboardActiveRef and the unconsumed events context field; drop the stray useStore arg in SelectArrow and the unused scroll-arrow refs; use ownerWindow(el).getComputedStyle per repo convention; comment fixes (SelectBackdrop description + docs, parseFloat fallback, outside-press); remove a shipped XXX note. Tests: typeahead skips a disabled item and commits the next match; commits nothing when the only match is disabled; multiple-mode itemToStringValue isn't invoked with the array.
691843e to
78d89a5
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes several Select correctness issues, centered on typeahead behavior and multiple-mode form serialization, and adds regression tests to prevent future regressions.
Changes:
- Extend
useTypeaheadwith an optionalisIndexDisabledpredicate and use it in Select to skip disabled items during matching (including closed-trigger typeahead). - Fix Select multiple-mode serialization so the shared hidden input doesn’t attempt to stringify the entire selected-value array.
- Misc. Select cleanup (remove unused context fields/refs, realm-safe
getComputedStyle, ref wiring) plus regression tests and doc/comment corrections.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/select/trigger/SelectTrigger.tsx | Ref wiring cleanup to prevent duplicate ref-callback firing; clarifies outside-press mouseup handling. |
| packages/react/src/select/root/SelectRootContext.ts | Removes unused context fields (events, keyboardActiveRef) and unused import. |
| packages/react/src/select/root/SelectRoot.tsx | Multiple-mode serialization fix; integrates disabled-skipping into typeahead via new hook predicate; removes unconsumed events plumbing. |
| packages/react/src/select/root/SelectRoot.test.tsx | Adds regression tests for multiple-mode serialization and disabled-skipping typeahead on closed trigger. |
| packages/react/src/select/popup/SelectPopup.tsx | Uses realm-safe ownerWindow(...).getComputedStyle(...); fixes maxHeight assignment; removes unused refs. |
| packages/react/src/select/item/SelectItem.tsx | Ensures custom equality function isn’t called with the raw empty array in multiple mode. |
| packages/react/src/select/backdrop/SelectBackdrop.tsx | Corrects component doc comment (“select popup”). |
| packages/react/src/select/arrow/SelectArrow.tsx | Removes a stray unused argument passed to useStore. |
| packages/react/src/floating-ui-react/hooks/useTypeahead.ts | Adds isIndexDisabled option and skips disabled items while matching. |
| docs/src/app/(docs)/react/components/select/types.md | Updates generated docs text to match Select terminology (“select popup”). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codex Review (GPT-5.5)Reviewed the full PR 5025 branch against freshly fetched 1. Bugs / Issues1. 🔴 Disabled double-letter items still block rapid same-letter cycling (blocking)
const allowRapidSuccessionOfFirstLetter = listContent.every((text) =>
text ? text[0]?.toLocaleLowerCase() !== text[1]?.toLocaleLowerCase() : true,
);The new matching path skips disabled items, but this rapid-succession guard still evaluates every label in Fix: Make the rapid-succession guard use the same eligibility rules as matching, at least ignoring Root Cause & Patch AssessmentThe multiple-mode serialization fix is well targeted: the nameless shared input no longer serializes the full array, while per-value hidden inputs still carry form data. The disabled-item typeahead fix addresses the single-key matching path, but the rapid repeated-letter path still has a separate eligibility decision. That leaves the branch short of fully aligning disabled item handling across typeahead behavior. Test Coverage AssessmentI ran: Both passed. The added Select tests cover single-key disabled skipping and the multiple-mode serialization regression, but they do not cover the disabled double-letter cycling case above. I did not verify the new regression tests against RecommendationRequest changes 🔴 The PR is close, but disabled items can still alter enabled typeahead behavior through the repeated-letter guard. I’d fix that guard and add the focused regression before merging. |
d457f0b to
0fd4874
Compare
flaviendelangle
left a comment
There was a problem hiding this comment.
PR Review Summary
Five specialized agents reviewed the PR in an isolated worktree against the merge base. Headline: the PR is correct and merge-ready. No critical bugs, no new silent failures, strong project-guideline compliance. Findings are about polish — one naming/convention question, one misleading JSDoc phrase, and one untested fix.
Critical Issues (0)
None. All seven flagged risk areas (keyboardActiveRef removal, events removal, ref-dedup, serializedValue='', outside-press simplification, useStore arg drop, maxHeight) were independently verified safe.
Important Issues (2)
1. isIndexDisabled naming collides with the established convention — useTypeahead.ts:41 (type-design-analyzer, Invariant Expression 5/10)
The codebase already expresses "disabled index" as disabledIndices?: DisabledIndices (useListNavigation.ts:149, type at composite.ts:8) with a shared resolver isListIndexDisabled (composite.ts:472). The new field isIndexDisabled sits one word from isListIndexDisabled but has a different shape (bare predicate vs. array-or-predicate union). Two sibling hooks in the same directory now name the same concept differently — a future maintainer could wire the wrong one. Recommend renaming to disabledIndices (ideally adopting the shared union, which makes the array form and attribute fallback free). The JSDoc's three-line "this isn't isListIndexDisabled" disclaimer is itself a signal the name fights the convention. (Judgment call — reasonable to defer, but cheap to fix now.)
2. The isItemEqualToValue → undefined fix has zero test coverage — SelectItem.tsx:100-110 (pr-test-analyzer, Gap A, 8/10)
This is one of the two fixes named in the PR title, yet no test exercises it. The pre-fix bug: multiple mode + empty selection ([]) + a custom isItemEqualToValue written for single items → the raw [] was passed to the comparer → throws on [].value. Existing isItemEqualToValue tests all use non-empty values and miss this branch. Add: render Select.Root multiple with defaultValue={[]} (or unset) and isItemEqualToValue={(a, b) => a.value === b.value} over object items; assert it renders without throwing. Fails pre-fix, passes post-fix.
Suggestions (5)
- Misleading JSDoc wording —
useTypeahead.ts:34-40(flagged independently by comment-analyzer AND type-design-analyzer). Says the predicate is "independent ofelementsRef/visibility," but the code AND-combines them:isItemAvailable = isVisible(index) && !isIndexDisabled?.(index). A disabled-but-also-hidden item is still rejected by visibility. Reword to "the disabled check doesn't readelementsRef, so consumers that don't passelementsRefstill get disabled-skipping." - Untested open-state skip path —
SelectRoot.tsx:402-407(Gap B, 6/10). All three new typeahead tests use the closed-trigger (setValue) branch; the open branch (store.set('activeIndex')) is unexercised. Adescribe.skipIf(isJSDOM)test opening the popup and asserting the disabled item gets nodata-highlightedwould close it. - Pre-existing latent quirk, now documented not fixed —
SelectPopup.tsx:316-318(silent-failure-hunter).parseFloat(x) || 10treats an explicitmargin:0/min-height:0as10/100. The PR only adds a comment about it (no regression), but it's a candidate for a follow-up usingNumber.isNaN(parsed) ? N : parsed. - Comment over-generalizes —
SelectPopup.tsx:314-315. "the align algorithm always reserves some spacing" is true for the two margins but the same|| Nalso guardsminHeight(not spacing). Narrow the clause. - Minor perf note —
useTypeahead.ts:164.allowRapidSuccessionOfFirstLetternow callsisItemAvailable(which runsisElementVisible+ the predicate) for every item on every keypress. Not a correctness issue; worth a glance if it shows in the combobox bench.
Strengths
- No new bugs and no new silent failures across all risk areas; the
serializedValue=''change correctly avoids breaking form submission (shared input is nameless in multiple mode; per-value inputs carry data) andisElementDisabled(null)returnstrue(skips gracefully, never throws). - Cleanups verified complete:
keyboardActiveRefwas genuinely write-only in Select (remaining reads belong to Combobox's own store);eventshad no consumer; the ref refactor still applies all four refs viauseRenderElement; import + memo body + dep array all pruned together. - 4 of 6 new tests are true regression guards (verified by tracing pre-fix behavior), including a negative case and the subtle disabled double-letter cycling interaction.
- Several exemplary "why" comments (multiple-mode serialization, the
isIndexDisabledrationale inSelectRoot,maxHeight: 'none'documenting the invalid-autotrap) and good guideline compliance (migrates twogetComputedStyleglobals toownerWindow, shares logic via context). SelectRootContextslimming is a clean encapsulation win (9/10) — drops a leakedFloatingEventstype and cross-component mutable ref.
Recommended Action
- Add the Gap A test (empty multiple + custom
isItemEqualToValue) — the one named fix with no coverage. (highest value) - Reword the
isIndexDisabledJSDoc atuseTypeahead.ts:34-40— quick, two reviewers flagged it. - Decide on the
isIndexDisabled→disabledIndicesrename — align withuseListNavigation, or consciously accept the divergence. - Optional polish: open-state test (Gap B), narrow the
SelectPopup:314comment, file a follow-up for theparseFloat || Nquirk.
- Rename useTypeahead's `isIndexDisabled` predicate to `disabledIndices` (array-or-predicate `DisabledIndices` union) to match `useListNavigation`, and resolve it via the shared `isListIndexDisabled`. The empty element list keeps it to the explicit array/predicate check, so consumers that don't opt in (Menu, Combobox) are unchanged. - Reword the JSDoc so it no longer claims independence from `elementsRef` while the code AND-combines visibility. - Add a regression test for the empty multiple-mode `isItemEqualToValue` fix (comparer must never receive the raw value array). - Add an open-popup typeahead test that disabled items are skipped when highlighting via `activeIndex`. - Narrow the SelectPopup `|| N` comment (covers margins and min-height).
flaviendelangle
left a comment
There was a problem hiding this comment.
PR Review Summary — Round 2 (PR #5025)
The author pushed one follow-up commit, 23a59f264 "Address review", which addresses all four findings from the previous round. I re-reviewed only the delta. Net: the source is solid and the rename is a clean win — but one of the two new tests is a vacuous pass and must be fixed before it provides any protection.
How the prior findings were addressed
| Prior finding | Status |
|---|---|
① isIndexDisabled naming collision |
✅ Renamed to disabledIndices: DisabledIndices, routed through the shared isListIndexDisabled resolver — matches useListNavigation exactly |
| ② Misleading "independent of visibility" JSDoc | ✅ Reworded to "the disabled check doesn't read elementsRef" |
③ Gap A — isItemEqualToValue empty-array fix untested |
|
| ④ Gap B — open-state skip path untested | ✅ Valid, non-flaky guard added |
(suggestion) || N comment over-generalized |
✅ Narrowed |
Important Issues (1 found)
- [pr-test-analyzer] The new Gap A test is a vacuous pass — it cannot fail even if the bug is reintroduced.
SelectRoot.test.tsx:1073("does not invoke isItemEqualToValue with the value array in multiple mode when empty"). The test renders a closedSelect.Root multiple defaultValue={[]}and never opens/focuses it. The comparison it targets lives in auseIsoLayoutEffectgated onhasRegistered(SelectItem.tsx:92-93), so it only runs once items mount — which a closed, unfocused Select never does. The comparer is never called, so both theArray.isArraythrow andnot.toHaveBeenCalledWith(...)pass vacuously. The analyst empirically confirmed: reverting theSelectItem.tsxfix leaves the test green; addingdefaultOpenmakes it correctly fail pre-fix and pass post-fix. I independently confirmed the mounting gate by reading the source.- Fix: add
defaultOpen(orforceMountthe items) to the test'sSelect.Rootso theSelectItemeffect actually runs. The comparison path needs no layout, so it should remain a jsdom test (noskipIf(isJSDOM)needed). The underlying source fix (SelectItem.tsx:100-105) is correct — only the test is inadequate.
- Fix: add
Suggestions (2 — optional, below merge-blocking threshold)
- [code-reviewer] JSDoc wording polish —
useTypeahead.ts:36-42. "...without opting into the visibility filter" is slightly imprecise sinceisItemAvailablealways AND-combines visibility regardless ofdisabledIndices. Meaning is clear from context; pure wording. - [type-design-analyzer]
isListIndexDisabled(EMPTY_ARRAY, …)is a mild API smell —useTypeahead.ts. Passing a sentinel empty list to defeat the resolver's element-based fallbacks is correct and well-commented, but the signature still advertises a list it doesn't use. A future cleanup could extractisIndexExplicitlyDisabled(index, disabledIndices)fromcomposite.ts:477-480and call that directly. Not worth blocking.
Strengths
- The
isIndexDisabled→disabledIndicesrename is behavior-preserving and verified. For Select's predicate,!isListIndexDisabled(EMPTY_ARRAY, i, fn)reduces exactly to!fn(i); fordisabledIndices == nullit short-circuits to visibility-only — Menu/Combobox confirmed unchanged. It also correctly broadens to the array-or-predicate union (the old?.()call would have thrown on an array). - Type design measurably improved: Invariant Expression 5/10 → 8/10, Enforcement 7 → 8 (deduplicated onto the shared resolver). The "rename before merge" recommendation is fully satisfied.
- Gap B test (open-popup skip) is a genuine, non-flaky guard — correctly gated with
it.skipIf(isJSDOM), one assertion perwaitFor(), and verified to fail pre-fix. The wrong-reason/start-index flakiness concern was traced and ruled out. - No new bugs, no silent failures, no guideline violations in the delta.
Recommended Action
- Add
defaultOpen(orforceMount) to the Gap A test atSelectRoot.test.tsx:1092so it actually exercises theSelectItemcomparison — currently it guards nothing. - Optionally apply the two wording/idiom polish suggestions.
- Everything else is merge-ready.
One actionable item this round. The rest of the follow-up is clean.
Summary
Fixes a few Select correctness issues plus adjacent cleanup, with regression tests.
Bugs
useTypeaheadonly skipped invisible elements, so typeahead could stop on a disabled item (and, on a closed trigger, commit it). It now skips disabled items while matching, so a single keypress advances to the next selectable item — matching native<select>and arrow-key navigation — in both open and closed states. This is done via a new opt-indisabledIndicesoption onuseTypeahead(the same array-or-predicate shape asuseListNavigation), decoupled from theelementsRef/visibility filter so Select's mounted-but-hidden closed items still match. Menu and Combobox don't pass it, so their behavior is unchanged.useTypeaheadno longer relies on locale-sensitive lowercasing, so Turkish/Azeri casing rules don't prevent typingifrom matching labels likeIstanbul.itemToStringValue. The shared hidden input is nameless in multiple mode (per-value<input>s carry the data), soserializedValueis now''; previously a useritemToStringValuewritten for a single item would throw or yield''.positionerElement.style.maxHeight = 'auto'(invalid, silently ignored) →'none', so the explicit height governs in align mode and isn't clamped by user CSS.useRenderElementref array).isItemEqualToValueis no longer handed the raw empty array as the "selected value" in multiple mode (undefinedwhen nothing is selected).Cleanup
keyboardActiveRefand the unconsumedeventscontext field.ownerWindow(el).getComputedStyle(el)inSelectPopup(repo convention for realm-sensitive lookups).useStoreargument inSelectArrowand unused scroll-arrow refs.parseFloatfallback, outside-press); remove a shippedXXXnote.Tests
I...labels when Turkish/Azeri casing would differ.itemToStringValueisn't invoked with the array.Typecheck, eslint, prettier, and the Select / Menu / Combobox / useTypeahead suites pass. Based on current
master.