Skip to content

Commit

Permalink
fix: prevent onselect event when prev, next calendar button (#7155)
Browse files Browse the repository at this point in the history
  • Loading branch information
KumJungMin authored Sep 12, 2024
1 parent 1425a6c commit 267e07b
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ export const Calendar = React.memo(

if (isValidSelection(value)) {
updateModel(event, value);
updateViewDate(event, value.length ? value[0] : value);

const date = value.length ? value[0] : value;

updateViewDate(event, date);
onViewDateSelect({ event, date });
}
} catch (err) {
//invalid date
Expand All @@ -170,6 +174,16 @@ export const Calendar = React.memo(
}
};

const onViewDateSelect = ({ event, date }) => {
if (date && props.onSelect) {
const day = date.getDate();
const month = date.getMonth();
const year = date.getFullYear();

onDateSelect(event, { day, month, year, selectable: isSelectable(day, month, year) }, null, true);
}
};

const reFocusInputField = () => {
if (!props.inline && inputRef.current) {
ignoreFocusFunctionality.current = true;
Expand Down Expand Up @@ -1083,17 +1097,7 @@ export const Calendar = React.memo(
setViewDateState(value);
}

if (!value) {
onClearButtonClick(event);
}

if (value && props.onSelect) {
const day = value.getDate();
const month = value.getMonth();
const year = value.getFullYear();

onDateSelect(event, { day, month, year, selectable: isSelectable(day, month, year) }, null, true);
}
if (!value) onClearButtonClick(event);
};

const setNavigationState = (newViewDate) => {
Expand Down Expand Up @@ -1800,6 +1804,7 @@ export const Calendar = React.memo(
props.onMonthChange && props.onMonthChange({ month: month + 1, year: currentYear });

updateViewDate(event, currentDate);
onViewDateSelect({ event, date: currentDate });
}
};

Expand Down Expand Up @@ -3068,7 +3073,10 @@ export const Calendar = React.memo(
}

if (props.viewDate) {
updateViewDate(null, getViewDate(props.viewDate));
const date = getViewDate(props.viewDate);

updateViewDate(null, date);
onViewDateSelect({ event: null, date });
}
}, [props.onViewDateChange, props.value, props.viewDate]);

Expand Down

0 comments on commit 267e07b

Please sign in to comment.