r/reactjs • • Oct 08 '26

Needs Help Dialog Animation on Unmount ?

{open && (

<AddEditAnnouncementDialog

open={open}

onOpenChange={(open) => {

if (!open) {

setOpen(false)

}

}}

initialData={initialData} />

)}

so i have this reusable dialog it is a very heavy component with 2 tiptap editors and also tiptap menu bars for rich text which is my i only mount this on opening but when closing it, it closes abruptly without animation as it unmounts.

is there any way to fix this ?

ths is shadcn baseui dialog

1 Upvotes

11 comments sorted by

4

u/denexapp Oct 08 '26

If you can customize the component, you can use react view transition enter and exit animations. https://react.dev/reference/react/ViewTransition#animating-an-element-on-enter

1

u/jdnsu Oct 08 '26

dont use state based mounting . it better to use it with classname to modify it throught classes

1

u/hasraltech Oct 09 '26

The {open && ...} is what kills the animation. When open flips to false, React unmounts the whole dialog immediately, so there's nothing left to animate out.

You probably don't need it. Base UI's Dialog only mounts the popup while it's open and keeps it mounted until the exit animation finishes (unless you set keepMounted on the portal). So your Tiptap editors still won't render while the dialog is closed:

<AddEditAnnouncementDialog
  open={open}
  onOpenChange={setOpen}
  initialData={initialData}
/>

If you need the component to fully unmount after closing (for example, to reset the editor state), keep a separate flag and clear it once the animation is done with onOpenChangeComplete on Dialog.Root:

const [mounted, setMounted] = useState(false)

// when opening: setMounted(true); setOpen(true)

{mounted && (
  <AddEditAnnouncementDialog
    open={open}
    onOpenChange={setOpen}
    onOpenChangeComplete={(isOpen) => {
      if (!isOpen) setMounted(false)
    }}
    initialData={initialData}
  />
)}

Your shadcn wrapper needs to pass onOpenChangeComplete through to Dialog.Root for this to work.

1

u/EvilPete Oct 08 '26

Most UI libraries provide hooks for mount/unmount animations. You'll have to dig around in the docs of the one you use.

But you could also try out the new React ViewTransition feature!

https://react.dev/blog/2026/09/09/react-19-3#view-transition

8

u/[deleted] Oct 08 '26

[removed] — view removed comment

0

u/Good_Language1763 Oct 08 '26

normally i do that but this is a very heavy form inside the dialog it has multiple tiptap editors and menu bars and also rhf and i feel like it is causing jank in the page

4

u/Cahnis Oct 08 '26

Lazyload the modal contents