Repository navigation
root: Make Tab work before anything is focused - #4017
Open
HappyFox001 wants to merge 1 commit into
Open
HappyFox001 wants to merge 1 commit into
HappyFox001 wants to merge 1 commit into
Conversation
With nothing focused, GPUI dispatches keystrokes from the window's root node, above `div#root` where the `Root` key context lives, so Tab, Shift-Tab and copy matched no binding until a control had been clicked. `Root` now holds a focus handle whenever nothing else has focus: when the window opens (deferred, so content that focuses itself on open comes first) and from `on_focus_lost`. The handle is tracked on an empty child of the surface rather than the surface itself, so pressing the background does not take focus away from a focused control. Closes longbridge#4004. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
✅ LGTM: small Root-level fix so Tab/Shift-Tab work with nothing focused; no public API change.
Ran at 5552c4d on Linux: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4004.
Description
In a window opened with
gpui_kit::open_window, Tab and Shift-Tab do nothing until something has focus. If an app doesn't focus a control at startup, a keyboard user can't get into it. The same thing happens again after the focused control is removed or blurred.Cause.
Rootbinds Tab, Shift-Tab and copy in itsRootkey context, which is set ondiv#root. With nothing focused, GPUI dispatches a keystroke from the window's root node (focus_node_id_in_rendered_framefalls back toroot_node_id()). That node is theRootview's own element, one level abovediv#root, so the context isn't on the dispatch path and no binding matches.Fix.
Rootkeeps a focus handle and takes focus whenever nothing else has it:on_focus_lost, when the focused element is blurred or leaves the tree.The handle isn't a tab stop, so Tab from it goes to the first stop and Shift-Tab to the last, the same as from no focus.
The handle sits on an empty, zero-sized child of
div#rootrather than ondiv#rootitself. A focusable div takes focus on mouse down, so on the surface it would pull focus out of a focused input every time the background is clicked. The child has no role, so screen readers still announce the window, as they do today.control_steps.rshad a test that focused the first stop by hand to get around this. It now just presses Tab.No public API changes.
This change was written with AI assistance (Claude Code).
How to Test
New tests in
crates/kit/tests/integration/root_focus.rs:tab_in_a_window_with_nothing_focused_reaches_the_first_controlshift_tab_in_a_window_with_nothing_focused_reaches_the_last_controltab_reaches_the_controls_again_after_the_focused_one_goes_awaycontent_that_focuses_itself_when_the_window_opens_keeps_that_focuspressing_the_background_leaves_the_focused_control_focusedOn
mainthe first three fail. The last two pass with and without the fix; they check thatRootdoesn't take focus it shouldn't.Run on macOS (Apple Silicon):
These use GPUI test-window events. I haven't checked native keyboard input or a screen reader.
Checklist
cargo runfor story tests related to the changes. (Not run. The story gallery focuses its own root when it opens, so it doesn't show this bug; the tests above cover it.)🤖 Generated with Claude Code