Skip to content

[Collapsible] Exit animation doesn't run when using motion and Tailwind v4 #1608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mj12albert opened this issue Mar 27, 2025 · 1 comment
Labels
component: collapsible This is the name of the generic UI component, not the React module! has workaround

Comments

@mj12albert
Copy link
Member

mj12albert commented Mar 27, 2025

https://codesandbox.io/p/devbox/suspicious-kate-j22y8v

Tailwind v4's reset sets display: none !important on the [hidden] selector, and the way motion sets styles cannot override !important

The workaround is to set hidden={undefined} on the panel, it will be unmounted as soon as hidden becomes true anyway:

<Collapsible.Root open={open} onOpenChange={setOpen}>
  <Collapsible.Trigger />
  <AnimatePresence>
    {open && (
      <Collapsible.Panel
        keepMounted
        key="MyPanel"
        // workaround tailwind `display: none !important` on [hidden]
        hidden={undefined}
        render={
          <motion.div
            initial={{ height: 0 }}
            animate={{
              height: "auto",
              transition: { duration: 1 },
            }}
            exit={{
              height: 0,
              // ensure the panel is visible during the exit animation
              display: "block",
              transition: { duration: 1 },
            }}
          />
        }
      >
        {/* panel content */}
      </Collapsible.Panel>
    )}
  </AnimatePresence>
</Collapsible.Root>

Base UI version

1.0.0-alpha.7

@mj12albert mj12albert added component: collapsible This is the name of the generic UI component, not the React module! has workaround labels Mar 27, 2025
@mj12albert
Copy link
Member Author

In #1601 I tried to delay setting hidden until detected animations have finished using the opacity: 0.9999 trick documented here but it didn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: collapsible This is the name of the generic UI component, not the React module! has workaround
Projects
None yet
Development

No branches or pull requests

1 participant