Skip to content

Commit

Permalink
fix #7220: resolve global esc key listener conflict in Calendar compo…
Browse files Browse the repository at this point in the history
…nent (#7228)

* fix: resolve global esc key listener conflict in calendar component

* fix: remove target in isOutsideClicked

* feat: add visible condition
  • Loading branch information
ozantekin authored Sep 23, 2024
1 parent df4892e commit 7265aeb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import PrimeReact, { PrimeReactContext, localeOption, localeOptions } from '../api/Api';
import { Button } from '../button/Button';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMergeProps, useMountEffect, useOverlayListener, usePrevious, useUnmountEffect, useUpdateEffect, useGlobalOnEscapeKey, ESC_KEY_HANDLING_PRIORITIES } from '../hooks/Hooks';
import { useMergeProps, useMountEffect, useOverlayListener, usePrevious, useUnmountEffect, useUpdateEffect, useGlobalOnEscapeKey, ESC_KEY_HANDLING_PRIORITIES, useDisplayOrder } from '../hooks/Hooks';
import { CalendarIcon } from '../icons/calendar';
import { ChevronDownIcon } from '../icons/chevrondown';
import { ChevronLeftIcon } from '../icons/chevronleft';
Expand All @@ -24,6 +24,8 @@ export const Calendar = React.memo(
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const [viewDateState, setViewDateState] = React.useState(null);
const [idState, setIdState] = React.useState(props.id);
const isCloseOnEscape = overlayVisibleState && props.closeOnEscape;
const overlayDisplayOrder = useDisplayOrder('overlay-panel', isCloseOnEscape);

const metaData = {
props,
Expand All @@ -39,8 +41,8 @@ export const Calendar = React.memo(
callback: () => {
hide();
},
when: overlayVisibleState,
priority: [ESC_KEY_HANDLING_PRIORITIES.OVERLAY_PANEL, 0]
when: overlayVisibleState && overlayDisplayOrder,
priority: [ESC_KEY_HANDLING_PRIORITIES.OVERLAY_PANEL, overlayDisplayOrder]
});

useHandleStyle(CalendarBase.css.styles, isUnstyled, { name: 'calendar' });
Expand Down Expand Up @@ -1852,7 +1854,7 @@ export const Calendar = React.memo(
setOverlayVisibleState(true);

overlayEventListener.current = (e) => {
if (!isOutsideClicked(e)) {
if (!isOutsideClicked(e) && visible) {
isOverlayClicked.current = true;
}
};
Expand Down

0 comments on commit 7265aeb

Please sign in to comment.