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(RangeCalendar): select dates only on a minimum mode #18

Merged
merged 1 commit into from
Nov 14, 2023
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
18 changes: 13 additions & 5 deletions src/components/Calendar/hooks/useRangeCalendarState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@
? makeRange(anchorDate, calendar.focusedDate, calendar.mode)
: (value && makeRange(value.start, value.end, calendar.mode)) ?? undefined;

const selectDate = (date: DateTime) => {
if (props.disabled || props.readOnly) {
const minMode = calendar.availableModes[0];

const selectDate = (date: DateTime, force = false) => {
if (props.disabled) {
return;
}

if (!force && calendar.mode !== minMode) {
calendar.zoomIn();
return;
}

if (props.readOnly) {
return;
}

date = constrainValue(date, props.minValue, props.maxValue);

Check warning on line 45 in src/components/Calendar/hooks/useRangeCalendarState.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to function parameter 'date'
if (calendar.isCellUnavailable(date)) {
return;
}
Expand All @@ -53,9 +64,6 @@
anchorDate,
setAnchorDate: setAnchorDateState,
highlightedRange,
selectFocusedDate() {
selectDate(calendar.focusedDate);
},
isSelected(date) {
if (!highlightedRange) {
return false;
Expand Down
Loading