Skip to content

Return false by default from FocusManager.CanHaveFocusableChildren - #21640

Merged
MrJul merged 3 commits into
AvaloniaUI:masterfrom
Smartbox-Assistive-Technology:Issue21620-FocusManager-CanHaveFocusableChildren-Partial-Fix
Jul 3, 2026
Merged

MrJul merged 3 commits into
AvaloniaUI:masterfrom
Smartbox-Assistive-Technology:Issue21620-FocusManager-CanHaveFocusableChildren-Partial-Fix

Conversation

@freddiesmartbox

@freddiesmartbox freddiesmartbox commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

What does the pull request do?

  • Changes FocusManager.CanHaveFocusableChildren to return false by default.
  • Adds tests for FocusManager to check that it can successfully navigate past un-focusable controls

What is the current behavior?

Current behaviour is that some controls (e.g. empty StackPanels and TextBlocks) which should be skipped cause the search for a candidate to fail because FocusHelpers.CanHaveFocusableChildren incorrectly returns true for them.

What is the updated/expected behavior with this PR?

FocusManager should correctly skip unfocusable elements.

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

FocusHelpers.CanHaveFocusableChildren appears to incorrectly return true for all non-null parameters. It looks like the intention was to default to false and then only return true if a positive condition is met (supported not only by the fact that the current behaviour makes no sense, but by the break condition at the end of the loop). This is implemented.

Checklist

  • Added unit tests (if possible)?
    • I've added some tests that relate to a specific scenario we care about; happy to add more, either against the FocusHelpers class itself or other methods that depend on FocusHelpers.CanHaveFocusableChildren if desirable
  • Added XML documentation to any related classes?
  • Consider submitting a PR to https://github.com/AvaloniaUI/avalonia-docs with user documentation

Breaking changes

Behaviour of FocusHelpers.CanHaveFocusableChildren is dramatically changed; likely that existing code relying on it is not working as expected currently.

Obsoletions / Deprecations

N/A

Fixed issues

Fixes #21620

@freddiesmartbox
freddiesmartbox force-pushed the Issue21620-FocusManager-CanHaveFocusableChildren-Partial-Fix branch from c2c5dc3 to afef661 Compare June 24, 2026 10:25
@MrJul MrJul added bug backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch labels Jun 24, 2026
@avaloniaui-bot

Copy link
Copy Markdown

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

@cla-avalonia

cla-avalonia commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.

@freddiesmartbox

Copy link
Copy Markdown
Contributor Author

(awaiting confirmation from employer re cla)

@freddiesmartbox
freddiesmartbox force-pushed the Issue21620-FocusManager-CanHaveFocusableChildren-Partial-Fix branch from afef661 to f11b583 Compare June 25, 2026 10:00
@freddiesmartbox

Copy link
Copy Markdown
Contributor Author

@cla-avalonia agree

Importantly, this will return false for controls that are not focusable (e.g. TextBlock) or that have no focusable childen (e.g. an empty StackPanel)
@freddiesmartbox
freddiesmartbox force-pushed the Issue21620-FocusManager-CanHaveFocusableChildren-Partial-Fix branch from f11b583 to 7f5c7b5 Compare June 26, 2026 07:14
@avaloniaui-bot

Copy link
Copy Markdown

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

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@MrJul
MrJul added this pull request to the merge queue Jul 3, 2026
Merged via the queue into AvaloniaUI:master with commit 88a1fc1 Jul 3, 2026
10 checks passed
@freddiesmartbox
freddiesmartbox deleted the Issue21620-FocusManager-CanHaveFocusableChildren-Partial-Fix branch July 3, 2026 11:24
@MrJul MrJul removed the backport-candidate-12.0.x Consider this PR for backporting to 12.0 branch label Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FocusHelpers.CanHaveFocusableChildren always returns true if its argument is non-null

4 participants