Skip to content

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

Closed

Description

@cixzhang

Summary

When a parent (expandable) TreeList row receives keyboard focus, the focus-visible outline is drawn around the parent and every one of its descendant rows — the whole subtree lights up instead of just the focused row.

Steps to reproduce

  1. Render a TreeList with a parent row that has children, expanded.
  2. Keyboard-focus the parent row (Tab into the tree / arrow to it).
  3. Observe the focus ring.

Expected

Only the focused row shows the focus-visible outline.

Actual

The parent row and all of its nested child rows show the outline simultaneously (see screenshot).

Root cause

In TreeListItem.tsx, the row outline uses:

outline: {
  [stylex.when.ancestor(':focus-visible', treeItemScope)]:
    `2px solid ${colorVars['--color-accent']}`,
  ':has(:focus-visible)': `2px solid ${colorVars['--color-accent']}`,
}

Every row is a <li role="treeitem"> tagged with the treeItemScope marker, and child rows are DOM descendants of the parent <li> (standard APG tree nesting). stylex.when.ancestor(':focus-visible', treeItemScope) matches an element whenever any ancestor carrying treeItemScope is :focus-visible — so when the parent row is focused, the condition is true for the parent and for every descendant row nested inside it. The result is the ring leaking onto the entire subtree.

The intent (per the code comments) is to bind the ring to the row's own treeitem, but when.ancestor matches any ancestor treeitem, not the nearest/own one, so parent focus propagates down.

Suggested fix direction

Scope the outline to the row's own focus state rather than an ancestor match — e.g. apply :focus-visible directly on the row element (the <li> is the roving-tabindex focus owner), or gate the when.ancestor rule so a descendant treeitem cancels the inherited match. Keep the existing :has(:focus-visible) branch for inner focusable actions.

Environment

  • Component: TreeList (@astryxdesign/core), packages/core/src/TreeList/TreeListItem.tsx

Activity

  1. added
    bug
    component
    on Jul 21, 2026
  2. added a commit that references this issue on Jul 22, 2026
    43c2dc9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcomponent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions