Menu
Open a menu of actions from a button.
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 Menu.vue and index.ts into app/components/ui/menu/.
app/components/ui/menu/Menu.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 array or grouped array (groups get auto-separators). |
side | "top" | "bottom" | "left" | "right" | "bottom" | Preferred side to position the menu. |
align | "start" | "center" | "end" | "start" | Alignment relative to the trigger. |
sideOffset | number | 4 | Gap in px between trigger and menu. |
closeOnSelect | boolean | true | Close the menu after an item is selected. |
radioValues | Record<string, string> | — | v-model:radio-values — state for radio groups. |
teleport | string | false | false | Teleport target for the menu. |
as | string | Component | "div" | Root element tag. |
dir | "ltr" | "rtl" | "ltr" | Logical keyboard direction and preferred submenu side. |
ui | MenuUi | — | CSS class overrides. |
Slots
| Slot | Scoped props | Description |
|---|---|---|
trigger | { isOpen, open, close, toggle, triggerProps } | The element that opens the menu. |
[item.slot] | { item } | Per-item render override when item.slot is set. |
Events
| Event | Payload | Description |
|---|---|---|
open-change | [open: boolean, details] | Fired when the open state changes. |
select | [item: MenuItem, details] | Fired when an item is selected. |
check-change | [item: MenuItem, checked: boolean, details] | Fired when a checkbox item changes. |
radio-change | [group: string, value: string, details] | Fired when a radio item is selected. |
update:radioValues | [values: Record<string, string>] | v-model event for radio group state. |
Exposed methods
| Method | Signature | Description |
|---|---|---|
open | (reason?, event?) => void | Opens the menu. |
close | (reason?, event?) => void | Closes the menu. |
toggle | (reason?, event?) => void | Toggles the menu. |
Keyboard
| Key | Behavior |
|---|---|
ArrowDown / ArrowUp | Moves focus through enabled items and loops. |
Home / End | Focuses first or last enabled item. |
Enter / Space | Activates item, checkbox, radio, or opens submenu. |
ArrowRight | Opens focused submenu and moves into it; reversed in RTL. |
ArrowLeft | Closes submenu and restores submenu-trigger focus; reversed in RTL. |
Escape | Closes submenu level or whole menu. |
| Printable characters | Typeahead focuses first matching item within 500 ms buffer. |
Opening with a pointer focuses the menu panel without highlighting an item. Arrow keys then move through items. Keyboard activation focuses the first enabled item. Trigger keyboard activation comes from trigger element supplied by user; apply triggerProps and use a native button.