Overlays
Layout
ContextMenu
A menu that opens at the pointer on right-click, or on a long press on touch screens. Use it for actions on the item under the pointer.
Keyboard users open the menu with Shift+F10 or the Menu key, which fire contextmenu on the focused element. Make the wrapped target focusable (tabindex="0") and give it an accessible name.
Install
import { ContextMenu } from 'vael-ui'Playground
Fruits
Placement, behaviour and animation
bottom
start
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { ContextMenu } from 'vael-ui'
const items = [
{ label: 'Apple', value: 'apple' },
{ label: 'Banana', value: 'banana' },
{ label: 'Cherry', value: 'cherry' },
]
const open = ref(false)
</script>
<template>
<ContextMenu :items="items" v-model:open="open">
<div>Right-click here</div>
</ContextMenu>
</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.
<ContextMenu
: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 pattern from the WAI-ARIA Authoring Practices Guide.
| Key | Action |
|---|---|
| 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, or opens its submenu. |
| 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. |
- It opens on the native
contextmenuevent, and the panel is a Menu with the same roles and keys. - Browsers also fire
contextmenufrom the keyboard on a focused element, so put something focusable inside. To open it from your own button, call the exposedopenAt(x, y). Passaria-labelto name the menu. - Focus moves to the first item on open. On close, it returns to what had it, or to the element you right-clicked.
- Right to left, ArrowLeft and ArrowRight swap, and submenus open to the left.