Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix DatePickerProps #4932

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
67 changes: 43 additions & 24 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
| "selectsMultiple"
| "dropdownMode"
> &
Pick<AdditionalProps, "excludeScrollbar"> &
Partial<Pick<AdditionalProps, "excludeScrollbar">> &
Pick<CalendarIconProps, "icon"> &
Omit<PortalProps, "children" | "portalId"> &
Omit<
Expand Down Expand Up @@ -197,7 +197,7 @@
onChangeRaw?: (
event?: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>,
) => void;
onSelect: (
onSelect?: (
date: Date | null,
event?:
| React.MouseEvent<HTMLElement, MouseEvent>
Expand All @@ -207,7 +207,7 @@
| {
selectsRange?: never;
selectsMultiple?: never;
onChange: (
onChange?: (
date: Date | null,
event?:
| React.MouseEvent<HTMLElement>
Expand All @@ -217,7 +217,7 @@
| {
selectsRange: true;
selectsMultiple?: never;
onChange: (
onChange?: (
date: [Date | null, Date | null],
event?:
| React.MouseEvent<HTMLElement>
Expand All @@ -227,7 +227,7 @@
| {
selectsRange?: never;
selectsMultiple: true;
onChange: (
onChange?: (
date: Date[] | null,
event?:
| React.MouseEvent<HTMLElement>
Expand Down Expand Up @@ -752,27 +752,41 @@
const hasStartRange = startDate && !endDate;
const isRangeFilled = startDate && endDate;
if (noRanges) {
onChange([changedDate, null], event);
onChange
yuki0410-dev marked this conversation as resolved.
Show resolved Hide resolved
? onChange([changedDate, null], event)
: DatePicker.defaultProps.onChange;

Check warning on line 757 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L757

Added line #L757 was not covered by tests
} else if (hasStartRange) {
if (changedDate === null) {
onChange([null, null], event);
onChange
? onChange([null, null], event)
: DatePicker.defaultProps.onChange;

Check warning on line 762 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L762

Added line #L762 was not covered by tests
} else if (isDateBefore(changedDate, startDate)) {
if (swapRange) {
onChange([changedDate, startDate], event);
onChange
? onChange([changedDate, startDate], event)
: DatePicker.defaultProps.onChange;

Check warning on line 767 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L767

Added line #L767 was not covered by tests
} else {
onChange([changedDate, null], event);
onChange
? onChange([changedDate, null], event)
: DatePicker.defaultProps.onChange;

Check warning on line 771 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L771

Added line #L771 was not covered by tests
}
} else {
onChange([startDate, changedDate], event);
onChange
? onChange([startDate, changedDate], event)
: DatePicker.defaultProps.onChange;

Check warning on line 776 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L776

Added line #L776 was not covered by tests
}
}
if (isRangeFilled) {
onChange([changedDate, null], event);
onChange
? onChange([changedDate, null], event)
: DatePicker.defaultProps.onChange;

Check warning on line 782 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L782

Added line #L782 was not covered by tests
}
} else if (selectsMultiple) {
if (changedDate !== null) {
if (!selectedDates?.length) {
onChange([changedDate], event);
onChange
? onChange([changedDate], event)
: DatePicker.defaultProps.onChange;

Check warning on line 789 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L789

Added line #L789 was not covered by tests
} else {
const isChangedDateAlreadySelected = selectedDates.some(
(selectedDate) => isSameDay(selectedDate, changedDate),
Expand All @@ -783,19 +797,26 @@
(selectedDate) => !isSameDay(selectedDate, changedDate),
);

onChange(nextDates, event);
onChange
? onChange(nextDates, event)
: DatePicker.defaultProps.onChange;

Check warning on line 802 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L802

Added line #L802 was not covered by tests
} else {
onChange([...selectedDates, changedDate], event);
onChange
? onChange([...selectedDates, changedDate], event)
: DatePicker.defaultProps.onChange;

Check warning on line 806 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L806

Added line #L806 was not covered by tests
}
}
}
} else {
onChange(changedDate, event);
onChange
? onChange(changedDate, event)
: DatePicker.defaultProps.onChange;

Check warning on line 813 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L813

Added line #L813 was not covered by tests
}
}

if (!keepInput) {
this.props.onSelect(changedDate, event);
const onSelect = this.props.onSelect ?? DatePicker.defaultProps.onSelect;
onSelect(changedDate, event);
this.setState({ inputValue: null });
}
};
Expand Down Expand Up @@ -856,7 +877,8 @@
preSelection: changedDate,
});

this.props.onChange(changedDate);
const onChange = this.props.onChange ?? DatePicker.defaultProps.onChange;
onChange(changedDate);
if (this.props.shouldCloseOnSelect && !this.props.showTimeInput) {
this.sendFocusBackToInput();
this.setOpen(false);
Expand Down Expand Up @@ -1154,16 +1176,13 @@

const { selectsRange, onChange } = this.props;
if (selectsRange) {
onChange([null, null], event);
onChange
? onChange([null, null], event)
: DatePicker.defaultProps.onChange();

Check warning on line 1181 in src/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/index.tsx#L1181

Added line #L1181 was not covered by tests
} else {
onChange(null, event);
onChange ? onChange(null, event) : DatePicker.defaultProps.onChange();
}

if (this.props.selectsRange) {
this.props.onChange([null, null], event);
} else {
this.props.onChange(null, event);
}
this.setState({ inputValue: null });
};

Expand Down
Loading