From 79e9e15b05476aa551dc5e13919b6360d924e808 Mon Sep 17 00:00:00 2001 From: cong Date: Fri, 14 Jul 2023 10:35:24 +0800 Subject: [PATCH 1/2] fix: date picker input default date --- .../DatePickerInput/DatePickerInput.story.tsx | 9 +++++++++ .../components/DatePickerInput/DatePickerInput.tsx | 13 +++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.story.tsx b/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.story.tsx index 7c334372708..096a8c44491 100644 --- a/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.story.tsx +++ b/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.story.tsx @@ -215,3 +215,12 @@ export function InOverlays() { ); } + +export function DefaultDate() { + return ( +
+ + +
+ ); +} diff --git a/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx b/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx index bbd6305a398..f00c93f6071 100644 --- a/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx +++ b/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx @@ -15,7 +15,7 @@ export type DatePickerInputStylesNames = PickerInputBaseStylesNames; export interface DatePickerInputProps extends DateInputSharedProps, - DatePickerBaseProps { + DatePickerBaseProps { /** Dayjs format to display input value, "MMMM D, YYYY" by default */ valueFormat?: string; } @@ -51,6 +51,7 @@ export const DatePickerInput: DatePickerInputComponent = forwardRef((props, ref) sortDates, maxDate, minDate, + defaultDate: _defaultDate, ...rest } = useComponentDefaultProps('DatePickerInput', defaultProps, props); @@ -76,6 +77,10 @@ export const DatePickerInput: DatePickerInputComponent = forwardRef((props, ref) sortDates, }); + const defaultDate = _defaultDate || (Array.isArray(_value) + ? _value[0] || getDefaultClampedDate({ maxDate, minDate }) + : _value || getDefaultClampedDate({ maxDate, minDate })); + return ( Date: Fri, 14 Jul 2023 11:15:51 +0800 Subject: [PATCH 2/2] fix: code format --- .../src/components/DatePickerInput/DatePickerInput.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx b/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx index f00c93f6071..e12542d4e2e 100644 --- a/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx +++ b/src/mantine-dates/src/components/DatePickerInput/DatePickerInput.tsx @@ -15,7 +15,7 @@ export type DatePickerInputStylesNames = PickerInputBaseStylesNames; export interface DatePickerInputProps extends DateInputSharedProps, - DatePickerBaseProps { + DatePickerBaseProps { /** Dayjs format to display input value, "MMMM D, YYYY" by default */ valueFormat?: string; } @@ -77,9 +77,11 @@ export const DatePickerInput: DatePickerInputComponent = forwardRef((props, ref) sortDates, }); - const defaultDate = _defaultDate || (Array.isArray(_value) - ? _value[0] || getDefaultClampedDate({ maxDate, minDate }) - : _value || getDefaultClampedDate({ maxDate, minDate })); + const defaultDate = + _defaultDate || + (Array.isArray(_value) + ? _value[0] || getDefaultClampedDate({ maxDate, minDate }) + : _value || getDefaultClampedDate({ maxDate, minDate })); return (