Skip to content

Commit

Permalink
Fix #6746: Fix Calendar onDateSelect function (#6748)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rekl0w authored Jun 12, 2024
1 parent 747d484 commit 5eb9484
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,19 @@ export const Calendar = React.memo(

const onTodayButtonClick = (event) => {
const today = new Date();
const dateMeta = { day: today.getDate(), month: today.getMonth(), year: today.getFullYear(), today: true, selectable: true };
const timeMeta = { hours: today.getHours(), minutes: today.getMinutes(), seconds: today.getSeconds(), milliseconds: today.getMilliseconds() };
const dateMeta = {
day: today.getDate(),
month: today.getMonth(),
year: today.getFullYear(),
today: true,
selectable: true
};
const timeMeta = {
hours: today.getHours(),
minutes: today.getMinutes(),
seconds: today.getSeconds(),
milliseconds: today.getMilliseconds()
};

updateViewDate(event, today);
onDateSelect(event, dateMeta, timeMeta);
Expand Down Expand Up @@ -1598,6 +1609,10 @@ export const Calendar = React.memo(
};

const onDateSelect = (event, dateMeta, timeMeta) => {
if (!event) {
return;
}

if (props.disabled || !dateMeta.selectable) {
event.preventDefault();

Expand Down Expand Up @@ -1853,7 +1868,16 @@ export const Calendar = React.memo(
};

const onOverlayEnter = () => {
const styles = props.touchUI ? { position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' } : !props.inline ? { position: 'absolute', top: '0', left: '0' } : undefined;
const styles = props.touchUI
? {
position: 'fixed',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)'
}
: !props.inline
? { position: 'absolute', top: '0', left: '0' }
: undefined;

DomHandler.addStyles(overlayRef.current, styles);

Expand Down Expand Up @@ -3120,7 +3144,12 @@ export const Calendar = React.memo(
};

const createBackwardNavigator = (isVisible) => {
const navigatorProps = isVisible ? { onClick: onPrevButtonClick, onKeyDown: (e) => onContainerButtonKeydown(e, trapFocus) } : { style: { visibility: 'hidden' } };
const navigatorProps = isVisible
? {
onClick: onPrevButtonClick,
onKeyDown: (e) => onContainerButtonKeydown(e, trapFocus)
}
: { style: { visibility: 'hidden' } };
const previousIconProps = mergeProps(
{
className: cx('previousIcon')
Expand Down Expand Up @@ -3150,7 +3179,12 @@ export const Calendar = React.memo(
};

const createForwardNavigator = (isVisible) => {
const navigatorProps = isVisible ? { onClick: onNextButtonClick, onKeyDown: (e) => onContainerButtonKeydown(e) } : { style: { visibility: 'hidden' } };
const navigatorProps = isVisible
? {
onClick: onNextButtonClick,
onKeyDown: (e) => onContainerButtonKeydown(e)
}
: { style: { visibility: 'hidden' } };
const nextIconProps = mergeProps(
{
className: cx('nextIcon')
Expand Down Expand Up @@ -3190,7 +3224,15 @@ export const Calendar = React.memo(
const viewDate = getViewDate();
const viewMonth = viewDate.getMonth();
const displayedMonthOptions = monthNames
.map((month, index) => ((!isInMinYear(viewDate) || index >= props.minDate.getMonth()) && (!isInMaxYear(viewDate) || index <= props.maxDate.getMonth()) ? { label: month, value: index, index } : null))
.map((month, index) =>
(!isInMinYear(viewDate) || index >= props.minDate.getMonth()) && (!isInMaxYear(viewDate) || index <= props.maxDate.getMonth())
? {
label: month,
value: index,
index
}
: null
)
.filter((option) => !!option);
const displayedMonthNames = displayedMonthOptions.map((option) => option.label);
const selectProps = mergeProps(
Expand Down

0 comments on commit 5eb9484

Please sign in to comment.