Skip to content

Commit

Permalink
feat(modal): add onCloseComplete prop to Modal (#5402)
Browse files Browse the repository at this point in the history
* feat(modal): add onCloseComplete prop to Modal

* chore: add changeset

* chore: update changeset

Co-authored-by: Tim Kolberger <tim@kolberger.eu>
  • Loading branch information
ShumRain and TimKolberger authored Mar 15, 2022
1 parent 73a06ae commit 2328530
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/twenty-plants-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/modal": minor
---

Add `onCloseComplete` prop to Modal which is called when all DOM nodes of the `Modal` are removed.
7 changes: 6 additions & 1 deletion packages/modal/src/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export interface ModalProps
* The transition that should be used for the modal
*/
motionPreset?: MotionPreset
/**
* Fires when all exiting nodes have completed animating out
*/
onCloseComplete?: () => void
}

interface ModalContext extends ModalOptions, UseModalReturn {
Expand Down Expand Up @@ -153,6 +157,7 @@ export const Modal: React.FC<ModalProps> = (props) => {
preserveScrollBarGap,
motionPreset,
lockFocusAcrossFrames,
onCloseComplete,
} = props

const styles = useMultiStyleConfig("Modal", props)
Expand All @@ -175,7 +180,7 @@ export const Modal: React.FC<ModalProps> = (props) => {
return (
<ModalContextProvider value={context}>
<StylesProvider value={styles}>
<AnimatePresence>
<AnimatePresence onExitComplete={onCloseComplete}>
{context.isOpen && <Portal {...portalProps}>{children}</Portal>}
</AnimatePresence>
</StylesProvider>
Expand Down

1 comment on commit 2328530

@vercel
Copy link

@vercel vercel bot commented on 2328530 Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.