From a0c6744812a2ff7a39737fa1507dc7d56802503f Mon Sep 17 00:00:00 2001 From: Eirik Backer Date: Wed, 6 Nov 2024 07:34:41 +0100 Subject: [PATCH] fix(Modal): expose event in onClose (#2738) Expose native `event` in Modal `onClose` handler --- .changeset/old-sheep-dress.md | 5 +++++ packages/react/src/components/Modal/Modal.tsx | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/old-sheep-dress.md diff --git a/.changeset/old-sheep-dress.md b/.changeset/old-sheep-dress.md new file mode 100644 index 0000000000..f7b1100b09 --- /dev/null +++ b/.changeset/old-sheep-dress.md @@ -0,0 +1,5 @@ +--- +"@digdir/designsystemet-react": patch +--- + +Modal: Expose native close event object to onClose callback diff --git a/packages/react/src/components/Modal/Modal.tsx b/packages/react/src/components/Modal/Modal.tsx index dc758ad9b6..bf58a7d6eb 100644 --- a/packages/react/src/components/Modal/Modal.tsx +++ b/packages/react/src/components/Modal/Modal.tsx @@ -21,7 +21,7 @@ export type ModalProps = { /** * Callback that is called when the modal is closed. */ - onClose?: () => void; + onClose?: (event: Event) => void; asChild?: boolean; } & DialogHTMLAttributes; @@ -76,7 +76,7 @@ export const Modal = forwardRef(function Modal( /* handle closing */ useEffect(() => { - const handleClose = () => onClose?.(); + const handleClose = (event: Event) => onClose?.(event); modalRef.current?.addEventListener('close', handleClose); return () => modalRef.current?.removeEventListener('close', handleClose);