CSS transitions
Use the following Base UI attributes for creating transitions when a component becomes visible or hidden:[data-starting-style]corresponds to the initial style to transition from.[data-ending-style]corresponds to the final style to transition to.
popover.css
CSS animations
Use the following Base UI attributes for creating CSS animations when a component becomes visible or hidden:[data-open]corresponds to the style applied when a component becomes visible.[data-closed]corresponds to the style applied before a component becomes hidden.
popover.css
JavaScript animations
JavaScript animation libraries such as Motion require control of the mounting and unmounting lifecycle of components in order for exit animations to play. Base UI relies onelement.getAnimations() to detect if animations have finished on an element. When using Motion, opacity animations are reflected in element.getAnimations(), so Base UI automatically waits for the animation finish before unmounting the component. If opacity isn’t part of your animation (such as in a translating drawer component), you should still animate it using a value close to 1 (such as opacity: 0.9999), so that Base UI can detect the animation.
Animating components unmounted from DOM when closed with Motion
Most popup components like Popover, Dialog, Tooltip, and Menu are unmounted from the DOM when they are closed by default. To animate them with Motion:- Make the component controlled with the
openprop so<AnimatePresence>can see the state as a child - Specify
keepMountedon the<Portal>part - Use the
renderprop to compose the<Popup>withmotion.div
animated-popover.tsx
Animating components kept in DOM when closed with Motion
Components that specifykeepMounted remain rendered in the DOM when they are closed. These elements need a different approach to be animated with Motion:
- Use the
renderprop to compose the<Popup>withmotion.div - Animate the properties based on the
openstate, avoiding<AnimatePresence>
animated-popover.tsx
Manual unmounting
For full control, you can manually unmount the component when it’s closed once animations have finished using anactionsRef passed to the <Root>:
manual-unmount.tsx