CMenu
A floating content container that positions itself relative to an activator element. Used as the foundation for dropdowns, selects, tooltips and other overlay components.
Basic usage
Show code
<template>
<c-menu
width="auto"
open-on-click
close-on-click-outside
close-on-content-click
align="bottom"
:offset-y="4"
>
<template #activator="{ on, activator }">
<c-btn class="bg-indigo" v-bind="activator" v-on="on" style="gap:8px">
<c-icon name="fas:folder" source="fa" :size="14" />
File
<c-icon name="fas:chevron-down" source="fa" :size="10" />
</c-btn>
</template>
<c-card class="elevation-4" style="min-width:220px">
<c-card-body class="py-1 px-0">
<c-list>
<c-list-item class="px-4" style="gap:12px" @click="notify('New file')">
<c-icon name="fas:plus" source="fa" :size="13" style="width:14px;opacity:.55" />
<span style="flex:1">New file</span>
<span class="kb">⌘N</span>
</c-list-item>
<c-list-item class="px-4" style="gap:12px" @click="notify('Open')">
<c-icon name="fas:folder" source="fa" :size="13" style="width:14px;opacity:.55" />
<span style="flex:1">Open…</span>
<span class="kb">⌘O</span>
</c-list-item>
<c-list-item class="px-4" style="gap:12px" @click="notify('Save')">
<c-icon name="fas:save" source="fa" :size="13" style="width:14px;opacity:.55" />
<span style="flex:1">Save</span>
<span class="kb">⌘S</span>
</c-list-item>
</c-list>
<div class="sep" />
<c-list>
<c-list-item class="px-4" style="gap:12px;color:#f44336" @click="notify('Delete')">
<c-icon name="fas:trash" source="fa" :size="13" style="width:14px" />
Delete file
</c-list-item>
</c-list>
</c-card-body>
</c-card>
</c-menu>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const msg = ref('')
function notify(text: string) {
msg.value = text
}
</script>
<style scoped>
.kb {
font-size: 11px;
color: var(--c-sys-color-on-surface-variant);
}
.sep {
height: 1px;
background: var(--c-sys-color-outline-variant);
margin: 4px 0;
}
</style>Hover
Use open-on-hover + close-on-leave for hover-triggered menus. open-delay / close-delay prevent accidental triggers.
Show code
<template>
<div class="d-flex align-center gap-1 pa-2 radius-8 elevation-1">
<c-menu
v-for="item in nav"
:key="item.label"
width="auto"
open-on-hover
close-on-leave
align="bottom"
:offset-y="2"
:open-delay="80"
:close-delay="140"
>
<template #activator="{ on, activator }">
<c-btn variant="text" :class="item.color" v-bind="activator" v-on="on" style="gap:6px">
<c-icon :name="item.icon" source="fa" :size="13" />
{{ item.label }}
</c-btn>
</template>
<c-card class="elevation-4" style="min-width:180px">
<c-card-body class="py-1 px-0">
<c-list>
<c-list-item v-for="link in item.links" :key="link.label" class="px-4" style="gap:10px">
<c-icon :name="link.icon" source="fa" :size="12" style="width:14px;opacity:.5" />
{{ link.label }}
</c-list-item>
</c-list>
</c-card-body>
</c-card>
</c-menu>
</div>
</template>
<script setup lang="ts">
const nav = [
{
label: 'Products',
icon: 'fas:briefcase',
color: 'text-indigo',
links: [
{ icon: 'fas:list-ul', label: 'UI Components' },
{ icon: 'fas:image', label: 'Icons' },
{ icon: 'fas:star', label: 'Themes' },
],
},
{
label: 'Docs',
icon: 'fas:code',
color: 'text-light-blue',
links: [
{ icon: 'fas:home', label: 'Getting started' },
{ icon: 'fas:file', label: 'Migration guide' },
],
},
]
</script>
<style scoped>
.text-indigo {
color: #3f51b5 !important;
}
.text-light-blue {
color: #03a9f4 !important;
}
</style>Positioning
align controls which side the menu opens on and how it aligns along the cross axis. Fine-tune with offsetX / offsetY.
When the menu is rendered inside its activator element, pass activator="parent" — CMenu binds activator listeners to the parent DOM element and does not render the activator slot.
bottombottom-centerbottom-righttop / top-center / top-rightright / right-centerleft / left-centerShow code
<!-- Opens below the activator, left-aligned -->
<c-menu
width="auto"
align="bottom"
:offset-y="8"
open-on-click
close-on-click-outside
close-on-content-click
>
<template #activator="{ on, activator }">
<c-btn class="bg-indigo" v-bind="activator" v-on="on">Bottom</c-btn>
</template>
<c-card>...</c-card>
</c-menu>
<!-- Opens to the right, vertically centered -->
<c-menu width="auto" align="right-center" :offset-x="8" open-on-click close-on-click-outside>
<template #activator="{ on, activator }">
<c-btn class="bg-teal" v-bind="activator" v-on="on">Right</c-btn>
</template>
<c-card>...</c-card>
</c-menu>
<!-- Opens above, centered horizontally -->
<c-menu width="auto" align="top-center" :offset-y="8" open-on-click close-on-click-outside>
<template #activator="{ on, activator }">
<c-btn class="bg-deep-purple" v-bind="activator" v-on="on">Top center</c-btn>
</template>
<c-card>...</c-card>
</c-menu>Context menu
Use position-x / position-y to anchor the menu to fixed coordinates instead of an activator element.
Show code
<template>
<div class="area" @contextmenu.prevent="onContextMenu">Right-click anywhere</div>
<c-menu
v-model="open"
:position-x="x"
:position-y="y"
width="auto"
close-on-click-outside
close-on-content-click
>
<c-card class="elevation-4" style="min-width:200px">
<c-card-body class="py-1 px-0">
<c-list>
<c-list-item class="px-4" style="gap:12px" @click="toast('Opened')">
<c-icon name="fas:eye" source="fa" :size="13" style="width:14px;opacity:.5" /> Open
</c-list-item>
<c-list-item class="px-4" style="gap:12px" @click="toast('Renamed')">
<c-icon name="fas:pen" source="fa" :size="13" style="width:14px;opacity:.5" /> Rename
</c-list-item>
<c-list-item class="px-4" style="gap:12px" @click="toast('Copied')">
<c-icon name="fas:link" source="fa" :size="13" style="width:14px;opacity:.5" /> Copy
path
</c-list-item>
</c-list>
<div class="sep" />
<c-list>
<c-list-item class="px-4" style="gap:12px;color:#f44336" @click="toast('Deleted')">
<c-icon name="fas:trash" source="fa" :size="13" style="width:14px" /> Move to Trash
</c-list-item>
</c-list>
</c-card-body>
</c-card>
</c-menu>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const open = ref(false)
const x = ref(0)
const y = ref(0)
function onContextMenu(e: MouseEvent) {
open.value = false
setTimeout(() => {
x.value = e.pageX
y.value = e.pageY
open.value = true
}, 0)
}
function toast(msg: string) {
console.log(msg)
}
</script>
<style scoped>
.area {
padding: 48px;
text-align: center;
border: 2px dashed var(--c-sys-color-outline-variant);
border-radius: 8px;
}
.sep {
height: 1px;
background: var(--c-sys-color-outline-variant);
}
</style>Width
By default CMenu inherits the width of its activator element. Pass width="auto" to let the content define its own width, or pass a fixed value.
<!-- Stretches to fill the activator (default) -->
<c-menu align="bottom">...</c-menu>
<!-- Content determines its own width -->
<c-menu align="bottom" width="auto">...</c-menu>
<!-- Fixed width -->
<c-menu align="bottom" :width="240">...</c-menu>Collision strategies
strategy="reverse" flips to the opposite side when there is not enough space. strategy="bounce" keeps the menu inside the viewport by shifting it.
<!-- Flip above when there's no room below -->
<c-menu align="bottom" strategy="reverse" open-on-click>...</c-menu>
<!-- Stay inside the viewport edges -->
<c-menu align="bottom" strategy="bounce" open-on-click>...</c-menu>v-model
Control the open state from outside the component.
<template>
<c-menu v-model="open" align="bottom">
<template #activator="{ on, activator }">
<button v-bind="activator" v-on="on">Toggle</button>
</template>
<div>Content</div>
</c-menu>
<button @click="open = !open">Toggle from outside</button>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const open = ref(false)
</script>ARIA
CMenu does not add any ARIA attributes on its own — each consumer is responsible for accessibility. Pass role and aria-* directly:
<c-menu role="menu" aria-label="Actions" open-on-click align="bottom"> ... </c-menu>API
Props
modelValuebooleanfalseopenOnClickbooleancloseOnClickbooleanopenOnHoverbooleancloseOnLeavebooleanopenOnFocusbooleancloseOnClickOutsidebooleancloseOnContentClickbooleanalignAlignValuebottom, top-center, right-center, bottom-rightoffsetXnumber | stringoffsetYnumber | stringpositionXnumberpositionYnumberstrategy'reverse' | 'bounce'widthnumber | stringheightnumber | stringminWidthnumber | stringmaxWidthnumber | stringminHeightnumber | stringmaxHeightnumber | stringopenDelaynumber | stringcloseDelaynumber | stringtransitionstring'fade'ssrbooleanactivatorElement | ComponentPublicInstance | 'parent' | stringpresetstringCMenuPreset (root zone, opened / closed states). Inside CSelect / CAutocomplete the menu also picks up the nested CMenuPreset from the combobox preset's menu field via contextAlignValue
type AlignValue =
| 'top'
| 'top-center'
| 'top-left'
| 'top-right'
| 'bottom'
| 'bottom-center'
| 'bottom-left'
| 'bottom-right'
| 'left'
| 'left-center'
| 'right'
| 'right-center'CSS variables
--c-menu-bg-colorvar(--c-sys-color-surface-container-high)--c-menu-text-colorvar(--c-sys-color-on-surface)--c-menu-border-radiusvar(--c-sys-shape-lg)--c-menu-elevationvar(--c-sys-elevation-3)--c-menu-max-height100%Slots
activator{ on, activator }defaultactivator slot props
onActivatorListenersv-on="on"activatorRecord<string, any>v-bind="activator"Events
update:modelValuebooleanopencloseclickoutside-clickExpose
open() => voidclose() => voidtoggle() => void