Fix DatePickerPresenter focusing wrong selector for day-first locales#21116
Merged
MrJul merged 4 commits intoApr 9, 2026
Merged
Conversation
…resenter SetInitialFocus had a copy-paste bug where the day-first branch focused _monthSelector instead of _daySelector. This caused every locale that puts day first (UK, Europe, Australia, India — dd/MM/yyyy) to focus the wrong selector when the picker opened. Refactored the three near-identical if/else branches into a data-driven loop that pairs each host panel with its selector, making this class of copy-paste bug structurally impossible.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an initial-focus bug in DatePickerPresenter where day-first locales (e.g., en-GB with dd/MM/yyyy) could focus the wrong selector on open, and adds a regression unit test to ensure the leftmost visible column receives focus.
Changes:
- Reworked
DatePickerPresenter.SetInitialFocusto select the leftmost visible selector via a small candidate scan (avoids copy/paste branching bugs). - Added a unit test that sets
en-GBculture and asserts the day selector is focused on initialization. - Introduced a focus-enabled
TestServicesconfiguration for the new test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Avalonia.Controls.UnitTests/DatePickerTests.cs | Adds a regression test validating initial focus for day-first locales and introduces focus-capable test services. |
| src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs | Refactors initial focus selection to consistently focus the leftmost visible selector. |
|
You can test this PR using the following package version. |
MrJul
added a commit
to MrJul/Avalonia
that referenced
this pull request
Apr 13, 2026
…AvaloniaUI#21116) * fix: focus correct date selector for day-first locales in DatePickerPresenter SetInitialFocus had a copy-paste bug where the day-first branch focused _monthSelector instead of _daySelector. This caused every locale that puts day first (UK, Europe, Australia, India — dd/MM/yyyy) to focus the wrong selector when the picker opened. Refactored the three near-identical if/else branches into a data-driven loop that pairs each host panel with its selector, making this class of copy-paste bug structurally impossible. * chore: retrigger CI * chore: retrigger CI --------- Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
Fixes
DatePickerPresenter.SetInitialFocusfocusing the month selector instead of the day selector when the day column is leftmost (e.g.dd/MM/yyyylocales).What is the current behavior?
Copy-paste bug: the
dayCol < monthCol && dayCol < yearColbranch calls_monthSelector.Focus()instead of_daySelector.Focus(). Users in day-first locales (UK, Europe, Australia, India, etc.) get the wrong selector focused when the picker opens.What is the updated/expected behavior with this PR?
Replaced the three if/else branches with a data-driven loop that pairs each
(visible, host, selector)tuple and focuses the leftmost visible column. This fixes the bug and makes the same class of copy-paste error structurally impossible.Checklist