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

Fixed FocusScopes functionality (#10433) #12827

Closed
wants to merge 3 commits into from

Conversation

HermanKirshin
Copy link
Contributor

Pls review thoroughly

What does the pull request do?

See #10433

What is the current behavior?

Menu steals focus from other controls.

What is the updated/expected behavior with this PR?

It works like in WPF, control outside focus scope keeps focused state.

How was the solution implemented (if it's not obvious)?

  • moved raising GotFocusEvent and LostFocusEvent to FocusManager to avoid raising LostFocusEvent on controls in another focus scope
  • added FocusWithin property that if element or one of its children has IsFocused, it depends on focus scope while IsKeyboardFocusWithin does not
  • added ability to get list of focused elements from multiple focus scopes (not used inside Avalonia sources, but this is useful for
  • added ClearFocus method to prevent losing focus from another focus scopes

Breaking changes

It slightly changes :focus-within pseudoclass meaning, which may be a breaking change for someone (I tried to find another name, but for consistency between property and pseudoclass names, renamed old pseudoclass to :keyboard-focus-within).
Also LostFocus event will not be called when focusing something in another focus scope.

Fixed issues

Fixes #10433

…id raising LostFocusEvent on controls in another focus scope

added FocusWithin property that if element or one of its children has IsFocused, it depends on focus scope while IsKeyboardFocusWithin does not
added ability to get list of focused elements from multiple focus scopes
added ClearFocus method to prevent losing focus from another focus scopes
@kekekeks kekekeks requested a review from grokys September 8, 2023 13:49
@kekekeks
Copy link
Member

kekekeks commented Sep 8, 2023

Need a spec + spec review

@maxkatz6
Copy link
Member

maxkatz6 commented Sep 8, 2023

Overall idea is to complete this spec: #7607
Any other refactoring shouldn't conflict with that.

@HermanKirshin
Copy link
Contributor Author

HermanKirshin commented Jan 31, 2024

This PR is not relevant anymore. Because IFocusScope now is not client implementable and after refactorings that allow to return focus to previous control after menu/popup close (in 13409) there is not much point in implementing smth advanced with focus scopes.

The only thing that is still not very convenient - when in menu item handler it is needed to do smth with focused element in the main scope, not MenuItem returned by FocusManager. But posting handler to dispatcher so it will be executed after popup closing and returning focus to previous control is a sufficient workaround for such case.

@HermanKirshin HermanKirshin deleted the fixes/10433 branch January 31, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Focus scopes are not working
4 participants