Skip to content

Commit

Permalink
Merge pull request #94 from EliranSiboni/fix-set-min-date-as-first-da…
Browse files Browse the repository at this point in the history
…te-when-available

Fix: set min date as first date to show when available
  • Loading branch information
farhoudshapouran authored Jul 16, 2024
2 parents 8a3aaab + ef298ac commit f5fc0a5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/DateTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const DateTimePicker = (
currentDate = dayjs(dates[0]);
}

if (minDate && currentDate.isBefore(minDate)) {
currentDate = dayjs(minDate);
}

let currentYear = currentDate.year();

dayjs.locale(locale);
Expand Down Expand Up @@ -162,7 +166,8 @@ const DateTimePicker = (

useEffect(() => {
if (mode === 'single') {
const newDate = date && (timePicker ? date : getStartOfDay(date));
const newDate =
(date && (timePicker ? date : getStartOfDay(date))) ?? minDate;

dispatch({
type: CalendarActionKind.CHANGE_SELECTED_DATE,
Expand All @@ -179,7 +184,7 @@ const DateTimePicker = (
payload: { dates },
});
}
}, [mode, date, startDate, endDate, dates, timePicker]);
}, [mode, date, startDate, endDate, dates, minDate, timePicker]);

const setCalendarView = useCallback((view: CalendarViews) => {
dispatch({ type: CalendarActionKind.SET_CALENDAR_VIEW, payload: view });
Expand Down

0 comments on commit f5fc0a5

Please sign in to comment.