Skip to content

Commit edcb393

Browse files
fix: DatePicker showing only selected day by default (#3169)
1 parent a0b13a5 commit edcb393

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/admin/components/elements/DatePicker/DatePicker.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const DateTime: React.FC<Props> = (props) => {
1616
const {
1717
value,
1818
onChange,
19-
displayFormat,
20-
pickerAppearance = "dayOnly",
19+
displayFormat: customDisplayFormat,
20+
pickerAppearance = 'default',
2121
minDate,
2222
maxDate,
2323
monthsToShow = 1,
@@ -39,20 +39,21 @@ const DateTime: React.FC<Props> = (props) => {
3939
console.warn(`Could not find DatePicker locale for ${locale}`);
4040
}
4141

42-
let dateTimeFormat = displayFormat;
42+
let dateFormat = customDisplayFormat;
4343

44-
if (dateTimeFormat === undefined && pickerAppearance) {
45-
if (pickerAppearance === 'dayAndTime') dateTimeFormat = 'MMM d, yyy h:mm a';
46-
else if (pickerAppearance === 'timeOnly') dateTimeFormat = 'h:mm a';
47-
else if (pickerAppearance === 'dayOnly') dateTimeFormat = 'dd';
48-
else if (pickerAppearance === 'monthOnly') dateTimeFormat = 'MMMM';
49-
else dateTimeFormat = 'MMM d, yyy';
44+
if (!customDisplayFormat) {
45+
// when no displayFormat is provided, determine format based on the picker appearance
46+
if (pickerAppearance === 'default') dateFormat = 'MM/dd/yyyy';
47+
else if (pickerAppearance === 'dayAndTime') dateFormat = 'MMM d, yyy h:mm a';
48+
else if (pickerAppearance === 'timeOnly') dateFormat = 'h:mm a';
49+
else if (pickerAppearance === 'dayOnly') dateFormat = 'MMM dd';
50+
else if (pickerAppearance === 'monthOnly') dateFormat = 'MMMM';
5051
}
5152

5253
const dateTimePickerProps = {
5354
minDate,
5455
maxDate,
55-
dateFormat: dateTimeFormat,
56+
dateFormat,
5657
monthsShown: Math.min(2, monthsToShow),
5758
showTimeSelect: pickerAppearance === 'dayAndTime' || pickerAppearance === 'timeOnly',
5859
minTime,

src/admin/components/elements/DatePicker/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
type SharedProps = {
22
displayFormat?: string
3-
pickerAppearance?: 'dayAndTime' | 'timeOnly' | 'dayOnly' | 'monthOnly'
3+
pickerAppearance?: 'default' | 'dayAndTime' | 'timeOnly' | 'dayOnly' | 'monthOnly'
44
}
55

66
type TimePickerProps = {
@@ -22,6 +22,9 @@ type MonthPickerProps = {
2222
}
2323

2424
export type ConditionalDateProps =
25+
| SharedProps & {
26+
pickerAppearance?: 'default'
27+
}
2528
| SharedProps & DayPickerProps & TimePickerProps & {
2629
pickerAppearance?: 'dayAndTime'
2730
}

0 commit comments

Comments
 (0)