-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix DatePicker displays today's date instead of blank state when Date is null #30657
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes inconsistent DatePicker behavior across platforms when the Date property is set to null. Previously, DatePicker would display blank or inconsistent states when Date was null, but now it consistently shows today's date while preserving the null value in the virtual view.
Key changes:
- Updated platform-specific DatePickerExtensions to use DateTime.Today as fallback when Date is null
- Added comprehensive device tests to verify consistent behavior across all platforms
- Maintained separation between virtual view state (remains null) and platform display (shows today's date)
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Core/src/Platform/iOS/DatePickerExtensions.cs | Updated iOS date handling to use DateTime.Today fallback and improved display text logic |
src/Core/src/Platform/Windows/DatePickerExtensions.cs | Changed Windows fallback from DateTime.MinValue to DateTime.Today |
src/Core/src/Platform/Android/DatePickerExtensions.cs | Updated Android text display to show today's date instead of empty string when Date is null |
src/Controls/tests/DeviceTests/Elements/DatePicker/DatePickerTests.cs | Added comprehensive device tests to verify null date behavior across all platforms |
Comments suppressed due to low confidence (1)
src/Controls/tests/DeviceTests/Elements/DatePicker/DatePickerTests.cs:24
- This test should be added to TestCases.HostApp and TestCases.Shared.Tests following the UI testing pattern. Device tests are good for unit testing, but UI behavior validation should use the established UI testing infrastructure with AutomationIds.
[Fact(DisplayName = "DatePicker Null Date Behavior Across All Platforms")]
src/Controls/tests/DeviceTests/Elements/DatePicker/DatePickerTests.cs
Outdated
Show resolved
Hide resolved
{ | ||
// Scenario 1: Initial null date should show today's date | ||
datePicker.Date = null; | ||
await Task.Delay(100); |
Copilot
AI
Jul 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using arbitrary Task.Delay values makes tests brittle and slow. Consider using a more deterministic approach or at least use a constant for the delay value.
await Task.Delay(100); | |
await Task.Delay(DelayMilliseconds); |
Copilot uses AI. Check for mistakes.
{ | ||
// Scenario 1: Initial null date should show today's date | ||
datePicker.Date = null; | ||
await Task.Delay(100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is required the delay here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz ,No it is not required. Removed the delay.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root Cause
DatePicker
control displayed inconsistent behavior across platforms when theDate
property was set to null. This inconsistency occurred because the platform-specific extension methods in DatePickerExtensions.cs were directly passing empty values to native platform controls without proper fallback handling.Description of Change
Modified the
UpdateDate
extension method in platform-specificDatePickerExtensions.cs
files to handle null date values consistently across all platforms.datePicker.Date
is null, the platform view now displaysDateTime.Today
, instead of showing a blank/empty stateSupersedes to #30642
Issues Fixed
Fixes #30641
Tested the behaviour in the following platforms
BeforeFix.MAC.mov
AfterFix.MAC.mov
BeforeFix.iOS.mov
AfterFix.iOS.mov