Presence
Shows and hides its child with CSS enter and exit motion: the child stays mounted while its exit motion runs, inert and marked data-presence="exiting", and unmounts when it ends (at once under reduced motion or without motion). Style the phases on the child: a transition with the duration-wave-* and ease-wave-* tokens, its start with the starting: variant gated on the entering phase (data-[presence=entering]:starting: classes), its exit with data-[presence=exiting]: classes, and a motion-reduce: counterpart (the usePresence JSDoc and the Presence stories show complete class lists). An ungated starting: class also animates a child that mounts entered (appear={false}, hydration): @starting-style applies to every first style of an element.
- The child is a single element (it must accept a ref, as DOM elements and ref-forwarding components do), which receives data-presence, inert while exiting and the presence ref, merged with its own ref and props; or a render function called with the presence result (isMounted, phase, ref, presenceProps) to spread yourself.
- appear runs the enter phase on mount (never on the server or when hydrating), unmountOnExit={false} keeps the exited child mounted, hidden and inert, and onEntered and onExited report the end of a phase (see usePresence).
- Renders nothing while the child is not mounted. Other children (text, several elements) are rendered as given, without the presence attributes, and a development warning is logged.
Examples
Fade And Slide
export const FadeAndSlide: Story = {
render: function FadeAndSlidePresence(args) {
return (
<TogglePresence
args={args}
label="details"
child={
<section
aria-label="Details"
className={`${cardClasses} transition-[opacity,translate] duration-wave-normal ease-wave-decelerate-mid data-[presence=entering]:starting:translate-y-1 data-[presence=entering]:starting:opacity-0 data-[presence=exiting]:translate-y-1 data-[presence=exiting]:opacity-0 data-[presence=exiting]:duration-wave-fast data-[presence=exiting]:ease-wave-accelerate-mid motion-reduce:transition-none`}
>
The report was saved to your documents.
</section>
}
/>
);
},
};Keep Mounted
export const KeepMounted: Story = {
args: { unmountOnExit: false },
render: function KeepMountedPresence(args) {
return (
<TogglePresence
args={args}
label="note"
child={
<section
aria-label="Note"
className={`${cardClasses} transition-opacity duration-wave-normal ease-wave-easy-ease data-[presence=entering]:starting:opacity-0 data-[presence=exiting]:opacity-0 motion-reduce:transition-none`}
>
<Input aria-label="Note text" placeholder="Type a note, then hide and show it" />
</section>
}
/>
);
},
};Provider Motion None
export const ProviderMotionNone: Story = {
render: function ProviderMotionNonePresence(args) {
return (
<WaveProvider motion="none" className="flex flex-col items-start gap-4">
<div className="flex flex-wrap gap-2">
<Dialog>
<Dialog.Trigger>
<Button>Open a dialog</Button>
</Dialog.Trigger>
<Dialog.Content title="No default motion">
<p>The dialog neither scales nor fades.</p>
</Dialog.Content>
</Dialog>
<Popover>
<Popover.Trigger>
<Button>Popover without motion</Button>
</Popover.Trigger>
<Popover.Content title="No default motion">It appears at once.</Popover.Content>
</Popover>
<Popover>
<Popover.Trigger>
<Button>Popover with its own motion</Button>
</Popover.Trigger>
<Popover.Content title="Its own motion" motion={ownFade}>
Its own motion still fades it.
</Popover.Content>
</Popover>
</div>
<Accordion className="w-80">
<Accordion.Item value="shipping">
<Accordion.Trigger>Shipping</Accordion.Trigger>
<Accordion.Panel>Orders ship within two working days.</Accordion.Panel>
</Accordion.Item>
</Accordion>
<TogglePresence
args={args}
label="card"
child={
<section
aria-label="Card"
className={`${cardClasses} transition-opacity duration-wave-normal ease-wave-easy-ease data-[presence=entering]:starting:opacity-0 data-[presence=exiting]:opacity-0 motion-reduce:transition-none`}
>
Your own classes on a Presence child still fade it.
</section>
}
/>
</WaveProvider>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
visible | boolean | Yes | Whether the content is shown; changes run the enter and exit phases. | |
children | React.ReactElement | ((presence: UsePresenceResult) => React.ReactNode) | Yes | A single element, which receives the presence attributes and ref (merged with its own ref and props: its own | |
appear | boolean | No | false | Run the enter phase when the element mounts already visible. Never on the server or while hydrating: the server HTML is the |
unmountOnExit | boolean | No | true | Unmount the element once it has exited. |
onEntered | () => void | No | Called when an enter phase ends (after its motion, or at once without one). | |
onExited | () => void | No | Called when an exit phase ends (after its motion, or at once without one), from the commit that unmounts the element (or, with |