Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sirineJ committed Dec 17, 2024
1 parent 729cc82 commit 854bb56
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions packages/circuit-ui/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {
const hasNativeDialog = hasNativeDialogSupport();

// set initial focus on the modal dialog content
// biome-ignore lint/correctness/useExhaustiveDependencies: we only want to run this effect once
useEffect(() => {
const dialogElement = dialogRef.current;
let timeoutId: NodeJS.Timeout;
Expand All @@ -135,12 +136,12 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {
};
}, [open]);

function setScrollProperty() {
const setScrollProperty = useCallback(() => {
document.documentElement.style.setProperty(
'--scroll-y',
`${window.scrollY}px`,
);
}
}, []);

useEffect(() => {
window.addEventListener('scroll', setScrollProperty);
Expand Down Expand Up @@ -183,21 +184,24 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {
dialogElement.close();
}
}, ANIMATION_DURATION);
}, []);
}, [hasNativeDialog]);

// intercept and prevent polyfill modal closing if preventClose is true
function onPolyfillDialogKeydown(event: KeyboardEvent) {
const onPolyfillDialogKeydown = useCallback((event: KeyboardEvent) => {
if (isEscape(event)) {
event.preventDefault();
event.stopPropagation();
}
}
}, []);

function onPolyfillBackdropClick(event: MouseEvent) {
if (preventClose) {
event.preventDefault();
}
}
const onPolyfillBackdropClick = useCallback(
(event: MouseEvent) => {
if (preventClose) {
event.preventDefault();
}
},
[preventClose],
);

useEffect(() => {
const dialogElement = dialogRef.current;
Expand Down Expand Up @@ -226,7 +230,13 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {
dialogElement.removeEventListener('keydown', onPolyfillDialogKeydown);
}
};
}, [onClose]);
}, [
onClose,
onPolyfillBackdropClick,
preventClose,
hasNativeDialog,
onPolyfillDialogKeydown,
]);

useEffect(() => {
const dialogElement = dialogRef.current;
Expand Down Expand Up @@ -273,7 +283,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>((props, ref) => {
dialogElement.close();
}
};
}, [open, handleDialogClose, hasNativeDialog]);
}, [open, handleDialogClose, hasNativeDialog, onPolyfillBackdropClick]);

const onDialogClick = (
event: ClickEvent<HTMLDialogElement> | ClickEvent<HTMLDivElement>,
Expand Down

0 comments on commit 854bb56

Please sign in to comment.