Skip to content

Commit

Permalink
Start date picker at min/max selectable date if applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuruuh committed Apr 2, 2024
1 parent b32a42b commit 0438757
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ const DatePicker: FC<DatePickerProps> = ({
[dayjs],
);
const [temporarySelectedDate, setTemporarySelectedDate] = useState(
dayFactory().day(dayjs().localeData().firstDayOfWeek()),
minimumSelectableDate ??
maximumSelectableDate ??
dayFactory().day(dayjs().localeData().firstDayOfWeek()),
);
const setTemporarySelectedDateDecorator: Setter<Dayjs> = (date) => {
const unwrappedDate =
typeof date === 'function' ? date(temporarySelectedDate) : date;
return setTemporarySelectedDate(unwrappedDate.date(1));
};

const setTemporarySelectedDateDecorator: Setter<Dayjs> = (date) =>
setTemporarySelectedDate(date.date(1));

const controlFactory = useControlFactory(
temporarySelectedDate,
Expand Down
1 change: 1 addition & 0 deletions src/definition.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dayjs/plugin/weekOfYear';
import 'dayjs/plugin/utc';
import 'dayjs/plugin/localeData';
import 'dayjs/plugin/minMax';
import 'vite/client';
4 changes: 1 addition & 3 deletions src/types/Setter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
import type { Dispatch, SetStateAction } from 'react';

export type Setter<T> = Dispatch<SetStateAction<T>>;
export type Setter<T> = (value: T) => void;

0 comments on commit 0438757

Please sign in to comment.