# ContextMenu
A right-click menu container that wraps a `MenuList`.
## Usage
Wrap a `MenuList`.
```svelte
```
## Anatomy
The `class` attribute values represent part names. Other attributes represent their corresponding props.
```svelte
` via rest props; `class` is merged onto the root.
## Styling
To learn more, see [Styling](/docs/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
| Key | Description |
| --- | --- |
| `Escape` | Closes the open menu |
For item navigation and type-ahead, see [MenuList](/docs/menu-list).
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](/docs/menu-list), including `role="menu"` on the menu body and `role="menuitem"` from `MenuItem`.
## Exports
### Types
```ts
interface ContextMenuProps extends Omit
, "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;
element?: HTMLDivElement; // bindable
styling?: SVSClass;
variant?: SVSVariant; // (VARIANT.NEUTRAL)
// other HTMLAttributes are passed to 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
**Code**
```svelte src=ContextMenuBasic.svelte
Right click HERE
```
### With Interactive Variant
**Code**
```svelte src=ContextMenuPract.svelte
Right click HERE
{#each menu as [text, cmd]}
{/each}
```