PXD
v0.2.1-dev

Popover

A pop-up box with no style, used to show some information.

Default

<script setup>
const content = 'The hymn of humanity is the hymn of courage.'
</script>

<template>
  <PStack justify="center" class="w-lg">
    <PPopover
      content-class="p-4 bg-background-100 shadow-sm border rounded-md"
      position="top-start"
    >
      <PButton> Top start </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" position="top">
      <PButton> Top </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" position="top-end">
      <PButton> Top end </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>
  </PStack>

  <PStack justify="between" class="w-lg my-2">
    <PStack direction="vertical" class="w-auto">
      <PPopover
        content-class="p-4 bg-background-100 shadow-sm border rounded-md"
        position="left-start"
      >
        <PButton> Left start </PButton>

        <template #content>
          {{ content }}
        </template>
      </PPopover>

      <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" position="left">
        <PButton> Left </PButton>

        <template #content>
          {{ content }}
        </template>
      </PPopover>

      <PPopover
        content-class="p-4 bg-background-100 shadow-sm border rounded-md"
        position="left-end"
      >
        <PButton> Left end </PButton>

        <template #content>
          {{ content }}
        </template>
      </PPopover>
    </PStack>

    <PStack direction="vertical" align="end" class="w-auto">
      <PPopover
        content-class="p-4 bg-background-100 shadow-sm border rounded-md"
        position="right-start"
      >
        <PButton> Right start </PButton>

        <template #content>
          {{ content }}
        </template>
      </PPopover>

      <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" position="right">
        <PButton> Right </PButton>

        <template #content>
          {{ content }}
        </template>
      </PPopover>

      <PPopover
        content-class="p-4 bg-background-100 shadow-sm border rounded-md"
        position="right-end"
      >
        <PButton> Right end </PButton>

        <template #content>
          {{ content }}
        </template>
      </PPopover>
    </PStack>
  </PStack>

  <PStack justify="center" class="w-lg">
    <PPopover
      content-class="p-4 bg-background-100 shadow-sm border rounded-md"
      position="bottom-start"
    >
      <PButton> Bottom start </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" position="bottom">
      <PButton> Bottom </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover
      content-class="p-4 bg-background-100 shadow-sm border rounded-md"
      position="bottom-end"
    >
      <PButton> Bottom end </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>
  </PStack>
</template>

Trigger Methods

<script setup>
import { ref } from 'vue'

const visible = ref(false)
const content =
  'The woods are lovely, dark and deep, but I have promises to keep, and miles to go before I sleep'
</script>

<template>
  <PStack>
    <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" trigger="hover">
      <PButton> Hover to active </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" trigger="click">
      <PButton> Click to active </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover
      content-class="p-4 bg-background-100 shadow-sm border rounded-md"
      trigger="contextmenu"
    >
      <PButton> Contextmenu to active </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover
      content-class="p-4 bg-background-100 shadow-sm border rounded-md"
      :trigger="['hover', 'click']"
    >
      <PButton> Hover/Click to active </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>

    <PPopover
      v-model="visible"
      trigger="manual"
      content-class="p-4 bg-background-100 shadow-sm border rounded-md"
    >
      <PButton @click="visible = !visible"> Manual to active </PButton>

      <template #content>
        {{ content }}
      </template>
    </PPopover>
  </PStack>
</template>

Multiple trigger

Use trigger-selector when several DOM elements should share one popover instance. The popover keeps the same floating element open and updates its position to the active matched trigger.

Trigger clicks are read in the capture phase, so an inner @click.stop still reaches the popover: use it to keep a clickable row from reacting without disabling the trigger. Mark a subtree with data-popover-ignore when its events should not reach the popover at all. A popover nested inside another one’s trigger area owns its own events.

<script setup>
const actions = [
  { key: 'bold', label: 'B', description: 'Make selected text bold.' },
  { key: 'italic', label: 'I', description: 'Make selected text italic.' },
  { key: 'underline', label: 'U', description: 'Underline selected text.' },
]
</script>

<template>
  <PPopover
    trigger="hover"
    trigger-selector="[data-popover-trigger]"
    content-class="p-3 bg-background-100 shadow-sm border rounded-md text-sm"
  >
    <div class="flex">
      <button
        v-for="action in actions"
        :key="action.key"
        type="button"
        data-popover-trigger
        :data-popover-key="action.key"
        :data-popover-description="action.description"
        class="h-8 w-8 -ms-px border bg-background-100 font-medium first:ms-0 first:rounded-s-md last:rounded-e-md"
      >
        {{ action.label }}
      </button>
    </div>

    <template #content="{ activeTrigger, activeTriggerIndex }">
      {{ activeTrigger.dataset.popoverDescription + activeTriggerIndex }}
    </template>
  </PPopover>
</template>

Align to point

Move, click, or right-click in this area
<script setup>
import { ref } from 'vue'

const content = 'The Popover follows the pointer position.'
const trigger = ref('hover')

