Popover
Displays a popover card with some content over the main content.
Preview
Installation
npx sigma-ui@latest add popoverUsage
<script setup lang="ts">
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
</script>
<template>
<Popover>
<PopoverTrigger>
Open popover
</PopoverTrigger>
<PopoverContent>
Some popover content
</PopoverContent>
</Popover>
</template>- Use
v-model:openonPopoverto control the open state. side,align, andsideOffsetonPopoverContentposition the popover relative to the trigger.
Examples
Custom Trigger
Use as-child on PopoverTrigger to render your own button.
<script setup lang="ts">
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
import { Button } from '@/components/ui/button';
</script>
<template>
<Popover>
<PopoverTrigger as-child>
<Button variant="outline">
Open popover
</Button>
</PopoverTrigger>
<PopoverContent
side="top"
class="w-80"
>
Some popover content
</PopoverContent>
</Popover>
</template>API Reference
Popover
Props
| Prop | Type | Default |
|---|---|---|
defaultOpenThe open state of the popover when it is initially rendered. Use when you do not need to control its open state. | boolean | - |
openThe controlled open state of the popover. | boolean | - |
modalThe modality of the popover. When set to true, interaction with outside elements will be disabled and only popover content will be visible to screen readers. | boolean | false |
Events
| Event | Payload |
|---|---|
update:openEvent handler called when the open state of the popover changes. | [value: boolean] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
PopoverTrigger
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
PopoverContent
Props
| Prop | Type | Default |
|---|---|---|
forceMountUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | boolean | - |
memoDependenciesReactive dependencies that should invalidate the memoized content subtree. | unknown[] | - |
sideThe preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. | "top" | "right" | "bottom" | "left" | "bottom" |
sideOffsetThe distance in pixels from the trigger. | number | 4 |
sideFlipFlip to the opposite side when colliding with boundary. | boolean | true |
alignThe preferred alignment against the trigger. May change when collisions occur. | "center" | "start" | "end" | "center" |
alignOffsetAn offset in pixels from the | number | 0 |
alignFlipFlip alignment when colliding with boundary.
May only occur when | boolean | true |
avoidCollisionsWhen | boolean | true |
collisionBoundaryThe element used as the collision boundary. By default this is the viewport, though you can provide additional element(s) to be included in this check. | Element | (Element | null)[] | null | [] |
collisionPaddingThe distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }. | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 0 |
arrowPaddingThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. | number | 0 |
hideShiftedArrowWhen | boolean | true |
stickyThe sticky behavior on the align axis. | "partial" | "always" | "partial" |
hideWhenDetachedWhether to hide the content when the trigger becomes fully occluded. | boolean | false |
positionStrategyThe type of CSS position property to use. | "absolute" | "fixed" | - |
updatePositionStrategyStrategy to update the position of the floating element on every animation frame. | "always" | "optimized" | 'optimized' |
disableUpdateOnLayoutShiftWhether to disable the update position for the content when the layout shifted. | boolean | false |
prioritizePositionForce content to be position within the viewport. Might overlap the reference element, which may not be desired. | boolean | false |
referenceThe custom element or virtual element that will be set as the reference to position the floating element. If provided, it will replace the default anchor element. | ReferenceElement | - |
dirThe reading direction of the popper content when applicable. <br> If omitted, inherits globally from | Direction | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
disableOutsidePointerEventsWhen | boolean | - |
Events
| Event | Payload |
|---|---|
escapeKeyDownEvent handler called when the escape key is down. Can be prevented. | [event: KeyboardEvent] |
pointerDownOutsideEvent handler called when a | [event: PointerDownOutsideEvent] |
focusOutsideEvent handler called when the focus moves outside of the | [event: FocusOutsideEvent] |
interactOutsideEvent handler called when an interaction happens outside the | [event: PointerDownOutsideEvent | FocusOutsideEvent] |
openAutoFocusEvent handler called when auto-focusing on open. Can be prevented. | [event: Event] |
closeAutoFocusEvent handler called when auto-focusing on close. Can be prevented. | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Adheres to the Dialog WAI-ARIA design pattern. Reka UI manages focus and the ARIA attributes of the trigger and the content.
| Key | Description |
|---|---|
| Space | Opens or closes the popover. |
| Enter | Opens or closes the popover. |
| Tab | Moves focus to the next focusable element. |
| Shift + Tab | Moves focus to the previous focusable element. |
| Esc | Closes the popover and moves focus to the trigger. |