Popover
Display text or interactive content beside a trigger. Use Tooltip for a short description and Popconfirm when an action requires confirmation.
Import
import { HuiPopover } from '@nscode/handy-ui'
import type { PopoverProps, PopoverTrigger, PopperPlacement } from '@nscode/handy-ui'
Examples
Accessible name without a visible title
aria-label names the actual dialog. The trigger keeps its own visible label.
<script setup lang="ts">
import { HuiButton, HuiPopover } from '@nscode/handy-ui'
</script>
<template>
<HuiPopover aria-label="Additional permissions" content="View, edit and export">
<HuiButton>3 more permissions</HuiButton>
</HuiPopover>
</template>
Triggers and title
Click toggles the popover. Hover and focus leave keyboard focus on the trigger.
<script setup lang="ts">
import { HuiButton, HuiPopover, HuiSpace } from '@nscode/handy-ui'
</script>
<template>
<HuiSpace wrap>
<HuiPopover trigger="click" title="Click" content="Click outside or press Escape to close."
><HuiButton>Click</HuiButton></HuiPopover
>
<HuiPopover trigger="hover" title="Hover" content="Move from the trigger into this panel."
><HuiButton>Hover</HuiButton></HuiPopover
>
<HuiPopover trigger="focus" title="Focus" content="Focus the button to show this panel."
><HuiButton>Focus</HuiButton></HuiPopover
>
</HuiSpace>
</template>
Controlled visibility, events and methods
Use manual trigger mode when an external button changes visible. A controlled popover requests a model update and waits for the parent to accept it.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiPopover, HuiSpace } from '@nscode/handy-ui'
const open = ref(false)
const popover = ref<InstanceType<typeof HuiPopover>>()
const events = ref('No visibility event')
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace>
<HuiButton @click="popover?.show()">Show</HuiButton>
<HuiButton @click="popover?.hide()">Hide</HuiButton>
<HuiButton @click="popover?.updatePosition()">Update position</HuiButton>
</HuiSpace>
<HuiPopover
ref="popover"
v-model:visible="open"
trigger="manual"
title="Controlled"
@show="events = 'Shown'"
@hide="events = 'Hidden'"
>
<template #reference
><HuiButton @click="open = !open">Toggle {{ open }}</HuiButton></template
>
<template #content
><p>Custom content can contain links, controls and other components.</p></template
>
</HuiPopover>
<output>{{ events }}</output>
</HuiSpace>
</template>
Width, placement, arrow and disabled state
Numbers mean pixels. An explicit width can be smaller than the default 150px minimum.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiPopover, HuiSpace, HuiSwitch } from '@nscode/handy-ui'
const disabled = ref(false)
</script>
<template>
<HuiSpace wrap align="center">
<HuiSwitch v-model="disabled" /><span>disabled = {{ disabled }}</span>
<HuiPopover
aria-label="Compact panel"
:disabled="disabled"
:width="100"
placement="right-start"
:offset="16"
:show-arrow="false"
content="A narrow panel"
><HuiButton>Compact</HuiButton></HuiPopover
>
</HuiSpace>
</template>
Inline teleport target
teleport=false keeps the panel in place. A selector chooses another target; the default is body.
<script setup lang="ts">
import { HuiButton, HuiPopover } from '@nscode/handy-ui'
</script>
<template>
<HuiPopover :teleport="false" title="Inline" content="This dialog remains inside its component.">
<HuiButton>Inline panel</HuiButton>
</HuiPopover>
</template>
Child popups and masks
Open the dialog, then its popover. The first complete mask click closes the popover; the second closes the dialog. Pressing inside the popover and releasing outside while selecting text keeps it open.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiModal, HuiPopover, HuiSpace } from '@nscode/handy-ui'
const dialog = ref(false)
const popup = ref(false)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiButton @click="dialog = true">Open dialog</HuiButton>
<HuiModal v-model:visible="dialog" title="Outside press boundaries">
<HuiPopover v-model:visible="popup" title="Selectable content">
<HuiButton>Open popover</HuiButton>
<template #content>
<p>Press here, select text and release outside. The popover stays open.</p>
<p>Click the mask twice to close the popover, then the dialog.</p>
</template>
</HuiPopover>
<p>Popover: {{ popup ? 'open' : 'closed' }}</p>
</HuiModal>
</HuiSpace>
</template>
Self-managed and controlled visibility
Omitting visible, or only listening to updates, stores visibility internally from false. Passing visible, including undefined, makes it controlled; undefined stays hidden. Requests emit update:visible in both modes. show and hide still describe actual visibility, so rejected requests do not emit those actual-state events. Switching control modes clears old hover-hide timers and removing the prop restores the internal value.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiPopover, HuiSpace } from '@nscode/handy-ui'
const popoverBound = ref(false)
const popoverRedraw = ref(0)
const popoverLast = ref<boolean | string>('None')
const recordPopover = (value: boolean) => {
popoverLast.value = value
}
</script>
<template>
<HuiSpace class="popover-q1-demo" direction="vertical" fill>
<HuiButton class="popover-redraw" @click="popoverRedraw++"
>Redraw parent {{ popoverRedraw }}</HuiButton
>
<HuiSpace wrap>
<HuiSpace class="popover-local" direction="vertical">
<span>Omitted visible</span>
<HuiPopover :data-parent="popoverRedraw" title="Visibility state">
<HuiButton class="popover-trigger">Show content</HuiButton>
<template #content>
<HuiSpace direction="vertical">
<span>Parent redraws retain the accepted visibility.</span>
<HuiButton class="popover-inside-redraw" @click="popoverRedraw++"
>Redraw parent {{ popoverRedraw }}</HuiButton
>
</HuiSpace>
</template>
</HuiPopover>
</HuiSpace>
<HuiSpace class="popover-listener" direction="vertical">
<span>Update listener only</span>
<HuiPopover
@update:visible="recordPopover"
:data-parent="popoverRedraw"
title="Visibility state"
>
<HuiButton class="popover-trigger">Show content</HuiButton>
<template #content>
<HuiSpace direction="vertical">
<span>Parent redraws retain the accepted visibility.</span>
<HuiButton class="popover-inside-redraw" @click="popoverRedraw++"
>Redraw parent {{ popoverRedraw }}</HuiButton
>
</HuiSpace>
</template>
</HuiPopover>
</HuiSpace>
<HuiSpace class="popover-empty" direction="vertical">
<span>Explicit undefined</span>
<HuiPopover :visible="undefined" :data-parent="popoverRedraw" title="Visibility state">
<HuiButton class="popover-trigger">Show content</HuiButton>
<template #content>
<HuiSpace direction="vertical">
<span>Parent redraws retain the accepted visibility.</span>
<HuiButton class="popover-inside-redraw" @click="popoverRedraw++"
>Redraw parent {{ popoverRedraw }}</HuiButton
>
</HuiSpace>
</template>
</HuiPopover>
</HuiSpace>
<HuiSpace class="popover-fixed" direction="vertical">
<span>Fixed hidden; parent rejects opening</span>
<HuiPopover :visible="false" :data-parent="popoverRedraw" title="Visibility state">
<HuiButton class="popover-trigger">Show content</HuiButton>
<template #content>
<HuiSpace direction="vertical">
<span>Parent redraws retain the accepted visibility.</span>
<HuiButton class="popover-inside-redraw" @click="popoverRedraw++"
>Redraw parent {{ popoverRedraw }}</HuiButton
>
</HuiSpace>
</template>
</HuiPopover>
</HuiSpace>
<HuiSpace class="popover-bound" direction="vertical">
<span>Two-way binding</span>
<HuiPopover
v-model:visible="popoverBound"
:data-parent="popoverRedraw"
title="Visibility state"
>
<HuiButton class="popover-trigger">Show content</HuiButton>
<template #content>
<HuiSpace direction="vertical">
<span>Parent redraws retain the accepted visibility.</span>
<HuiButton class="popover-inside-redraw" @click="popoverRedraw++"
>Redraw parent {{ popoverRedraw }}</HuiButton
>
</HuiSpace>
</template>
</HuiPopover>
</HuiSpace>
</HuiSpace>
<span class="popover-status"
>Requested: {{ popoverLast }};Bound visible: {{ popoverBound }}</span
>
</HuiSpace>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| content | string | — | Text content; the content slot can replace it |
| title | string | — | Visible panel title |
| ariaLabel | string | — | Accessible name on the dialog; explicit empty strings are retained |
| placement | PopperPlacement | 'top' | Preferred placement; flips when necessary |
| trigger | PopoverTrigger | 'click' | click, hover, focus or manual |
| width | number | string | — | Panel width; numbers are pixels |
| offset | number | 8 | Distance from the trigger in pixels |
| disabled | boolean | false | Prevent opening and hide an open panel |
| visible | boolean | — | Passed means controlled, including undefined as hidden. Omitted or listener-only stores visibility internally. |
| showArrow | boolean | true | Show the positioning arrow |
| popperClass | string | — | Class on the actual panel |
| transition | string | 'hui-popover-fade' | Vue Transition name |
| teleport | string | boolean | 'body' | Selector target; false renders in place, true means body |
Events
| Event | Payload | Description |
|---|---|---|
| update:visible | (value: boolean) | Visibility request from user interaction or methods, in both controlled and self-managed modes. |
| show | — | Actual visibility became true |
| hide | — | Actual visibility became false |
Slots
| Slot | Parameters | Description |
|---|---|---|
| default | — | Trigger element |
| reference | — | Trigger; takes priority over default |
| content | — | Replace content text |
Methods
| Method | Signature | Description |
|---|---|---|
| show | () => void | Open, or request visible=true when controlled |
| hide | () => void | Close, or request visible=false when controlled |
| updatePosition | () => void | Reposition against the current trigger geometry |
The instance also exposes readonly actualVisible.
Types
import type { PopoverProps, PopoverTrigger, PopperPlacement } from '@nscode/handy-ui'
type PopoverTrigger = 'hover' | 'click' | 'focus' | 'manual'
type PopperPlacement =
| 'top'
| 'top-start'
| 'top-end'
| 'bottom'
| 'bottom-start'
| 'bottom-end'
| 'left'
| 'left-start'
| 'left-end'
| 'right'
| 'right-start'
| 'right-end'