Skip to content

Add cause field to FocusGained event#23993

Merged
alice-i-cecile merged 16 commits intobevyengine:mainfrom
jordanhalase:focus_gained_tabbed
Apr 26, 2026
Merged

Add cause field to FocusGained event#23993
alice-i-cecile merged 16 commits intobevyengine:mainfrom
jordanhalase:focus_gained_tabbed

Conversation

@jordanhalase
Copy link
Copy Markdown
Contributor

Objective

  • Users would like the ability to know how a focus was gained

Solution

  • Add FocusCause field to FocusGained event
  • Automatically select all when navigating into a text input (even without SelectAllOnFocus)

Testing

  • Tab into the color input of feathers_gallery to test that its text gets highlighted

@jordanhalase
Copy link
Copy Markdown
Contributor Author

jordanhalase commented Apr 26, 2026

This touches on many different files, please let me know if the choices to propagate FocusCause::Pressed vs. FocusCause::Navigated were correct.

  1. As it currently stands, middle-clicking or secondary-clicking will propagate a FocusCause::Navigated event, only primary clicking sends a FocusCause::Pressed. This may be intentional. EditableText::on_focus_select_all() currently relies on this being the case.

    On Discord we've decided to go the route for using FocusCause::Navigated for unknown or default cases and non-primary mouse presses. This also distinguishes its behavior for future right-click menus.

  2. The default behavior for HTML inputs is to always highlight all text when tabbed/navigated into so I followed that behavior. I don't know if it's worth opting out of this with some NoSelectAllOnNavigation marker to preserve previously highlighted text when tabbing back to it. (Could be useful for larger multi-line text inputs)

    For now I am following the HTML standard of selecting all for single line inputs on navigation or retaining selection for multiline inputs

@jordanhalase
Copy link
Copy Markdown
Contributor Author

Closes #23976

@alice-i-cecile
Copy link
Copy Markdown
Member

Can you say more about why this is useful? I think I have an intuition, but it's helpful to write it down explicitly.

@viridia
Copy link
Copy Markdown
Contributor

viridia commented Apr 26, 2026

Looks good overall. One issue to consider is whether "initial" focus should be considered "navigated" or "pressed".

For example, when a modal dialog opens, it is common practice to set focus to some widget inside the dialog. If the dialog contains a text input field, then we will want to select all the text so that the user can immediately start typing, without having to click on it. Similar logic goes for input fields with the AutoFocus marker.

Other widgets that automatically set focus on opening are popup menus, but in that case it doesn't matter. However, for consistency, I would suggest that "navigated" be the choice for any widget that is automatically focused when it appears. (We could add a third option to the FocusCause enum, but I don't see the need and it would make the logic more complex.)

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-UI Graphical user interfaces, styles, layouts, and widgets S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 26, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI Apr 26, 2026
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 26, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 26, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Apr 26, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 26, 2026
Merged via the queue into bevyengine:main with commit 1dac2ec Apr 26, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from Needs SME Triage to Done in UI Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants