Popover
A neo-brutalist popover component for displaying floating content anchored to a trigger element. Built on reka-ui's PopoverRoot, supporting modal/non-modal modes and custom anchor positioning.
Demo
基础用法
对齐方式 (align)
偏移距离 (sideOffset=20)
Installation
pnpm dlx brutx-vue@latest add popoverUsage
<script setup>
import { PopoverRoot as Popover, PopoverTrigger, PopoverAnchor } from 'reka-ui'
import { PopoverContent, Button } from 'brutx-ui-vue'
</script>
<template>
<Popover>
<PopoverTrigger as-child>
<Button variant="outline">Open Popover</Button>
</PopoverTrigger>
<PopoverContent>
<div class="grid gap-4">
<div class="space-y-2">
<h4 class="font-black leading-none">Dimensions</h4>
<p class="text-sm text-brutal-muted-foreground">
Set the dimensions for the layer.
</p>
</div>
</div>
</PopoverContent>
</Popover>
</template>Scoped Themes
PopoverContent is portalled to body and inherits the trigger scope's theme preset, dark mode, and --brutal-* tokens. Changes to ancestor theme classes or inline tokens also update open content. If Teleport moves the same trigger node to another scope, the open popover follows its new ancestors. Nested Popovers and Popover-based ColorPickers follow the same rule.
The content panel's own class and inline tokens can override inherited values. See theme tokens.
Sub-components
| Component | Description |
|---|---|
Popover | Root component (re-exported from reka-ui's PopoverRoot) |
PopoverTrigger | Button that opens the popover |
PopoverContent | Popover content panel |
PopoverAnchor | Anchor element for positioning |
Trigger identity
Set id on PopoverTrigger to identify the trigger. The popover content uses the same ID for its accessible naming reference. An ID is generated when omitted.
API Reference
Popover
| Name | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | undefined | — | The initial open state in uncontrolled mode; when omitted, the Reka UI primitive starts closed. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/Popover.vue | |||
open | boolean | undefined | — | The controlled open state. Listen for update:open and update this prop to keep it in sync. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/Popover.vue | |||
modal | boolean | undefined | — | Enables modal behavior, disabling interaction with outside elements and limiting screen-reader focus to the popover content. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/Popover.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@update:open | [value: boolean] | Emits the new boolean open state for controlled usage. |
DetailsDeclared type[value: boolean] Literal values
Sourcepackages/ui/src/components/popover/Popover.vue | ||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | The trigger, content panel, and other Reka UI primitives inside the popover. |
DetailsDeclared type{}Sourcepackages/ui/src/components/popover/Popover.vue | ||
PopoverContent
| Name | Type | Default | Description |
|---|---|---|---|
as | AsTag | Component | undefined | "div" | The HTML tag or Vue component rendered for the panel. Defaults to div. |
DetailsDeclared typeAsTag | Component | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/PopoverContent.vue | |||
asChild | boolean | undefined | — | Applies the panel attributes, accessible name, and interactions to its single child element. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/PopoverContent.vue | |||
align | "center" | "start" | "end" | undefined | "center" | The content panel alignment relative to its trigger. |
DetailsDeclared type"center" | "start" | "end" | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/PopoverContent.vue | |||
sideOffset | number | undefined | 8 | The pixel gap between the content panel and its trigger. |
DetailsDeclared typenumber | undefined Default value details
Sourcepackages/ui/src/components/popover/PopoverContent.vue | |||
collisionPadding | number | Partial<Record<"right" | "bottom" | "left" | "top", number>> | undefined | 8 | The inset used for floating-content collision handling; accepts one number or per-side top/right/bottom/left values. |
DetailsDeclared typenumber | Partial<Record<"right" | "bottom" | "left" | "top", number>> | undefined Default value details
Sourcepackages/ui/src/components/popover/PopoverContent.vue | |||
class | string | undefined | undefined | CSS classes added to the Reka UI floating content element. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/popover/PopoverContent.vue | |||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | The content rendered inside the popover panel. |
DetailsDeclared type{}Sourcepackages/ui/src/components/popover/PopoverContent.vue | ||
PopoverTrigger
| Name | Type | Default | Description |
|---|---|---|---|
id | string | undefined | — | The trigger ID, also used to label the popover content. An ID is generated when omitted. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/popover/PopoverTrigger.vue | |||
asChild | boolean | undefined | — | Merges the trigger props and interaction behavior into its single child element. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/PopoverTrigger.vue | |||
as | AsTag | Component | undefined | — | Selects the HTML tag or component rendered as the trigger; the child determines the target when asChild is enabled. |
DetailsDeclared typeAsTag | Component | undefined Literal values
Default value details
Sourcepackages/ui/src/components/popover/PopoverTrigger.vue | |||
| Name | Signature or type | Description |
|---|---|---|
#default | {} | The trigger content, usually a button or link. |
DetailsDeclared type{}Sourcepackages/ui/src/components/popover/PopoverTrigger.vue | ||
Reka UI Primitive Features
Popover wraps Reka UI’s PopoverRoot, while PopoverTrigger and PopoverContent wrap their corresponding primitives. Import PopoverAnchor from reka-ui. The API above lists members declared by the local components. PopoverContent forwards undeclared Vue attributes and event listeners to the Reka UI primitive, including openAutoFocus, closeAutoFocus, pointerDownOutside, interactOutside, escapeKeyDown, and focusOutside.
Accessibility
- Keyboard: Press
Escapeto close the popover - ARIA Attributes: The popover uses
role="dialog"semantics and automatically linksaria-labelledbyto the trigger - Focus Management: The popover auto-focuses when opened
- Interaction Behavior: Clicking outside closes the popover; in modal mode, interaction with external elements is disabled
Relationship with Popconfirm
Popconfirm is essentially a Popover + confirm/cancel button combination. It internally uses Popover/PopoverTrigger/PopoverContent directly, adding a TriangleAlert warning icon and confirm/cancel button logic.
When to use Popconfirm
- Simple "confirm/cancel" binary operations
- Out-of-the-box usage without assembling buttons and events manually
- Consistent dangerous action confirmation experience
When to use Popover manually
- Custom button text, styling, or layout
- Complex content like forms or lists inside the popover
- Fine-grained control over open/close timing
<script setup lang="ts">
import { ref } from 'vue'
import { Button, Popconfirm } from 'brutx-ui-vue'
import { Popover, PopoverTrigger, PopoverContent } from 'brutx-ui-vue/popover'
const open = ref(false)
function handleDelete() {
open.value = false
alert('Deletion confirmed!')
}
</script>
<template>
<Popconfirm
title="Are you sure to delete?"
confirm-button-text="Confirm"
cancel-button-text="Cancel"
@confirm="handleDelete"
>
<Button variant="danger">Delete</Button>
</Popconfirm>
<Popover v-model:open="open">
<PopoverTrigger as-child>
<Button variant="outline">Custom confirmation</Button>
</PopoverTrigger>
<PopoverContent>
<p>Delete this item?</p>
<form @submit.prevent="handleDelete" @reset.prevent="open = false">
<Button type="reset" variant="outline">Cancel</Button>
<Button type="submit" variant="danger">Confirm deletion</Button>
</form>
</PopoverContent>
</Popover>
</template>