Skip to content

Fix focus not being lost when a parent element is hidden #18916

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

Conversation

TomEdwardsEnscape
Copy link
Contributor

@TomEdwardsEnscape TomEdwardsEnscape commented May 25, 2025

InputElement now clears focus from child elements when IsVisible changes to false. Previously, it only cleared focus from itself.

The FocusManager.ClearFocusOnElementRemoved method is now called, with FocusManager.ClearFocus used only as a fallback in case we can't provide parameters (which would indicate an invalid state). This seems sensible to me since as far as the focus manager is concerned, a hidden element has been removed.

The Focus_Should_Be_Cleared_When_Control_Is_Effectively_Hidden test has also been enabled.

Breaking changes

None.

Obsoletions / Deprecations

None.

Fixed issues

Fixes #18817

@avaloniaui-bot
Copy link

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

@TomEdwardsEnscape TomEdwardsEnscape force-pushed the fixes/clear-focus-when-not-effectivelyvisible branch from 69b6ef2 to d04beaf Compare May 25, 2025 15:28
@avaloniaui-bot
Copy link

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

@TomEdwardsEnscape TomEdwardsEnscape force-pushed the fixes/clear-focus-when-not-effectivelyvisible branch from d04beaf to e440f50 Compare May 25, 2025 18:11
@TomEdwardsEnscape TomEdwardsEnscape changed the title Fix focus not being lost when an element is hidden Fix focus not being lost when a parent element is hidden May 25, 2025
@avaloniaui-bot
Copy link

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

Copy link
Member

@grokys grokys left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@grokys grokys added this pull request to the merge queue May 26, 2025
Merged via the queue into AvaloniaUI:master with commit fa9f223 May 26, 2025
10 checks passed
@grokys grokys deleted the fixes/clear-focus-when-not-effectivelyvisible branch May 26, 2025 08:24
@MrJul MrJul added bug backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels May 31, 2025
MrJul pushed a commit that referenced this pull request Jun 5, 2025
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jun 5, 2025
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.

FocusAdorner remains after the element has been hidden
4 participants