Skip to content

FocusScope: input.select() breaks focus handling #11016

Open

Description

@rothsandro

Provide a general summary of the issue here

If a component like GridList / Tree (a component that accepts interactive elements inside their items and restores focus to the previously selected item when tabbing into the component) is rendered within a dialog/popover (a component that uses a FocusScope), and the items render a checkbox as their first interactive control (e.g. for selection), then focus restoration when moving focus again into the GirdList/tree is slightly broken: it first moves focus to the checkbox for a short but noticeable time before it's properly restored (I thought that sometimes it even stays on the checkbox but I can't reproduce this anymore).


FocusScope moves focus to the next focusable element (the checkbox) when pressing tab. This triggers focus handling of the GridList and properly restores focus, but then select() is called for all HTML input elements (to select the text for text inputs):

if (nextElement instanceof getOwnerWindow(nextElement).HTMLInputElement) {
nextElement.select();
}

🤔 Expected Behavior?

Focus restoration should work properly, same behavior as when rendered outside a dialog.

😯 Current Behavior

Focus stays on the checkbox for a short time before being moved to the item.

StackBlitz Reproduction

https://stackblitz.com/edit/sqtykpby?file=src%2FExample.tsx

🖥️ Steps to Reproduce

  1. Click on "Oen GridList Dialog"
  2. Click on the input inside the dialog
  3. Press Tab to move focus into the grid
  4. Press ArrowDown to move focus to the 2nd item
  5. Press Shift + Tab to move focus back to the input
  6. Press Tab to move focus into the grid list

Focus should be immediately on the 2nd grid item, but it stays on the checkbox for a short moment before being moved to the 2nd grid item.

Same for the "Open Tree Dialog" example.

💁 Possible Solution

select() should probably only be called if the element is still focused.

🔦 Context

We're building a custom TreeSelect with a search inside the popover and this issue occured.

Version

react-aria-components@1.22.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Windows 11

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Activity

  1. okeken commented on Nov 23, 2026

    @okeken
    Contributor

    Confirmed on main in Chrome. It's easy to miss because focus usually ends up on the right row. The checkbox only flashes, then a re-render in the GridList moves focus back. If that re-render doesn't happen, focus stays on the checkbox. Jest tests don't catch it either, because jsdom's select() never moves focus.

    The cause is FocusScope calling select() after the GridList has already moved focus to the row; in Chrome, select() focuses the checkbox again. I'm opening a PR that only calls select() if the input still has focus, so focus no longer depends on a re-render to recover. It includes a Chromium test that fails on main and passes with the fix.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions