Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Initial visible month

If `isDateBlocked` returns `true`, then the date is blocked.

#### `changeActiveMonthOnSelect?: boolean`

If this is false, the active month panel will not change when selecting the start date.

### `unavailableDates?: Date[]`

Receives unavailable dates in array.
Expand Down
17 changes: 10 additions & 7 deletions packages/hooks/src/useDatepicker/useDatepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface UseDatepickerProps {
initialVisibleMonth?: Date
isDateBlocked?(date: Date): boolean
unavailableDates?: Date[]
changeActiveMonthOnSelect?: boolean
}

export function useDatepicker({
Expand All @@ -61,6 +62,7 @@ export function useDatepicker({
firstDayOfWeek = 1,
isDateBlocked: isDateBlockedProps = () => false,
unavailableDates = [],
changeActiveMonthOnSelect = true,
}: UseDatepickerProps) {
const [activeMonths, setActiveMonths] = useState(() =>
startDate
Expand All @@ -73,15 +75,15 @@ export function useDatepicker({
useEffect(() => {
if (typeof window !== 'undefined') {
if (window.addEventListener) {
window.addEventListener('keydown', handleKeyDown)
window.addEventListener('keydown', handleKeyDown)
}
}

return () => {
if (window.removeEventListener) {
window.removeEventListener('keydown', handleKeyDown)
}

return () => {
if (window.removeEventListener) {
window.removeEventListener('keydown', handleKeyDown)
}
}
})

const disabledDatesByUser = (date: Date) => {
Expand Down Expand Up @@ -228,7 +230,8 @@ export function useDatepicker({

if (
focusedInput !== END_DATE &&
(!focusedDate || (focusedDate && !isSameMonth(date, focusedDate)))
(!focusedDate || (focusedDate && !isSameMonth(date, focusedDate))) &&
changeActiveMonthOnSelect
) {
setActiveMonths(getInitialMonths(numberOfMonths, date))
}
Expand Down