Skip to content

Commit 0c422e7

Browse files
committed
Added displayFormat prop to change the text didplay of the selected dates
1 parent 351bcbd commit 0c422e7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/components/Datepicker.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interface Props {
4646
disabled?: boolean;
4747
inputClassName?: string | null;
4848
containerClassName?: string | null;
49+
displayFormat?: string;
4950
}
5051

5152
const Datepicker: React.FC<Props> = ({
@@ -63,7 +64,8 @@ const Datepicker: React.FC<Props> = ({
6364
i18n = "en",
6465
disabled = false,
6566
inputClassName = null,
66-
containerClassName = null
67+
containerClassName = null,
68+
displayFormat = "YYYY-MM-DD"
6769
}) => {
6870
// Ref
6971
const containerRef = useRef<HTMLDivElement>(null);
@@ -214,7 +216,9 @@ const Datepicker: React.FC<Props> = ({
214216
end: formatDate(endDate)
215217
});
216218
setInputText(
217-
`${formatDate(startDate)}${asSingle ? "" : ` ~ ${formatDate(endDate)}`}`
219+
`${formatDate(startDate, displayFormat)}${
220+
asSingle ? "" : ` ~ ${formatDate(endDate, displayFormat)}`
221+
}`
218222
);
219223
}
220224
}
@@ -225,7 +229,7 @@ const Datepicker: React.FC<Props> = ({
225229
end: null
226230
});
227231
}
228-
}, [asSingle, value]);
232+
}, [asSingle, value, displayFormat]);
229233

230234
// Variable
231235
const colorPrimary = useMemo(() => {

0 commit comments

Comments
 (0)