Repository navigation
fix(TreeList): scope focus-visible outline to the focused row only - #4156
Conversation
TreeListItem drew its focus ring via stylex.when.ancestor(':focus-visible',
treeItemScope) on the content wrapper. Since every treeitem <li> shares the
same marker class, that selector matches ANY ancestor treeitem being
focused-visible — so focusing a parent row lit up the ring on every nested
descendant row too (the whole expanded subtree), not just the focused row.
Replace the shared ancestor-selector marker with a CSS custom property
declared on each <li>'s own :focus-visible state. Every nested <li>
redeclares the property with its own default, so a descendant's default
shadows an ancestor's active value instead of matching it — the ring
resolves to the nearest containing treeitem only, however deep the tree
nests. The now-unused treeItemScope marker file is removed.
Fixes meta#4130
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis ReportModified ComponentsTreeList
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
Reviewed the focus-ring scoping fix — this is a clean, well-targeted change.
What it does: replaces the shared ancestor-selector marker (which matched any focused ancestor treeitem and applied the ring to every descendant's content wrapper) with a per-row inheritable CSS custom property. Each <li> redeclares the var with a default: none, so a descendant's default shadows an ancestor's active value in the cascade — the ring resolves to the nearest containing treeitem only.
Why it's solid:
- Correct root-cause fix, and the cascade-shadowing approach generalizes to arbitrary nesting depth (the added regression test proves it at 3 levels).
- The
:has(:focus-visible)branch for inner focusable actions is preserved and cleanly separated — no double-application. - StyleX-only via literal
--_private custom properties, semantic--color-accentfor the ring, roving tabindex / ARIA untouched, changeset present and scoped.
Nice-to-have (non-blocking): the two 2px solid var(--color-accent) ring definitions are now duplicated literals — a shared local const would DRY it up, but it mirrors the pre-existing pattern, so not worth a round-trip.
LGTM.
Summary
Fixes #4130 — focusing a parent
TreeListrow was drawing the focus-visible outline on every descendant row in the expanded subtree, not just the focused row.Root cause
TreeListItem.tsxscoped the outline viastylex.when.ancestor(':focus-visible', treeItemScope). Every treeitem<li>shares the sametreeItemScopemarker class, so this selector matches any ancestor treeitem being:focus-visible— including a focused parent several levels up, whose match then applies to every nested descendant's content wrapper.Fix
Replace the shared ancestor-selector marker with a CSS custom property (
--_tree-focus-outline/--_tree-focus-outline-offset) declared directly on each<li>'s own:focus-visiblestate. Every nested<li>redeclares the property with its owndefaultvalue, so a descendant's default shadows an ancestor's active value in the CSS cascade instead of matching it via selector — the ring now resolves to the nearest containing treeitem only, regardless of nesting depth. The:has(:focus-visible)branch (for inner focusable actions) is unchanged. The now-unusedtreeItemScopemarker file is removed.Test plan
TreeList.test.tsxasserting that focusing a 3-level-deep row (Root>Mid>Leaf, all expanded) sets the outline var onRootonly, whileMidandLeafstay unset.TreeList.test.tsxsuite passes (48/48).tsc --noEmitandeslintclean on changed files.