Skip to content

Commit

Permalink
feat(DatePicker): fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinsawicki committed Dec 19, 2024
1 parent 1abb2fe commit ae83adb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const RangeDatePicker = ({
initialToDate,
toMonth,
onChange,
onSelect,
children,
}: IRangeDatePickerProps): ReactElement => {
const prevSelectedItem = useRef<string | null>(
Expand Down Expand Up @@ -119,6 +120,17 @@ export const RangeDatePicker = ({
onChange(optionsHash[selectedItem]);
}, [onChange, state.selectedItem, options]);

const handleOnSelect = useCallback(() => {
const { from, to } = state;

if (from && to && onSelect) {
onSelect({
from,
to,
});
}
}, [onSelect]);

const handleDayMouseEnter = useCallback(
(day: Date) => {
const isInRange = toMonth
Expand Down Expand Up @@ -231,6 +243,7 @@ export const RangeDatePicker = ({
disabled: disabledDays,
onDayMouseEnter: handleDayMouseEnter,
onMonthChange: handleMonthChange,
onSelect: handleOnSelect,
},
selectedOption,
};
Expand Down
3 changes: 2 additions & 1 deletion packages/react-components/src/components/DatePicker/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Reducer, ReactElement } from 'react';

import { DayPickerProps } from 'react-day-picker';
import { DayPickerProps, DateRange } from 'react-day-picker';

export type IDatePickerProps = DayPickerProps;

Expand Down Expand Up @@ -92,5 +92,6 @@ export interface IRangeDatePickerProps {
initialToDate?: Date;
toMonth?: Date;
onChange: (selected: IRangeDatePickerOption | null) => void;
onSelect?: (selected: DateRange | null) => void;
children(payload: IRangeDatePickerChildrenPayload): ReactElement;
}

0 comments on commit ae83adb

Please sign in to comment.