fix(DateInput): correctly display time in controlled mode when valueF… #8587
+120
−4
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.
This PR fixes issue #8556 where DateInput component could not correctly display time values in controlled mode when the
valueFormatprop includes time tokens.Problem
The DateInput component, when used in controlled mode with time formats like
"YYYY-MM-DD HH:mm", would always display00:00instead of the actual time value. This happened because:useUncontrolledDateshook was hardcoded to usewithTime: falsedefaultDateParserdidn't handle time formats properlydate-string-parserhad limited format supportSolution
Changes Made:
Intelligent Time Token Detection (
DateInput.tsx)TIME_TOKENSarray with tokens:['H', 'HH', 'h', 'hh', 'm', 'mm', 's', 'ss', 'A', 'a']hasTimeInFormatdetection:TIME_TOKENS.some((token) => valueFormat.includes(token))Enhanced Date Parsing (
DateInput.tsx)defaultDateParserto use locale fallback:ctx.getLocale(locale) || 'en'hasTimeInFormat ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD'formatValuewith locale fallbackImproved useUncontrolledDates Integration (
DateInput.tsx)withTime: hasTimeInFormattouseUncontrolledDatesEnhanced Date String Parser (
date-string-parser/date-string-parser.ts)'MMMM D, YYYY','DD/MM/YYYY','MM/DD/YYYY','D/M/YYYY','YYYY/MM/DD'Comprehensive Test Coverage (
DateInput.test.tsx)Before (broken):
// Displays: "2024-12-18 00:00" ❌After (fixed):
// Displays: "2024-12-18 14:30" ✅Fixes DateInput cannot correctly display input value when it is controlled #8556