Skip to content

Commit 5c65dbc

Browse files
committed
[Fix] Date format onesine#25
[Fix] Refresh `startFrom` when selection changes
1 parent 468aeab commit 5c65dbc

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Diff for: src/components/Datepicker.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ const Datepicker: React.FC<Props> = ({
140140

141141
const secondGotoDate = useCallback(
142142
(date: dayjs.Dayjs) => {
143-
const newDate = dayjs(formatDate(date));
144-
const reformatDate = dayjs(formatDate(firstDate));
143+
const newDate = dayjs(formatDate(date, displayFormat));
144+
const reformatDate = dayjs(formatDate(firstDate, displayFormat));
145145
if (newDate.isSame(reformatDate) || newDate.isBefore(reformatDate)) {
146146
setFirstDate(previousMonth(date));
147147
}
@@ -214,8 +214,8 @@ const Datepicker: React.FC<Props> = ({
214214
validDate && (startDate.isSame(endDate) || startDate.isBefore(endDate));
215215
if (condition) {
216216
setPeriod({
217-
start: formatDate(startDate),
218-
end: formatDate(endDate)
217+
start: formatDate(startDate, displayFormat),
218+
end: formatDate(endDate, displayFormat)
219219
});
220220
setInputText(
221221
`${formatDate(startDate, displayFormat)}${
@@ -233,6 +233,19 @@ const Datepicker: React.FC<Props> = ({
233233
}
234234
}, [asSingle, value, displayFormat, separator]);
235235

236+
useEffect(() => {
237+
if(startFrom && dayjs(startFrom).isValid()) {
238+
239+
if(value != null && value.startDate != null) {
240+
setFirstDate(dayjs(value.startDate))
241+
setSecondDate(nextMonth(dayjs(value.startDate)))
242+
} else {
243+
setFirstDate(dayjs(startFrom))
244+
setSecondDate(nextMonth(dayjs(startFrom)))
245+
}
246+
}
247+
}, [startFrom, value])
248+
236249
// Variable
237250
const colorPrimary = useMemo(() => {
238251
if (COLORS.includes(primaryColor)) {

0 commit comments

Comments
 (0)