Skip to content
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

Implement focus traps #6286

Merged
merged 13 commits into from
May 19, 2024
Merged

Implement focus traps #6286

merged 13 commits into from
May 19, 2024

Conversation

smoogipoo
Copy link
Contributor

Fixes ppy/osu#25769
Fixes ppy/osu#26079 (likely)
Supersedes / closes #6095
Closes #6097 (note that ppy/osu#25850 is likely not fixed by this and will need reimplementation)

By extracting focus-management logic out of InputManager, we can implement something akin to a focus trap. Components can trap the focus management (ChangeFocus()/TriggerFocusContention()) of their subcomponents to add supplementary logic.

This PR features a partial redesign of Dropdown making use of this. There are two components wanting to manage focus here - the Menu and the TextBox.

  • The Menu's focus is trapped by Dropdown and reduced to a no-op.
  • The TextBox's focus is trapped within DropdownSearchBox to perform additional functionality such as opening the dropdown on focus, selecting items on commit, clearing text on escape, etc.

This is not a breaking change, but I've obsoleted InputManager.TriggerFocusContention() and InputManager.ChangeFocus() partially to make this easy to test.

Comment on lines 75 to 86
// On mobile platforms, let's not make the keyboard popup unless the dropdown is intentionally searchable.
// Unfortunately it is not enough to just early-return here,
// as even despite that the text box will receive focus via the text box input manager;
// it is necessary to cut off the text box input manager from parent input entirely.
// TODO: preferably figure out a better way to do this.
bool willShowOverlappingKeyboard = host?.OnScreenKeyboardOverlapsGameWindow == true;

if (willShowOverlappingKeyboard && !AlwaysDisplayOnFocus)
{
textBoxInputManager.UseParentInput = false;
return;
}
Copy link
Contributor Author

@smoogipoo smoogipoo May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't yet tested whether removing this is an issue (likely is). The logic here is quite convoluted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 5724733. It's touching some scary code but I think it makes sense.

@frenzibyte
Copy link
Member

I've added tests in my other PR to ensure the issues linked above are specifically fixed (see cf31661), worth adding in this PR.

For ppy/osu#25850, I would just disable searching in TabControls and call it a day. I can open a separate PR for that.

@smoogipoo
Copy link
Contributor Author

@frenzibyte Thanks. Added your tests almost verbatim in the last commit.

@peppy peppy self-requested a review May 19, 2024 05:54
@peppy peppy merged commit fdb335b into ppy:master May 19, 2024
21 checks passed
@peppy
Copy link
Member

peppy commented May 19, 2024

Definitely better than the other approach, let's see how this pans out 😄 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants