-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Closing Popup sets wrong focus. #13325
Comments
For expected behavior, I would argue it should be: Additional context: Take this code in InputElement:
What it does here is to say if this control is focused in it's scope clear focus for the app. The introduction of |
But by clicking the "Click me to delete to set focus to null" button, the "Show" button is no longer focused. So if this were to be refocused on close, then we might have unwanted behavior again.
There are no focus scopes in play here. The only focus scope is the |
PopupRoot is a focus scope. It doesn't matter in this version of the example since we use the delete buttons to make focus null. The focus scope issue is probably best defined as a separate issue. The reason why I argued the "Show" should have focus is not because it had focus before you click the delete button. I should have probably made a separate "Hide" button for the example. When you click the "Show" button to hide the popup you expect the button to get focus because you click it. In the example above the "Show" button has Focusable set to false, though. So I guess expected focus should be that it remains null. |
Are you sure? It doesn't implement
But the "Show" button is explicitly marked as non-focusable? |
PopupRoot implements IPopupHost which implements IFocusScope. Yes. So in this example it shouldn't. |
Ah ok sorry, I missed that transitive reference. Ok, there's definitely something wrong with focus scopes in this case then. Investigating further. |
Tested this with WPF, and WPF sets the keyboard focus via the following mechanism:
The end result being that the focused element in the |
My suggestion is to remove the hackfix in #4809 and modify our focus scopes to restore focus to any outermost focus scope when
Note that the above isn't special-casing the root focus scope, it's just that we're removing the control from the root focus scope and so it by definition won't have a focused element. Pinging @maxkatz6 @amwx for feedback as you've both worked on focus more recently than me. |
- Store focused element within a scope using an attached property (like WPF) - Store current focus root so that focus can be restored to that root when a focused control or active focus scope is removed Fixes #13325
* Remove focus hack from Popup. * Added failing focus scope tests. * Refactor focus scopes in FocusManager. - Store focused element within a scope using an attached property (like WPF) - Store current focus root so that focus can be restored to that root when a focused control or active focus scope is removed Fixes #13325 * Suppress API compat error. This was being produced for a compiler-generated enumerable class that was erroneously being included in the reference assembly for `FocusManager`. * Remove focus hack from ContextMenu. And add failing test now that the hack is removed. * Try to return a rooted host visual. Fixes failing test from previous comment where focus wasn't restored when closing a context menu.
* Remove focus hack from Popup. * Added failing focus scope tests. * Refactor focus scopes in FocusManager. - Store focused element within a scope using an attached property (like WPF) - Store current focus root so that focus can be restored to that root when a focused control or active focus scope is removed Fixes #13325 * Suppress API compat error. This was being produced for a compiler-generated enumerable class that was erroneously being included in the reference assembly for `FocusManager`. * Remove focus hack from ContextMenu. And add failing test now that the hack is removed. * Try to return a rooted host visual. Fixes failing test from previous comment where focus wasn't restored when closing a context menu. #Conflicts: # src/Avalonia.Controls/Primitives/Popup.cs
Describe the bug
Closing a popup can set focus to the wrong control. Reported by @jankrib .
To Reproduce
Expected behaviour
Either:
Environment
Additional context
This behaviour was added in #4809 which said:
This may be a better solution. An even better solution might be to let our focus scope code handle this.
The text was updated successfully, but these errors were encountered: