KEMBAR78
Fix DatePicker displays today's date instead of blank state when Date is null by prakashKannanSf3972 · Pull Request #30657 · dotnet/maui · GitHub
Skip to content

Conversation

prakashKannanSf3972
Copy link
Contributor

@prakashKannanSf3972 prakashKannanSf3972 commented Jul 16, 2025

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

  • The DatePicker control displayed inconsistent behavior across platforms when the Date 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-specific DatePickerExtensions.cs files to handle null date values consistently across all platforms.

Supersedes to #30642

Issues Fixed

Fixes #30641

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac
Before After
BeforeFix.MAC.mov
AfterFix.MAC.mov
BeforeFix.iOS.mov
AfterFix.iOS.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jul 16, 2025
@prakashKannanSf3972 prakashKannanSf3972 marked this pull request as ready for review July 17, 2025 11:15
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 11:15
@prakashKannanSf3972 prakashKannanSf3972 requested a review from a team as a code owner July 17, 2025 11:15
Copy link
Contributor

@Copilot Copilot AI left a 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")]

{
// Scenario 1: Initial null date should show today's date
datePicker.Date = null;
await Task.Delay(100);
Copy link

Copilot AI Jul 17, 2025

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.

Suggested change
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);
Copy link
Contributor

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?

Copy link
Contributor

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.

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen PureWeen moved this from Todo to Ready To Review in MAUI SDK Ongoing Aug 4, 2025
@rmarinho
Copy link
Member

rmarinho commented Aug 7, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

rmarinho
rmarinho previously approved these changes Aug 7, 2025
@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Aug 7, 2025
@PureWeen PureWeen added the p/0 Work that we can't release without label Aug 7, 2025
@rmarinho
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@rmarinho rmarinho merged commit a965afa into dotnet:net10.0 Aug 14, 2025
129 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Aug 14, 2025
@PureWeen PureWeen added the area-controls-datetimepicker DatePicker, TimePicker label Aug 20, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-datetimepicker DatePicker, TimePicker community ✨ Community Contribution p/0 Work that we can't release without partner/syncfusion Issues / PR's with Syncfusion collaboration

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants