Skip to content

Make popup focus stealing configurable. #16642

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

Merged
merged 8 commits into from
Sep 30, 2024
Merged

Conversation

grokys
Copy link
Member

@grokys grokys commented Aug 9, 2024

What does the pull request do?

#16365 removed focus stealing for popups, but this turns out that completely removing this isn't a good idea. Two example scenarios for focus stealing are:

  • A user is working in a native text box when an Avalonia ToolTip popups up: in his case, focus should remain in the native text box so the user can continue typing (no stealing)
  • A user is working in a native text box when an Avalonia ContextMenu is shown: in this case, focus should be transferred back to Avalonia to allow them to press the Down arrow to select the first item in the context menu (stealing)

I added a test scenario to IntegrationTestApp that shows the two desired behaviors:

  • Hover over the embedded text box to show an Avalonia ToolTip
  • Right-click the embedded text box to show an Avalonia ContextMenu

To control this behavior, I added an attached Popup.TakesFocusFromNativeControl property, which defaults to true (it's attached because you can set it directly on Popup or on a control that uses a popup - only ContextMenu respects this property currently). ToolTip sets the property to false for its inbuilt popup.

I'm not attached to this naming, please feel free to suggest alternatives.

  • Implement on Windows
  • Implement on macOS
  • [ ] Implement on X11 not in this PR
  • Implement integration test on Windows
  • [ ] Implement integration test on macOS Can't get integration tests to work on macOS

grokys added 2 commits August 9, 2024 12:55
In native text box in integration test app. Only implemented for win32 right now.

This is to test the two popup behaviors required for native controls:

- The context menu needs focus to be transferred to Avalonia
- The ToolTip must not transfer focus to Avalonia
By default, if a popup is shown when a native control is focused, focus is transferred back to Avalonia in order for the popup to receive input. If this property is set to false, then the shown popup will not receive input until it receives an interaction which explicitly focuses the popup, such as a mouse click.

The effect of this property can be seen in the Embedding tag of the IntegrationTestApp: hovering over the native text box shows an Avalonia `ToolTip` which does not steal focus from the native text box. Right-clicking to open an Avalonia `ContextMenu` does steal focus so the menu items can be selected using the arrow keys.

Currently only implemented on a win32.
@grokys grokys added the customer-priority Issue reported by a customer with a support agreement. label Aug 9, 2024
grokys added a commit that referenced this pull request Sep 13, 2024
This reverts commit e7d1b36 and
9d55d19.
@grokys grokys marked this pull request as ready for review September 30, 2024 13:11
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0052288-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

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

I left a comment regarding the attached property usage.
Other than that, LGTM!

@MrJul MrJul enabled auto-merge September 30, 2024 14:29
@MrJul MrJul added this pull request to the merge queue Sep 30, 2024
Merged via the queue into master with commit b272283 Sep 30, 2024
11 checks passed
@MrJul MrJul deleted the fixes/popup-focus-stealing-2 branch September 30, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug customer-priority Issue reported by a customer with a support agreement. enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants