Skip to content
Focsd homeFocsd homeFocsd
Forms

Context menu

A menu opened by right-click or the keyboard on a target.

  • Tag: focsd-context-menu
  • Pattern: Menu
  • Category: Overlays

Example

report-q3.pdf (right-click or Shift+F10)
Open Download
HTML
<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>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
openopenbooleanfalse

Methods

MethodDescription
openMenu(edge)Open and focus the first or last item.
closeMenu()Close the menu.

Slots

SlotDescription
targetThe element that opens the menu on right-click or Shift+F10.
(default)The focsd-menu-item elements.
triggerThe button that opens the menu.

CSS parts

Style the inside of the component with ::part(), for example focsd-context-menu::part(menu).

PartDescription
menuThe 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

KeyAction
Shift + F10 / ContextMenuOpen
Arrow Up / DownMove
Enter / SpaceChoose the item
EscapeClose