Menampilkan konten kaya di dalam portal, dipicu lewat sebuah tombol.
Installation
pnpm dlx kliping@latest add popoverPasang dependensi berikut:
pnpm add reka-uiSalin dan tempel kode sumber di GitHub ke project Anda.
Sesuaikan path import dengan struktur project Anda.
Usage
<script setup lang="ts">
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover'
</script>
<template>
<Popover>
<PopoverTrigger>Open</PopoverTrigger>
<PopoverContent>Place content for the popover here.</PopoverContent>
</Popover>
</template>2
3
4
5
6
7
8
9
10
11
12
13
14
Requirements
Semua dipasang otomatis oleh kliping add; tabel ini untuk Anda yang memasang manual atau memeriksa project.
| Requirement | Value |
|---|---|
| Project | Vue 3.5+, Tailwind CSS v4, alias @ — disiapkan kliping init |
| npm packages | @vueuse/core@^14.4.0, reka-ui@^2.10.3 |
| Files | components/ui/popover/popover.vuecomponents/ui/popover/popover-anchor.vuecomponents/ui/popover/popover-content.vuecomponents/ui/popover/popover-trigger.vuecomponents/ui/popover/index.ts |
Anatomy
Susunan bagiannya seperti dipakai di contoh-contoh di atas. Impor semua bagian dari satu tempat, lalu susun begini:
<Popover>
<PopoverTrigger />
<PopoverContent />
<PopoverAnchor>
<PopoverTrigger />
</PopoverAnchor>
</Popover>API Reference
Popover
| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen? | boolean | — | The open state of the popover when it is initially rendered. Use when you do not need to control its open state. |
open? | boolean | — | The controlled open state of the popover. |
modal? | boolean | — | The 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. |
| Event | Payload | Description |
|---|---|---|
@update:open | [value: boolean] | Emitted when the open state changes. |
| Slot | Props |
|---|---|
#default | { open: boolean; close: () => void; } |
| Data attribute | Value |
|---|---|
[data-slot] | "popover" |
PopoverAnchor
| Prop | Type | Default | Description |
|---|---|---|---|
reference? | ReferenceElement | — | The reference (or anchor) element that is being referred to for positioning. If not provided will use the current component as anchor. |
asChild? | boolean | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
as? | AsTag | Component | — | The element or component this component should render as. Can be overwritten by asChild. |
| Slot | Props |
|---|---|
#default | — |
| Data attribute | Value |
|---|---|
[data-slot] | "popover-anchor" |
PopoverContent
| Prop | Type | Default | Description |
|---|---|---|---|
forceMount? | boolean | — | Used to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. |
memoDependencies? | unknown[] | — | Reactive dependencies that should invalidate the memoized content subtree. |
side? | "bottom" | "top" | "right" | "left" | — | The preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. |
sideOffset? | number | 4 | The distance in pixels from the trigger. |
sideFlip? | boolean | — | Flip to the opposite side when colliding with boundary. |
align? | "start" | "end" | "center" | "center" | The preferred alignment against the trigger. May change when collisions occur. |
alignOffset? | number | — | An offset in pixels from the start or end alignment options. |
alignFlip? | boolean | — | Flip alignment when colliding with boundary. May only occur when prioritizePosition is true. |
avoidCollisions? | boolean | — | When true, overrides the side and align preferences to prevent collisions with boundary edges. |
collisionBoundary? | Element | (Element | null)[] | — | The 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. |
collisionPadding? | number | Partial<Record<"bottom" | "top" | "right" | "left", number>> | — | The 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 }. |
arrowPadding? | number | — | The padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. |
hideShiftedArrow? | boolean | — | When true, hides the arrow when it cannot be centered to the reference element. |
sticky? | "partial" | "always" | — | The sticky behavior on the align axis. partial will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst "always" will keep the content in the boundary regardless. |
hideWhenDetached? | boolean | — | Whether to hide the content when the trigger becomes fully occluded. |
positionStrategy? | "fixed" | "absolute" | — | The type of CSS position property to use. |
updatePositionStrategy? | "always" | "optimized" | — | Strategy to update the position of the floating element on every animation frame. |
disableUpdateOnLayoutShift? | boolean | — | Whether to disable the update position for the content when the layout shifted. |
prioritizePosition? | boolean | — | Force content to be position within the viewport. Might overlap the reference element, which may not be desired. |
reference? | ReferenceElement | — | The 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. |
dir? | Direction | — | The reading direction of the popper content when applicable. If omitted, inherits globally from ConfigProvider or assumes LTR (left-to-right) reading mode. |
asChild? | boolean | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
as? | AsTag | Component | — | The element or component this component should render as. Can be overwritten by asChild. |
disableOutsidePointerEvents? | boolean | — | When true, hover/focus/click interactions will be disabled on elements outside the DismissableLayer. Users will need to click twice on outside elements to interact with them: once to close the DismissableLayer, and again to trigger the element. |
| Event | Payload | Description |
|---|---|---|
@escapeKeyDown | [event: KeyboardEvent] | Emitted when Escape is pressed; call event.preventDefault() to keep it open. |
@pointerDownOutside | [event: PointerDownOutsideEvent] | Emitted on a pointer down outside; call event.preventDefault() to keep it open. |
@focusOutside | [event: FocusOutsideEvent] | Emitted when focus moves outside; call event.preventDefault() to keep it open. |
@interactOutside | [event: PointerDownOutsideEvent | FocusOutsideEvent] | Emitted on any pointer down or focus outside; call event.preventDefault() to keep it open. |
@openAutoFocus | [event: Event] | Emitted when focus moves in on open; call event.preventDefault() to stop it. |
@closeAutoFocus | [event: Event] | Emitted when focus returns on close; call event.preventDefault() to stop it. |
| Slot | Props |
|---|---|
#default | — |
| Data attribute | Value |
|---|---|
[data-slot] | "popover-content" |
PopoverTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
asChild? | boolean | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
as? | AsTag | Component | — | The element or component this component should render as. Can be overwritten by asChild. |
| Slot | Props |
|---|---|
#default | — |
| Data attribute | Value |
|---|---|
[data-slot] | "popover-trigger" |
Keyboard Interactions
Perilaku keyboard-nya datang dari primitif Reka UI Popover yang dipakai komponen ini, mengikuti pola WAI-ARIA.
| Key | Description |
|---|---|
Space | Opens/closes the popover. |
Enter | Opens/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 PopoverTrigger. |
CSS Variables
Token tema yang dibaca komponen ini — ubah nilainya di CSS global (:root dan .dark, lihat Theming) untuk mengubah tampilannya tanpa menyentuh komponennya: --border, --popover, --popover-foreground, --radius.
Credits
Berasal dari shadcn-vue (MIT, Copyright (c) 2023 unovue). Rantai lengkapnya di Credits.