Context Menu
Show a menu of actions at the pointer when someone right-clicks.
Demos
Size
Usage
vue
<script setup lang="ts">
import { Accordion } from '~/components/ui/accordion'
const items = [
{ value: 'source', label: 'Do I own the source?', content: 'Yes. Copy and adapt the files.' },
]
</script>
<template>
<Accordion :items="items" />
</template>
Installation
Complete the shared installation. Copy ContextMenu.vue and index.ts into app/components/ui/context-menu/.
app/components/ui/context-menu/ContextMenu.vue
<script setup lang="ts">
import { AlertDialog as Primitive } from 'akaza-ui'
import { computed, useAttrs, useTemplateRef } from 'vue'
import { cn } from '../../../utils/ui'
import uiConfig from '../ui.config'
import {
alertDialogVariants,
resolveAlertDialogVariants,
type AlertDialogProps,
type AlertDialogSlots,
} from './index'
defineOptions({ inheritAttrs: false })
// Preserve Akaza defaults when optional props, including Boolean aliases, are omitted.
const props = withDefaults(defineProps<AlertDialogProps>(), {
as: undefined,
teleport: undefined,
transition: undefined,
duration: undefined,
title: undefined,
ariaLabel: undefined,
description: undefined,
ui: undefined,
modelValue: undefined,
})
defineSlots<AlertDialogSlots>()
const attrs = useAttrs()
const styles = computed(() => alertDialogVariants(resolveAlertDialogVariants(props, uiConfig)))
const mergedUi = computed(() => {
const overrides = props.ui as Record<string, string | undefined> | undefined
return Object.fromEntries(
Object.entries(styles.value).map(([part, style]) => [
part,
cn(style(), overrides?.[part], part === 'content' ? props.class : undefined),
]),
)
})
const primitiveProps = computed(() => {
const { class: _class, ui: _ui, width: _width, ...native } = props
return native
})
const primitive = useTemplateRef<InstanceType<typeof Primitive>>('primitive')
defineExpose({
get open() {
return primitive.value!.open
},
get close() {
return primitive.value!.close
},
get toggle() {
return primitive.value!.toggle
},
get titleId() {
return primitive.value!.titleId
},
get descriptionId() {
return primitive.value!.descriptionId
},
})
</script>
<template>
<component
:is="Primitive"
ref="primitive"
v-bind="{ ...primitiveProps, ...attrs }"
:ui="mergedUi"
>
<template v-for="(_, name) in $slots" #[name]="scope"
><slot :name="name as keyof AlertDialogSlots" v-bind="scope ?? {}"
/></template>
</component>
</template>
API
Variants and defaults
| Prop | Values | Default |
|---|---|---|
size | xs, sm, md, lg, xl | sm |
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items | MenuItem[] | MenuItem[][] | โ | Flat or grouped menu item array. |
disabled | boolean | false | Prevents opening. |
dir | "ltr" | "rtl" | "ltr" | Logical keyboard direction and preferred submenu side. |
closeOnSelect | boolean | true | Closes after normal item selection. |
radioValues | Record<string, string> | โ | State for radio item groups. |
sideOffset | number | 4 | Gap in px from the pointer. |
longPressDelay | number | 700 | Touch/pen hold delay. Set 0 to disable. |
restoreFocus | boolean | true | Returns focus after keyboard close or selection. |
teleport | string | false | "body" | Teleport target. |
ui | ContextMenuUi | โ | Classes for root, content, and menu parts. |
Slots
| Slot | Props | Description |
|---|---|---|
default | isOpen, openAt, close | Context-menu surface. |
[item.slot] | Depends on item type | Per-item render override. |
checkbox-item | item, checked | Shared checkbox item renderer. |
radio-item | item, checked | Shared radio item renderer. |
label | item | Shared label renderer. |
Events
| Event | Payload | Description |
|---|---|---|
open-change | (open, details) | Fired before open state changes. |
select | (item, details) | Fired when a normal item is selected. |
check-change | (item, checked, details) | Fired when a checkbox item changes. |
radio-change | (group, value, details) | Fired when a radio item is selected. |
update:radioValues | (values) | v-model event for radio state. |
Keyboard
| Key | Behavior |
|---|---|
ArrowDown / ArrowUp | Move highlighted item. |
Home / End | Move to first/last enabled item. |
Enter / Space | Select or toggle highlighted item. |
ArrowRight / ArrowLeft | Open/close submenu; reversed in RTL, even after a visual collision flip. |
Escape | Close the current submenu level, or the context menu when at its root. |
Shift+F10 / Context Menu key | Open at focused target. |
Touch and pen users can open the menu with a long press. Moving more than 10px before delay cancels it.