Skip to content

Commit 8a9aea9

Browse files
authored
Allow string dates in DatePicker (#783)
1 parent 2fdcf1c commit 8a9aea9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/core/src/components/DatePicker/DatePicker.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ type Props = {
5757
borderColor?: string;
5858
borderColorActive?: string;
5959
autoDismissKeyboard?: boolean;
60-
minimumDate?: Date;
61-
maximumDate?: Date;
60+
minimumDate?: Date | string;
61+
maximumDate?: Date | string;
6262
} & IconSlot &
6363
TextInputProps;
6464

@@ -531,8 +531,8 @@ const DatePicker: React.FC<React.PropsWithChildren<Props>> = ({
531531
mode={mode}
532532
isVisible={pickerVisible}
533533
toggleVisibility={toggleVisibility}
534-
minimumDate={minimumDate}
535-
maximumDate={maximumDate}
534+
minimumDate={parseDate(minimumDate)}
535+
maximumDate={parseDate(maximumDate)}
536536
onChange={(_event: any, data: any) => {
537537
toggleVisibility();
538538
setValue(data);
@@ -583,4 +583,11 @@ const styles = StyleSheet.create({
583583
},
584584
});
585585

586+
function parseDate(date?: string | Date) {
587+
if (typeof date === "string") {
588+
return new Date(date);
589+
}
590+
return date;
591+
}
592+
586593
export default withTheme(DatePicker);

0 commit comments

Comments
 (0)