Skip to content

Commit

Permalink
fix(Modal): expose event in onClose (#2738)
Browse files Browse the repository at this point in the history
Expose native `event` in Modal `onClose` handler
  • Loading branch information
eirikbacker authored Nov 6, 2024
1 parent 16d82d7 commit a0c6744
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-sheep-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-react": patch
---

Modal: Expose native close event object to onClose callback
4 changes: 2 additions & 2 deletions packages/react/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDialogElement>;

Expand Down Expand Up @@ -76,7 +76,7 @@ export const Modal = forwardRef<HTMLDialogElement, ModalProps>(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);
Expand Down

0 comments on commit a0c6744

Please sign in to comment.