Skip to content

fix(TreeList): scope focus-visible outline to the focused row only - #4156

Merged
cixzhang merged 1 commit into
meta:mainfrom
is-jain:fix/treelist-focus-ring-leak
Jul 22, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
is-jain:fix/treelist-focus-ring-leak

Conversation

@is-jain

@is-jain is-jain commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #4130 — focusing a parent TreeList row was drawing the focus-visible outline on every descendant row in the expanded subtree, not just the focused row.

Root cause

TreeListItem.tsx scoped the outline via stylex.when.ancestor(':focus-visible', treeItemScope). Every treeitem <li> shares the same treeItemScope marker 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-visible state. Every nested <li> redeclares the property with its own default value, 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-unused treeItemScope marker file is removed.

Test plan

  • Added a regression test in TreeList.test.tsx asserting that focusing a 3-level-deep row (Root > Mid > Leaf, all expanded) sets the outline var on Root only, while Mid and Leaf stay unset.
  • Full TreeList.test.tsx suite passes (48/48).
  • Full core+lab test suite passes (pre-existing perf-budget flakes unrelated to this change; no TreeList failures).
  • tsc --noEmit and eslint clean on changed files.

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
@vercel

vercel Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 22, 2026 1:34am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 22, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Jul 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Modified Components

TreeList
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 711 -
Complexity N/A Very High (74) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-accent for 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.

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 22, 2026
@cixzhang
cixzhang merged commit 43c2dc9 into meta:main Jul 22, 2026
20 checks passed
AKnassa added a commit to AKnassa/astryx that referenced this pull request Jul 23, 2026
@github-actions
github-actions Bot deleted the fix/treelist-focus-ring-leak branch July 23, 2026 08:34

This branch was successfully deployed

1 active deployment
Preview — 2fbcc16f Deployed Jul 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TreeList: focusing a parent row highlights the entire subtree (focus ring leaks onto all descendant rows)

2 participants