Repository navigation
[combobox] Fix stale chip focus after returning to the input - #5879
Conversation
commit: |
Bundle size
PerformanceTotal duration: 399.21 ms -29.24 ms(-6.8%) | Renders: 76 (+0) | Paint: 728.31 ms -69.05 ms(-8.7%)
13 tests within noise — details 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. |
PR reviewThe PR fixes the reported keyboard path, but the stale chip highlight it targets still happens when focus leaves a chip any way other than Tab. Clicking back into the input or clicking away and tabbing back still breaks Backspace and ArrowLeft. Because of that, the fix is incomplete and blocks merge. I checked both missed paths with jsdom probes against Bugs (1)1. 🔴 Stale chip highlight survives every focus exit except TabLocation: if (event.key === 'Tab') {
setHighlightedChipIndex(undefined);
return;
}
Failure scenario: Both of these fail on the PR head (no
Fix: Clear the highlight when the input gains focus, and drop the Tab special case in the chip: onFocus() {
setFocused(true);
comboboxChipsContext?.setHighlightedChipIndex(undefined);
// ...This passes both probes and the PR's two new tests. The rest of the Combobox jsdom suite passes except the test covered in Tests #1. Tests (1)1. 🟠 An existing test pins the stale-highlight behavior, and the new tests only cover TabLocation: input.focus();
await user.keyboard('{ArrowLeft}');
expect(banana).toHaveFocus();"navigates an existing chip highlight when focus returns to the input" calls Failure scenario: A later change to the chip keydown path could bring back the mouse and blur variants of this bug without any test failing. The fix in Bugs #1 is also blocked by the outdated test at line 609. Fix: Change the line-609 test to expect that focusing the input clears the highlight (ArrowLeft goes to the last chip). Add cases for clicking the input with Simplifications (1)1. ℹ️ The input-side highlighted-chip branch is nearly dead once focus clears the highlightLocation: if (highlightedChipIndex !== undefined) {
if (event.key === previousChipKey) {Chips receive real focus, so with the input clearing the highlight in Failure scenario: About 25 lines of keyboard handling stay in the bundle to serve a state that can no longer be reached in practice. Fix: Optional follow-up: remove the branch and the VerdictRequest changes - the fix covers only the Tab path, so the same Backspace/ArrowLeft bug is still reachable by mouse or by clicking away and tabbing back. 🤖 Review generated with Claude Code |
|
I’ve addressed the review Claude’s review recommended updating the existing test to expect the chip highlight to be cleared when the input receives focus. |
Yep, that is fine More simplifications could be done here, applied them |
reproduction
• Backspace does not remove the last chip.
• ArrowLeft focuses the second-to-last chip instead of the last chip.
Expected behavior
Backspace removes the last chip, and ArrowLeft focuses the last chip.