Popover VPopover anchors a native popover panel to a trigger. Add the role and keyboard behaviour required by your content.
Usage Details Anyone with the link can open this file.
<script setup lang="ts">
import { VButton, VPopover, VTypography } from 'vectis-ui'
</script>
<template>
<VPopover>
<template #trigger="{ triggerProps }">
<VButton variant="outline" tone="neutral" v-bind="triggerProps">Details</VButton>
</template>
<VTypography>Anyone with the link can open this file.</VTypography>
</VPopover>
</template> Examples Placements placement sets the preferred position. The panel flips when the requested side lacks space.
top-start top top-end bottom-start bottom bottom-end left-start left left-end right-start right right-end <script setup lang="ts">
import { VButton, VPopover, VTypography, type PopoverPlacement } from 'vectis-ui'
const PLACEMENTS: PopoverPlacement[] = [
'top-start',
'top',
'top-end',
'bottom-start',
'bottom',
'bottom-end',
'left-start',
'left',
'left-end',
'right-start',
'right',
'right-end',
]
</script>
<template>
<div class="grid">
<VPopover v-for="placement in PLACEMENTS" :key="placement" :placement="placement">
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral" size="sm">
{{ placement }}
</VButton>
</template>
<VTypography variant="body-sm">Placed {{ placement }}</VTypography>
</VPopover>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(3, max-content);
justify-content: center;
gap: var(--vectis-space-4);
padding: var(--vectis-space-10) var(--vectis-space-12);
}
</style> Interactive content Panels can contain controls. Focus is not trapped; provide keyboard behaviour appropriate to the content.
<script setup lang="ts">
import { ref } from 'vue'
import { VButton, VCheckbox, VPopover, VTypography } from 'vectis-ui'
const open = ref(false)
const filters = ref({ active: true, archived: false, mine: false })
const applied = ref('Active')
function apply() {
const chosen = Object.entries(filters.value)
.filter(([, on]) => on)
.map(([key]) => key)
applied.value = chosen.length ? chosen.join(', ') : 'none'
open.value = false
}
</script>
<template>
<div class="column">
<VPopover v-model:open="open" placement="bottom-start">
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral">Filters</VButton>
</template>
<div class="panel">
<VTypography variant="overline" tone="muted">Show</VTypography>
<VCheckbox v-model="filters.active" label="Active" />
<VCheckbox v-model="filters.archived" label="Archived" />
<VCheckbox v-model="filters.mine" label="Mine only" />
<div class="actions">
<VButton variant="ghost" tone="neutral" size="sm" @click="open = false">Cancel</VButton>
<VButton size="sm" @click="apply">Apply</VButton>
</div>
</div>
</VPopover>
<VTypography variant="body-sm" tone="muted">Showing: {{ applied }}</VTypography>
</div>
</template>
<style scoped>
.column {
display: grid;
justify-items: start;
gap: var(--vectis-space-3);
}
.panel {
display: grid;
gap: var(--vectis-space-2);
min-inline-size: 14rem;
}
.actions {
display: flex;
justify-content: flex-end;
gap: var(--vectis-space-2);
margin-block-start: var(--vectis-space-2);
}
</style> Modes auto closes on outside click or Escape. In manual mode, provide dismissal yourself. Control visibility with v-model:open or the exposed show and close methods.
auto Click outside or press Escape: the browser closes this one.
manual Clicking outside leaves this open. Escape does nothing either.
Close Opened through the ref Opened synchronously, with no tick in between.
Close show() <script setup lang="ts">
import { ref, useTemplateRef } from 'vue'
import { VButton, VPopover, VTypography } from 'vectis-ui'
const manualOpen = ref(false)
const syncPanel = useTemplateRef<InstanceType<typeof VPopover>>('syncPanel')
</script>
<template>
<div class="column">
<VPopover>
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral">auto</VButton>
</template>
<VTypography variant="body-sm">
Click outside or press Escape: the browser closes this one.
</VTypography>
</VPopover>
<VPopover v-model:open="manualOpen" mode="manual">
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral">manual</VButton>
</template>
<div class="panel">
<VTypography variant="body-sm">
Clicking outside leaves this open. Escape does nothing either.
</VTypography>
<VButton size="sm" @click="manualOpen = false">Close</VButton>
</div>
</VPopover>
<!-- Use exposed methods when opening must happen synchronously. -->
<div class="row">
<VPopover ref="syncPanel" mode="manual">
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral">
Opened through the ref
</VButton>
</template>
<div class="panel">
<VTypography variant="body-sm"
>Opened synchronously, with no tick in between.</VTypography
>
<VButton size="sm" @click="syncPanel?.close()">Close</VButton>
</div>
</VPopover>
<VButton variant="ghost" tone="neutral" @click="syncPanel?.show()">show()</VButton>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
justify-items: start;
gap: var(--vectis-space-4);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-3);
}
.panel {
display: grid;
justify-items: start;
gap: var(--vectis-space-3);
max-inline-size: 16rem;
}
</style> Match trigger matchTrigger makes the trigger width the panel’s minimum width.
A wide trigger, a narrow panel A wide trigger, matched Narrow The content is wider than the trigger, so the panel grows past it rather than being squeezed into its width.
<script setup lang="ts">
import { VButton, VPopover, VTypography } from 'vectis-ui'
</script>
<template>
<div class="column">
<VPopover placement="bottom-start">
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral" class="wide">
A wide trigger, a narrow panel
</VButton>
</template>
<VTypography variant="body-sm">Short.</VTypography>
</VPopover>
<VPopover match-trigger placement="bottom-start">
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral" class="wide">
A wide trigger, matched
</VButton>
</template>
<VTypography variant="body-sm">Short.</VTypography>
</VPopover>
<VPopover match-trigger placement="bottom-start">
<template #trigger="{ triggerProps }">
<VButton v-bind="triggerProps" variant="outline" tone="neutral">Narrow</VButton>
</template>
<VTypography variant="body-sm">
The content is wider than the trigger, so the panel grows past it rather than being squeezed
into its width.
</VTypography>
</VPopover>
</div>
</template>
<style scoped>
.column {
display: grid;
justify-items: start;
gap: var(--vectis-space-4);
}
.wide {
inline-size: 22rem;
}
</style> Anchoring to your own element Use anchor for an existing CSS anchor, including text input triggers. Set the anchor on the field’s control box and scope it from a parent.
<script setup lang="ts">
import { ref } from 'vue'
import { VPopover, VTypography } from 'vectis-ui'
const CITIES = ['Bordeaux', 'Lyon', 'Marseille', 'Nantes', 'Paris', 'Toulouse']
const query = ref('')
const open = ref(false)
const matches = () =>
CITIES.filter((city) => city.toLowerCase().startsWith(query.value.toLowerCase()))
function choose(city: string) {
query.value = city
open.value = false
}
</script>
<template>
<!-- Scope the anchor so top-layer panels do not attach to another instance. -->
<div class="field-wrapper">
<!-- Text inputs cannot use popovertarget; open the panel from the focus handler. -->
<input
v-model="query"
class="field"
type="text"
placeholder="A city"
aria-label="A city"
@focus="open = true"
@input="open = true"
/>
<VPopover v-model:open="open" anchor="--city-anchor" match-trigger mode="manual" bare>
<ul class="list">
<li v-for="city in matches()" :key="city">
<button type="button" class="row" @click="choose(city)">{{ city }}</button>
</li>
<li v-if="matches().length === 0" class="empty">
<VTypography variant="body-sm" tone="muted">No city matches</VTypography>
</li>
</ul>
</VPopover>
</div>
</template>
<style scoped>
.field-wrapper {
anchor-scope: --city-anchor;
inline-size: 16rem;
}
.field {
anchor-name: --city-anchor;
inline-size: 100%;
padding: 0 var(--vectis-space-3);
block-size: var(--vectis-control-height-md);
border: 1px solid var(--vectis-color-border);
border-radius: var(--vectis-radius-interactive);
background: var(--vectis-color-surface);
color: var(--vectis-color-text);
font: inherit;
}
.list {
display: grid;
margin: 0;
padding: var(--vectis-space-1);
border: 1px solid var(--vectis-color-border);
border-radius: var(--vectis-radius-overlay);
background: var(--vectis-color-surface-overlay);
box-shadow: var(--vectis-shadow-lg);
list-style: none;
}
.row {
inline-size: 100%;
padding: var(--vectis-space-2) var(--vectis-space-3);
border: none;
border-radius: var(--vectis-radius-interactive);
background: none;
color: inherit;
font: inherit;
text-align: start;
cursor: pointer;
}
.row:hover {
background: var(--vectis-color-surface-muted);
}
.empty {
padding: var(--vectis-space-2) var(--vectis-space-3);
}
</style> API Props Slots Types Types used in the API tables. Import exported types from vectis-ui.
export type PopoverTriggerProps = {
popovertarget: string
'aria-expanded': boolean
'aria-controls': string
}