Markdown:
Components

ContextMenu

A right-click menu container that wraps a MenuList.

Right click HERE

Usage

Wrap a MenuList.

Svelte
<ContextMenu {...props}>
  <MenuList {...props} />
</ContextMenu>

Anatomy

The class attribute values represent part names. Other attributes represent their corresponding props.

Svelte
<div class="whole" {...rest} style={positioning}>
  {children}
</div>

Container for a descendant MenuList. ContextMenu provides MenuContainerContext and owns the contextmenu trigger, touch long-press fallback, fixed positioning, visibility, focus restore, Escape dismissal, and outside-click dismissal. Menu semantics, navigation, typeahead, data-mode, and item context live in MenuList.

Props

NameTypeDefaultDescription
childrenSnippet-Usually renders a MenuList; menu semantics and navigation are owned by MenuList
openbooleanfalseBindable open state; observable, not a positioning control
lockbooleanfalsePrevents the current open state from changing
targetHTMLElement-Limits the contextmenu trigger to a specific element; otherwise the document is used
attachAttachment-Svelte attachment on the root menu
elementHTMLDivElement-Bindable root element
stylingSVSClass-Styling override
variantSVSVariantNEUTRALMenu variant

Other HTMLAttributes are passed to <div> via rest props; class is merged onto the root.

Styling

To learn more, see Styling.

Variant Management

No automatic switching.

Default Class Name

svs-context-menu

Behavior

Container for a descendant MenuList. ContextMenu provides MenuContainerContext and owns the contextmenu trigger, touch long-press fallback, fixed positioning, visibility, focus restore, Escape dismissal, and outside-click dismissal. Menu semantics, navigation, typeahead, data-mode, and item context live in MenuList.

When closed, the menu is hidden with visibility rather than unmounted; the children DOM, including the descendant MenuList, is always present in the document.

On touch input, a long press on the trigger opens the menu. Moving the finger past a small threshold before the press completes cancels the long-press open.

Touch targets that should avoid iOS's native selection callout should apply caller CSS such as -webkit-touch-callout: none; user-select: none; to the trigger element.

Accessibility

Keyboard Interactions

KeyDescription
EscapeCloses the open menu

For item navigation and type-ahead, see MenuList.

Opening records the previously focused element. Closing the menu, including by outside click, restores focus to that element when it is still connected.

ARIA Roles and Attributes

The component applies these automatically:

  • ContextMenu does not add menu roles or menu ARIA attributes itself.

Menu semantics come from a descendant MenuList, including role="menu" on the menu body and role="menuitem" from MenuItem.

Exports

Types

TypeScript
interface ContextMenuProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "style"> {
  children?: Snippet<[string]>; // Snippet<[variant]>; usually renders a MenuList
  open?: boolean; // bindable (false); to observe state, not to control
  lock?: boolean; // (false)
  target?: HTMLElement;
  attach?: Attachment<HTMLDivElement>;
  element?: HTMLDivElement; // bindable
  styling?: SVSClass;
  variant?: SVSVariant; // (VARIANT.NEUTRAL)
  // other HTMLAttributes are passed to <div> via ...rest; `class` is merged onto root
  // style is component-owned
}
type ContextMenuReqdProps = never;
type ContextMenuBindProps = "open" | "element";

Others

No additional exports are available.

Examples

The example code uses Tailwind CSS along with SVSClass.

Basic

Right click HERE

With Interactive Variant

Preset for Demo
Enter variant as you like
Right click HERE