-
Notifications
You must be signed in to change notification settings - Fork 6k
gpui: Add focus_trap to group the tab focus
#34804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tab_group to group the tab focus
|
Ready for review |
This comment was marked as resolved.
This comment was marked as resolved.
After a moment think, I think split name is better, because |
|
Use for GPUI Component example: Screen.Recording.2025-07-22.at.19.08.25.mov |
tidely
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good, just some tiny nits that keep the code clear
crates/gpui/src/tab_stop.rs
Outdated
| prev_ix = self.handles.len().saturating_sub(1); | ||
| prev_ix = group_handles.len().saturating_sub(1); | ||
| } else { | ||
| prev_ix = ix.saturating_sub(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check that ix is larger than 0 before, so this doesn't need to be saturating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, even the ix is 0, the group_handles.len() may also 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should’ve been more clear with what line I meant, that’s my bad. I think it only applies to prev_ix = ix.saturating_sub(1); since we know ix isn’t zero
ed0ec39 to
b361b4a
Compare
Co-authored-by: tidely <[email protected]>
crates/gpui/src/window.rs
Outdated
|
|
||
| /// Set the tab group of this focus handle. | ||
| /// | ||
| /// If set, the focus cycle will loop in same group. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want focus to cycle when hitting the edge of a tab group. Rather, I think it would make more sense if focus continued on to the next tab stop after the group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, should you please explain more?
I am not got your point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this UI:
<tab-index = 0> <!---- If you hit tab here -->
<tab-group tab-index = 1>
<tab-index = 3>
<tab-index = 2> <!----- This is where you should end up -->
</tab-group>
<tab-index = 2>Calling focus_next repeatedly should result in an order like 0->2->3->1->0..., not 0->2->3->2->3->2->3...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I see.
|
@mikayla-maki Let me explain the meaning of this feature: The original intention is to add restrictions to tab focus for Modal and Popup scenarios, so that when Popup or Modal is opened, the tab focus always remains within the scope of the Modal, and is restored to other places after closing. Screen.Recording.2025-07-28.at.11.56.07.movThere is no such feature in HTML, but front-end components often implement it, and they use focus trap, such as:
Similar to Chrome: So, what if I rename this method to |
tab_group to group the tab focusfocus_trap to group the tab focus
This change adds the current tab index functionality to buttons and implements a proof of concept for the new welcome page. Primarily blocked on #34804, secondarily on #35075 so we can ensure navigation always works as intended. Another thing to consider here is whether we want to assign the tab order more implicitly / "automatically" based on the current layout ordering. This would generally enable us to add a default order to focusable elements if we want this. See [the specification](https://html.spec.whatwg.org/multipage/interaction.html#flattened-tabindex-ordered-focus-navigation-scope) on some more context on how the web usually handles this for focusable elements. Release Notes: - N/A
This change adds the current tab index functionality to buttons and implements a proof of concept for the new welcome page. Primarily blocked on zed-industries#34804, secondarily on zed-industries#35075 so we can ensure navigation always works as intended. Another thing to consider here is whether we want to assign the tab order more implicitly / "automatically" based on the current layout ordering. This would generally enable us to add a default order to focusable elements if we want this. See [the specification](https://html.spec.whatwg.org/multipage/interaction.html#flattened-tabindex-ordered-focus-navigation-scope) on some more context on how the web usually handles this for focusable elements. Release Notes: - N/A
|
#38531 is merged. |
Wait zed-industries/zed#33008, zed-industries/zed#34804 to merge. https://github.com/user-attachments/assets/3c21ebc9-44a0-4311-bb0f-5f63fe8d4bb3 - Improved `focus_ring` to render like an outline. - Added to support press `Enter`, `Space` key to trigger Checkbox, Button, Radio. ## Break Changes - The `FocusableExt` has been changed to only for crate internal. - The `FocusableCycle` has been removed, now GPUI has it own tab stop implementation.
Continue #33008 to add a
focus_trapoption method for let tabs with in group.This is used to help us to manage the focus loop when in some case like Modal, Popover.
Screen.Recording.2025-07-28.at.11.56.07.mov
Release Notes: