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);