Context menu
A menu opened by right-click or the keyboard on a target.
Example
report-q3.pdf (right-click or Shift+F10)
<focsd-context-menu label="File actions"> <div slot="target" tabindex="0" class="focsd-docs-target"> report-q3.pdf (right-click or Shift+F10) </div> <focsd-menu-item value="open">Open</focsd-menu-item> <focsd-menu-item value="download">Download</focsd-menu-item></focsd-context-menu>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-context-menu.js';</script>
<focsd-context-menu label="File actions">…</focsd-context-menu>import { ContextMenu } from '@focsd-dev/react';
export function Example() { return <ContextMenu label="File actions">…</ContextMenu>;}<script setup>import '@focsd-dev/components/focsd-context-menu.js';</script>
<template> <focsd-context-menu label="File actions">…</focsd-context-menu></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-context-menu.js';
// template<focsd-context-menu label="File actions">…</focsd-context-menu><script> import '@focsd-dev/components/focsd-context-menu.js';</script>
<focsd-context-menu label="File actions">…</focsd-context-menu>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label | label | string | — |
open | open | boolean | false |
Methods
| Method | Description |
|---|---|
openMenu(edge) | Open and focus the first or last item. |
closeMenu() | Close the menu. |
Slots
| Slot | Description |
|---|---|
target | The element that opens the menu on right-click or Shift+F10. |
(default) | The focsd-menu-item elements. |
trigger | The button that opens the menu. |
CSS parts
Style the inside of the component with ::part(), for example focsd-context-menu::part(menu).
| Part | Description |
|---|---|
menu | The menu element. |
Accessibility
- Opens at the pointer on right-click or long press, or at the target with Shift+F10 or the ContextMenu key when the target has focus.
- Same menu semantics and keys as
focsd-menu. Always provide another way to reach the same actions.
Keyboard
| Key | Action |
|---|---|
| Shift + F10 / ContextMenu | Open |
| Arrow Up / Down | Move |
| Enter / Space | Choose the item |
| Escape | Close |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.