Popover
Open a floating panel beside a button or another control.
Demos
Size
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy Popover.vue and index.ts into app/components/ui/popover/.
app/components/ui/popover/Popover.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | md |
Width fits the content by default, capped at 20rem and the viewport. Panel padding stays at 12px across sizes. size controls text size, line height, and corner radius. The default trigger gap is 4px. Use class or ui.content to set an explicit width when needed. Child components retain their own size props.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
side | "top" | "bottom" | "left" | "right" | "bottom" | Preferred side to position the popover. |
align | "start" | "center" | "end" | "start" | Alignment relative to the trigger. |
sideOffset | number | 4 | Gap in px between trigger and panel. |
teleport | string | false | false | Teleport target. |
transition | string | false | "akaza-popover" | Named Vue transition. |
ui | PopoverUi | — | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
trigger | { isOpen, open, close, toggle, triggerProps } | Element that opens the popover. |
content | { close } | The floating panel content. |
Events
| Event | Payload | Description |
|---|---|---|
open-change | [open: boolean, details] | Fired when the open state changes. |
Exposed methods
| Method | Signature | Description |
|---|---|---|
open | (reason?, event?) => void | Opens the popover. |
close | (reason?, event?) => void | Closes the popover. |
toggle | (reason?, event?) => void | Toggles the popover. |
Keyboard
| Key | Behavior |
|---|---|
Enter / Space | Opens when trigger is a native button wired to toggle. |
Escape | Closes topmost popover and restores trigger focus. |
Tab / Shift + Tab | Uses normal document order; Popover is non-modal and does not trap focus. |
Apply triggerProps to trigger element so expanded state and popup relationship are announced.