Repository navigation
Description
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):
react-spectrum/packages/react-aria/src/focus/FocusScope.tsx
Lines 396 to 398 in 6be3466
| 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
- Click on "Oen GridList Dialog"
- Click on the input inside the dialog
- Press Tab to move focus into the grid
- Press ArrowDown to move focus to the 2nd item
- Press Shift + Tab to move focus back to the input
- 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
okeken commentedon Nov 23, 2026
Confirmed on
mainin 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'sselect()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 callsselect()if the input still has focus, so focus no longer depends on a re-render to recover. It includes a Chromium test that fails onmainand passes with the fix.