Repository navigation
[composite] Fix roving focus when items are added or removed - #5447
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,167.40 ms -13.81 ms(-1.2%) | Renders: 76 (+0) | Paint: 1,828.88 ms -19.35 ms(-1.0%) No significant changes — 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. |
|
@claude review low |
|
The review finished without producing a report. 🤖 Review generated with Claude Code · Opus 5 (High) · |
0fcae59 to
d302f00
Compare
|
@claude review low |
PR reviewNothing here is merge-blocking: the new revalidation in Bugs (3)1. 🟡 New eligibility checks ignore
|
d302f00 to
508de3e
Compare
|
@claude review low |
PR reviewThe revalidation logic in Bugs (1)1. 🟠 Tab stop only falls back to the active item when the highlighted slot is emptyLocation: if (nextIndex === -1) {
// A replacement at the same index can keep the tab stop. Otherwise move it to an
// eligible item so a missing, hidden, or disabled replacement does not take the
// composite out of the tab order.
const replacement = elements[highlightedIndex];
if (!replacement || isListIndexDisabled(elements, highlightedIndex, disabledIndices)) {
onHighlightedIndexChange(getFallbackIndex(elements, disabledIndices));
} else {
highlightedElementRef.current = replacement;
}
}The PR description states that "removing the highlighted item moves the tab stop to the active item, or to the first item that can take focus." In practice that only happens when nothing valid occupies For Failure scenario: Fix: In the 2. ℹ️ Revalidation is keyed on identity/index only, so in-place hidden or disabled transitions still strand the tab stopLocation: const nextIndex = elements.indexOf(highlightedElementRef.current);When the highlighted element stays in the list but stops being able to hold the tab stop — Relatedly, the comment on Failure scenario: Fix: Out of scope for this PR as written — this is pre-existing behavior, not a regression. Worth either following up separately or noting in the PR that only mount/unmount transitions are revalidated, so the description's "hidden and disabled items are skipped" is not read as covering in-place changes. VerdictApprove after nits - no regressions found; the one 🟠 is an incomplete fallback that contradicts the PR description rather than a break in existing behavior. 🤖 Review generated with Claude Code · Opus 5 (High) · |
Adding or removing composite items could leave the roving tab stop on the wrong item, or on no item at all. The highlighted index is stored as a plain number and nothing revalidated it when the item map changed.
Affects Tabs, Toolbar, Toggle Group, Radio Group, Menubar, and Navigation Menu. OTP Field is unaffected because it derives and clamps its active index during render.
Changes
useCompositeRootnow revalidates the highlighted index on every item map change instead of only the first one:tabIndex="-1", which dropped the whole widget out of the tab order.This replaces the Tabs-local fix in the first two commits. The same bug affects every composite, so the fallback lives with the shared highlighted index.