Navigation & menus
Layout
Menu
A dropdown list of actions that opens from a trigger, with full keyboard navigation. Use it for a set of actions behind one button.
Install
import { Menu } from 'vael-ui'Playground
Fruits
bottom
start
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Menu, Button } from 'vael-ui'
const items = [
{ label: 'Apple', value: 'apple' },
{ label: 'Banana', value: 'banana' },
{ label: 'Cherry', value: 'cherry' },
]
const open = ref(false)
</script>
<template>
<Menu :items="items" v-model:open="open">
<template #trigger>
<Button>Trigger</Button>
</template>
</Menu>
</template>Motion New
Menu's motion, and ContextMenu's and SplitButton's: values or hooks for positioner and panel, and how it opens and closes. false turns it off.
<Menu
:motion="{
initial: { panel: { opacity: 0, y: 8, scale: 0.98 } },
spring: { damping: 0.85, response: 0.35 },
}"
/>| Name | Type | Description |
|---|---|---|
initialexit | positionerpanel | Sets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate. |
enterleave | (parts, context) => animation | Animates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted. |
morphlinkedexitOrder | 'trigger' | Record<string, LinkedMotion> | 'reverse' | morph: 'trigger' grows it out of the element that opened it. linked moves other elements with it, such as the page receding behind it. exitOrder: 'reverse' closes its children first. |
springdurationeasing | { damping, response } | number | string | Times all of it: a spring, or a duration in ms with an easing. Never both. |
false | boolean | Turns its motion off, for an animation of your own on its exposed elements. |
Accessibility
Follows the Menu Button pattern from the WAI-ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| EnterSpace | Opens the menu from the trigger and focuses the first item. |
| ArrowDown | Opens the menu from the trigger and focuses the first item. |
| ArrowUp | Opens the menu from the trigger and focuses the last item. |
| ArrowDownArrowUp | Moves focus to the next or previous item, wrapping at the ends. |
| HomeEnd | Moves focus to the first or last item. |
| EnterSpace | Activates the focused item and closes the menu, or opens its submenu. |
| Space | On a checkbox row, toggles it and keeps the menu open. |
| ArrowRight | Opens the focused item’s submenu and focuses its first item. |
| ArrowLeft | Closes the submenu and returns focus to its parent item. |
| A letter | Moves focus to the next item whose label starts with the typed letters. |
| Escape | Closes the open submenu, or the menu, and returns focus to its trigger. |
| Tab | Closes the menu and moves focus to the element after the trigger. |
- The trigger gets
aria-haspopup="menu",aria-expanded, andaria-controlswhile open. The list hasrole="menu"and is named by its trigger, and a submenu by its row. - Rows are
role="menuitem", orrole="menuitemcheckbox"witharia-checkedwhencheckedis set. Submenu rows addaria-haspopupandaria-expanded. - Items use a roving
tabindex, and disabled items are skipped. The row under the mouse takes focus, so Enter activates the row you see highlighted. With the default slot, render your ownrole="menuitem"elements. - Right to left, ArrowLeft and ArrowRight swap, and submenus open to the left.