Skip to content

Commit

Permalink
fix: revert onExit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukTheCoder committed Sep 22, 2024
1 parent 13c3a7f commit 0eb65bc
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions widget/ui/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ModalPropTypes } from './Modal.types.js';
import type { PropsWithChildren } from 'react';

import * as Dialog from '@radix-ui/react-dialog';
import React from 'react';
import React, { useEffect, useRef } from 'react';

import { CloseIcon } from '../../icons/index.js';
import { BottomLogo } from '../BottomLogo/index.js';
Expand All @@ -24,6 +24,7 @@ export function Modal(props: PropsWithChildren<ModalPropTypes>) {
title,
open,
onClose,
onExit,
styles,
anchor = 'bottom',
container = document.body,
Expand All @@ -36,18 +37,45 @@ export function Modal(props: PropsWithChildren<ModalPropTypes>) {
hasWatermark = true,
hasCloseIcon = true,
} = props;
const exitCallbackRef = useRef<ModalPropTypes['onExit']>();
const modalContainerRef = useRef<HTMLDivElement | null>(null);

const handleBackDropClick = (open: boolean) => {
if (dismissible && !open) {
onClose();
}
};

useEffect(() => {
exitCallbackRef.current = onExit;
}, [onExit]);

useEffect(() => {
if (exitCallbackRef.current) {
modalContainerRef.current?.addEventListener(
'transitionend',
exitCallbackRef.current
);
}

return () => {
if (exitCallbackRef.current) {
modalContainerRef.current?.removeEventListener(
'transitionend',
exitCallbackRef.current
);
}
};
}, [open]);

return (
<Dialog.Root open={open} onOpenChange={handleBackDropClick}>
<Dialog.Portal container={container}>
<DialogOverlay>
<DialogContent css={styles?.container} anchor={anchor}>
<DialogContent
ref={modalContainerRef}
css={styles?.container}
anchor={anchor}>
{header ?? (
<ModalHeader noTitle={!title && dismissible && !prefix}>
{prefix}
Expand Down

0 comments on commit 0eb65bc

Please sign in to comment.