const toggleButtonOptions = [
  { label: 'Hover', value: 'hover' },
  { label: 'Click', value: 'click' },
  { label: 'Context Menu', value: 'contextmenu' },
]
</script>

<template>
  <PStack direction="vertical" align="start" class="w-full gap-3">
    <PToggleButtonGroup v-model="trigger" size="sm" variant="outline" :multiple="false" :options="toggleButtonOptions" />

    <PPopover
      align-point
      :trigger="trigger"
      class="w-full"
      :interactive="false"
      content-class="p-3 bg-background-100 shadow-sm border rounded-md text-sm"
    >
      <div class="flex h-48 w-full items-center justify-center rounded-md border border-dashed text-sm">
        Move, click, or right-click in this area
      </div>

      <template #content>
        {{ content }}
      </template>
    </PPopover>
  </PStack>
</template>

Offset

<script setup>
const content =
  'Two roads diverged in a wood, and I — I took the one less traveled by, and that has made all the difference.'
</script>

<template>
  <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" :offset="30">
    <PButton> Hover to active </PButton>

    <template #content>
      {{ content }}
    </template>
  </PPopover>
</template>

Max width

<script setup>
const content = 'Do not go gentle into that good night, rage, rage against the dying of the light.'
</script>

<template>
  <PPopover content-class="p-4 bg-background-100 shadow-sm border rounded-md" :max-width="200">
    <PButton> Hover to active </PButton>

    <template #content>
      {{ content }}
    </template>
  </PPopover>
</template>

Match trigger width

match-width puts the trigger width on the panel’s min-width, so content wider than the trigger still grows; left off, the panel sizes to its content. Either way the panel stops at max-width. To clamp the content exactly to the trigger width, use the exposed --popover-trigger-width variable, e.g. content-class="w-(--popover-trigger-width)" (the content scrolls internally).

<script setup>
const content = 'Do not go gentle into that good night, rage, rage against the dying of the light.'
</script>

<template>
  <PPopover
    match-width
    content-class="p-4 bg-background-100 shadow-sm border rounded-md"
    :max-width="200"
  >
    <PButton> Hover to active </PButton>

    <template #content>
      {{ content }}
    </template>
  </PPopover>
</template>

closeOnPressEscape

<script setup>
const content = 'Do not go gentle into that good night, rage, rage against the dying of the light.'
</script>

<template>
  <PPopover close-on-press-escape content-class="p-4 bg-background-100 shadow-sm border rounded-md" :max-width="200">
    <PButton> Hover to active </PButton>

    <template #content>
      {{ content }}
    </template>
  </PPopover>
</template>

Nested popovers

The nearest popover owns the trigger event. Clicking the small button opens its own popover and closes the row one, so two contents are never shown at once, and no manual stop is needed.

Inbox
Drafts
<script setup>
const rows = [
  { key: 'inbox', label: 'Inbox', detail: '12 unread messages' },
  { key: 'drafts', label: 'Drafts', detail: '3 unsent drafts' },
]
</script>

<template>
  <PPopover
    trigger="click"
    trigger-selector="[data-row]"
    content-class="p-3 bg-background-100 shadow-sm border rounded-md text-sm"
  >
    <PStack direction="vertical" class="w-64 gap-1">
      <div
        v-for="row in rows"
        :key="row.key"
        data-row
        :data-detail="row.detail"
        class="h-9 pe-1 ps-2 flex items-center justify-between rounded-md border cursor-pointer"
      >
        {{ row.label }}

        <PPopover trigger="click" content-class="p-2 bg-background-100 shadow-sm border rounded-md text-sm">
          <PButton size="sm" variant="ghost"> Actions </PButton>

          <template #content> Actions for {{ row.label }} </template>
        </PPopover>
      </div>
    </PStack>

    <template #content="{ activeTrigger }">
      {{ activeTrigger?.dataset.detail }}
    </template>
  </PPopover>
</template>

Ignored trigger areas

Every chip matches trigger-selector, but the second one carries data-popover-ignore: events inside it are never treated as a trigger, for any trigger method. A popover that is already open stays open until the pointer leaves it.

<script setup>
const chips = [
  { key: 'inbox', label: 'Inbox', description: '12 unread messages' },
  { key: 'drafts', label: 'Drafts', description: '3 unsent drafts', ignored: true },
  { key: 'sent', label: 'Sent', description: 'Everything delivered' },
]
</script>

<template>
  <PPopover
    trigger="hover"
    trigger-selector="[data-chip]"
    content-class="p-3 bg-background-100 shadow-sm border rounded-md text-sm"
  >
    <PStack class="w-64 gap-1">
      <button
        v-for="chip in chips"
        :key="chip.key"
        type="button"
        data-chip
        :data-description="chip.description"
        :data-popover-ignore="chip.ignored ? '' : undefined"
        class="h-8 px-2 rounded-md border bg-background-100 text-sm"
      >
        {{ chip.label }}
      </button>
    </PStack>

    <template #content="{ activeTrigger }">
      {{ activeTrigger?.dataset.description }}
    </template>
  </PPopover>
