Presence component provides enhanced control over element mounting/unmounting. It ensures animations and transitions complete before removing elements from the DOM, making it perfect for animated UI components.
| Prop | Default | Type |
|---|---|---|
present* | booleanConditional to mount or unmount the child element. Similar to | |
forceMount | booleanForce the element to render all the time.\n\nUseful for programmatically render grandchild component with the exposed |
| Event | Type |
|---|---|
enter | CustomEventEvent handler called when the enter animation has started |
after-enter | CustomEventEvent handler called when the enter animation has finished |
leave | CustomEventEvent handler called when the leave animation has started |
after-leave | CustomEventEvent handler called when the leave animation has finished |
<template>
<APresence :present="isVisible">
<div
:data-state="isVisible ? 'open' : 'closed'"
class="data-[state=open]:animate-fadeIn data-[state=closed]:animate-fadeOut"
>
<slot />
</div>
</APresence>
</template>
When you need to ensure content is always rendered regardless of the present state:
<template>
<APresence
v-slot="{ present }"
:present="isVisible"
:force-mount="true"
>
<div>
This content will always be rendered
<div v-if="present">
This content is hidden
</div>
</div>
</APresence>
</template>