Skip to content

Implement focus traps#6286

Merged
peppy merged 13 commits intoppy:masterfrom
smoogipoo:focus-trap
May 19, 2024
Merged

Implement focus traps#6286
peppy merged 13 commits intoppy:masterfrom
smoogipoo:focus-trap

Conversation

@smoogipoo
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@peppy
Copy link
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

When buttons are stacked on top of each other, the button below should not trigger Dropdowns aren't correctly isolating / blocking key bindings

3 participants