</template>

As child

as-child renders the default slot’s single element as the trigger itself: the popover’s attributes, DOM listeners and state markers are merged onto it and no wrapper is added, so aria-*, id and a listener bound on the popover describe the element people actually use. The child must resolve to exactly one element — text, several siblings and a component with multiple roots fall back to the wrapper with a development warning. It cannot be combined with trigger-selector.

<script setup>
const content = 'The button is the trigger, without a wrapper element.'
</script>

<template>
  <PPopover as-child content-class="p-4 bg-background-100 shadow-sm border rounded-md">
    <PButton aria-label="Open details"> As child </PButton>

    <template #content>
      {{ content }}
    </template>
  </PPopover>
</template>

Props

NameTypeDefaultDescription
z-indexnumber | string-Custom z-index for the Popover wrapper
offsetnumber-Gap in px between the Popover and its trigger
trigger'click' | 'hover' | 'contextmenu' | 'manual' | ('click' | 'hover' | 'contextmenu' | 'manual')[]() => ['hover']Trigger methods; takes one or an array of hover, click, contextmenu, manual
trigger-selectorstring-Selector for multiple DOM triggers inside the default slot.
as-childbooleanfalseMerge the popover’s attributes, listeners and state markers onto the default slot’s single element instead of wrapping it.
align-pointboolean-Align the Popover to the pointer position.
disabledboolean-Ignore every trigger event so the Popover cannot be shown
layout'auto' | 'anchored' | 'sheet''auto'Panel layout: auto anchors it beside the trigger on wide screens and turns it into a bottom sheet with a dimmed backdrop and slide motion on narrow ones. Only the sheet form is announced as a modal dialog
match-widthbooleanfalseKeep the panel at least as wide as its trigger; without it the panel sizes to its content
keep-heightbooleanfalseKeep the largest content height seen while open, so filtering cannot move the anchored edge
max-widthnumber | string-Max width of the panel; a number is treated as px
max-heightnumber | string'min(50rem, 80dvh)'Max height of the panel; a number is treated as px
position'top' | 'right' | 'bottom' | 'left' | ...bottomPreferred placement: top, right, bottom or left, each with optional -start / -end
show-delaynumber0Delay in ms before the Popover is shown
hide-delaynumber0Delay in ms before the Popover is hidden
destroy-delaynumber3000Delay before unmounting content after hide.
show-arrowboolean-Render the arrow pointing back to the trigger
arrow-colorstring-Fill color of the arrow, any CSS color value
model-valueboolean-Controlled visibility, normally used with the manual trigger
interactivebooleantrueKeep the Popover open while the pointer moves over it
auto-positionbooleantrueReposition on scroll and resize, flip when it would be clipped, and cap the content height to the space available
wrapper-classstring | any[] | object-Class bound to the Popover wrapper
aria-labelledbystring-ID of the element that labels the Popover dialog
aria-targetHTMLElement-Element that receives the popup state (aria-haspopup, aria-expanded) when the trigger is not the control, such as a field’s inner input
content-classstring | any[] | object-Class bound to the Popover content
toggle-on-triggerbooleantrueHide the Popover when the trigger is activated again
auto-focus-elementstring | booleanfalseFocus the first tabbable element on open, or the one matching a selector
return-focus-on-deactivatebooleantrueReturn focus to the trigger when the Popover closes
close-on-invisiblebooleantrueHide the Popover when the trigger is clipped or scrolled out of view
close-on-outside-clickbooleantrueClose the Popover when the pointer is pressed outside of it and its trigger
close-on-press-escapebooleantrueClose the Popover when pressing Escape
agentbooleantrueRegister with the agent bridge, so a snapshot lists it and a step can open it. Set false on a popover that only explains something, as a tooltip does.

Events

NameTypeDescription
show() => voidEmitted when the popover becomes visible.
hide() => voidEmitted when the popover becomes hidden.
escape(event: KeyboardEvent) => voidEmitted when Escape is pressed while the popover is open, before it hides.
outside-click(event: PointerEvent) => voidEmitted when the pointer is pressed outside both the trigger and the popover while it is open. Judged by where the press starts, so a drag that begins inside and releases outside does not count.
trigger-click(event: PointerEvent) => voidEmitted when one of the resolved trigger elements is clicked.
visible-change(visible: boolean) => voidEmitted when the visible state changes.
wrapper-keydown(event: KeyboardEvent) => voidEmitted when a key is pressed inside the popover while it is open.
update:model-value(visible: boolean) => voidEmitted right after show or hide with the new visibility.

Slots

NameDescription
defaultTrigger content
contentPopover content. Slot props: activeTrigger: HTMLElement | null, activeTriggerIndex: number.

Methods

NameTypeDescription
show() => Promise<void>Show the popover after the configured show-delay.
hide(immediate?: boolean) => Promise<void>Hide the popover, skipping the hide-delay when immediate is true.
update() => voidRecompute the popover position on the next animation frame.

Source

Source