Skip to content

Keep focus in the text box when an AutoCompleteBox item is picked - #22356

Merged
MrJul merged 7 commits into
AvaloniaUI:mainfrom
Evan260:fix-autocompletebox-dropdown-focus
Oct 26, 2026
Merged

MrJul merged 7 commits into
AvaloniaUI:mainfrom
Evan260:fix-autocompletebox-dropdown-focus

Conversation

@Evan260

@Evan260 Evan260 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What does the pull request do?

Keeps the AutoCompleteBox drop-down open while focus is inside it, so picking an item with the mouse commits the item.

What is the current behavior?

The drop-down is its own popup, so pressing an item moves focus into it. OnLostFocus closes the popup immediately, which means PointerReleased never reaches the selector and the commit never runs. The text box shows the picked item, but focus never returns to it, so a Text binding with UpdateSourceTrigger=LostFocus is left holding whatever was typed before the click.

Picking with the keyboard works, because focus stays in the text box the whole time.

What is the updated/expected behavior with this PR?

OnLostFocus ignores focus moving into the drop-down, so the popup stays open until the item is committed. Items keep their normal focus behaviour and pointer handling is untouched.

Checklist

Fixed issues

Fixes #22246

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

NuGet packages

The packages for this pull request have been published (workflow run):

@MrJul MrJul added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch area-controls labels Sep 30, 2026

@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.

I don't think this is the right approach.

For comparison, ComboBox items are focusable, and we should keep the same behavior here. I'm also worried about the impact on accessibility and automation, but I haven't tested them yet.

This PR introduces a real regression: touch/pen don't close the box anymore. This seems to be actually a pre-existing bug that was previously hidden by the focus change, so in the end it worked.

In addition, if there's any focusable control in the container itself from an item template (a niche scenario, I admit), the fix won't work. We need a more general solution here.

@Evan260

Evan260 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Sure, I changed the approach. The real problem was that OnLostFocus closed the popup on pointer down, so PointerReleased never reached the selector and the commit never ran, which is why the text never made it to the source. OnLostFocus now ignores focus moving into the drop-down itself, so items stay focusable and nothing about pointer handling changes.

@MrJul
MrJul added this pull request to the merge queue Oct 26, 2026
Merged via the queue into AvaloniaUI:main with commit 99086ac Oct 26, 2026
10 checks passed
@Evan260
Evan260 deleted the fix-autocompletebox-dropdown-focus branch October 26, 2026 18:45
MrJul added a commit that referenced this pull request Nov 2, 2026
…2356)

* Add a test for AutoCompleteBox drop-down items not taking focus

* Keep focus in the text box when an AutoCompleteBox item is picked

* Keep the pointer handler's doc comment with its method

* Simplify comment

* Add test

* Keep the drop-down open while focus is inside it

---------

Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Nov 2, 2026
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.

Autocomplete box not committing selected item from drop down

3 participants