# ContextMenu (@limerdev/zest) A menu opened by right-clicking (or long-pressing) an area: `` holds a `ContextMenu.Trigger` (the area) and a `ContextMenu.Content` at the pointer. It takes the same items as `DropdownMenu`: `Item` (`variant="error"`, `Shortcut`), `CheckboxItem`, `RadioGroup` with `RadioItem`s, `Group` with `GroupHeading`, `Label`, `Separator` and submenus. Arrow keys move, Enter chooses, Escape closes. - Category: Actions - Import: `import { ContextMenu } from '@limerdev/zest'` - Bits UI: `ContextMenu`, https://bits-ui.com/docs/components/context-menu - Exports: `ContextMenu.Root`, `ContextMenu.Trigger`, `ContextMenu.Content`, `ContextMenu.Portal`, `ContextMenu.Item`, `ContextMenu.CheckboxItem`, `ContextMenu.CheckboxGroup`, `ContextMenu.RadioGroup`, `ContextMenu.RadioItem`, `ContextMenu.Group`, `ContextMenu.GroupHeading`, `ContextMenu.Label`, `ContextMenu.Separator`, `ContextMenu.Shortcut`, `ContextMenu.Sub`, `ContextMenu.SubTrigger`, `ContextMenu.SubContent` - Use for: Shortcuts for actions on the thing under the pointer, such as a row or a file, that are also reachable another way. - Don't: Actions only a right-click reaches: keyboard and touch users may never find them. Offer the same actions in a visible `DropdownMenu` or buttons. ```svelte Right-click this row Open Delete ``` Props of `ContextMenu.Root`: - `dir` (`"ltr" | "rtl"`, default `"ltr"`): The direction of the site. - `onOpenChange` (`OnChangeFn`): A callback that is called when the menu is opened or closed. - `onOpenChangeComplete` (`OnChangeFn`): A callback that is called when the menu is opened or closed. - `open` (`boolean`, default `false`, bindable): The open state of the menu. Props of `ContextMenu.Trigger`: - `disabled` (`boolean`): Whether the context menu trigger is disabled. If disabled, the trigger will not open the menu when right-clicked. Props of `ContextMenu.Content`: - `align` (`"start" | "center" | "end"`): The preferred alignment of the anchor to render against when open. This may change when collisions occur. - `alignOffset` (`number`): An offset in pixels from the "start" or "end" alignment options. - `arrowPadding` (`number`): This describes the padding between the arrow and the edges of the floating element. If your floating element has border-radius, this will prevent it from overflowing the corners. - `avoidCollisions` (`boolean`, default `true`): When `true`, overrides the `side` and `align` options to prevent collisions with the boundary edges. - `collisionBoundary` (`Arrayable`): A boundary element or array of elements to check for collisions against. - `collisionPadding` (`number | Partial>`, default `8`): The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision. - `customAnchor` (`string | HTMLElement | Measurable | null`): Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger. You can pass a selector string or an HTMLElement. - `dir` (`"ltr" | "rtl"`): The text direction of the content. - `escapeKeydownBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Escape behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press. - `forceMount` (`boolean`): Whether to force mount the component. - `hideWhenDetached` (`boolean`) - `interactOutsideBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Interact outside behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to the parent element. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction. - `loop` (`boolean`, default `false`): When `true`, the menu will loop through items when navigating with the keyboard. - `onCloseAutoFocus` (`EventCallback`): Event handler called when auto-focusing on close. Can be prevented. - `onEscapeKeydown` (`((e: KeyboardEvent) => void)`): Callback fired when escape is pressed. - `onFocusOutside` (`((event: FocusEvent) => void)`): Callback fired when focus leaves the dismissible layer. - `onInteractOutside` (`InteractOutsideEventHandler`): Callback fired when an outside interaction event completes, which is either a `pointerup`, `mouseup`, or `touchend` event, depending on the user's input device. - `onOpenAutoFocus` (`EventCallback`): Event handler called when auto-focusing on open. Can be prevented. - `portalProps` (`PortalProps`): Props for the portal the content renders in: `to` (the element to render in, the body by default) and `disabled` (render in place). - `preventOverflowTextSelection` (`boolean`, default `true`): Passing `true` will prevent the overflow of text selection outside the element, provided the element is the top layer. - `preventScroll` (`boolean`, default `true`): Whether to prevent scrolling the body when the content is open. Whether to prevent body scrolling when the content is open. - `side` (`"top" | "right" | "bottom" | "left"`): The preferred side of the anchor to render against when open. Will be reversed when collisions occur. - `sideOffset` (`number`): The distance in pixels from the anchor to the floating element. - `sticky` (`"partial" | "always"`) - `strategy` (`"absolute" | "fixed"`): The positioning strategy to use for the floating element. - `trapFocus` (`boolean`, default `false`): Whether focus is trapped within the focus scope. - `updatePositionStrategy` (`"always" | "optimized"`, default `"optimized"`): "optimized" will only update the position when necessary, while "always" will update the position on each animation frame, which is useful if the floating content is following something like a mouse cursor. Props of `ContextMenu.Portal`: - `disabled` (`boolean`, default `false`): Disable portalling and render the component inline - `to` (`PortalTarget`, default `document.body`): Where to portal the content to. Props of `ContextMenu.Item`: - `closeOnSelect` (`boolean`, default `true`): Whether or not the menu item should close when selected. - `disabled` (`boolean`, default `false`): When `true`, the user will not be able to interact with the menu item. - `inset` (`boolean`): Indent the text to line up with items that show an icon, check or dot. - `onSelect` (`((event: Event) => void)`): A callback fired when the menu item is selected. Prevent default behavior of selection with `event.preventDefault()`. - `textValue` (`string`, default `undefined`): Optional text to use for typeahead filtering. By default, typeahead will use the `.textContent` of the menu item. When the content is more complex, you can provide a string here instead. - `variant` (`"error" | "default"`, default `'default'`): `error` colours the item for deleting. Props of `ContextMenu.CheckboxItem`: - `checked` (`boolean`, default `false`, bindable): The checked state of the checkbox. It can be one of: - `true` for checked - `false` for unchecked - `closeOnSelect` (`boolean`, default `false`): Whether or not the menu item should close when selected. - `disabled` (`boolean`, default `false`): When `true`, the user will not be able to interact with the menu item. - `indeterminate` (`boolean`, default `false`, bindable): Whether the checkbox is in an indeterminate state or not. - `onCheckedChange` (`OnChangeFn`): A callback that is fired when the checked state changes. - `onIndeterminateChange` (`OnChangeFn`): A callback function called when the indeterminate state changes. - `onSelect` (`((event: Event) => void)`): A callback fired when the menu item is selected. Prevent default behavior of selection with `event.preventDefault()`. - `textValue` (`string`, default `undefined`): Optional text to use for typeahead filtering. By default, typeahead will use the `.textContent` of the menu item. When the content is more complex, you can provide a string here instead. - `value` (`string`): The value of the checkbox item when used in a checkbox group. Props of `ContextMenu.CheckboxGroup`: - `onValueChange` (`OnChangeFn`): A callback that is fired when the selected checkbox items change. - `value` (`string[]`, default `[]`, bindable): The values of the selected checkbox items. Supports two-way binding with `bind:value`. Props of `ContextMenu.RadioGroup`: - `onValueChange` (`OnChangeFn`): A callback that is fired when the selected radio item changes. - `value` (`string`, default `''`, bindable): The value of the selected radio item. Supports two-way binding with `bind:value`. Props of `ContextMenu.RadioItem`: - `closeOnSelect` (`boolean`, default `false`): Whether or not the menu item should close when selected. - `disabled` (`boolean`, default `false`): When `true`, the user will not be able to interact with the menu item. - `onSelect` (`((event: Event) => void)`): A callback fired when the menu item is selected. Prevent default behavior of selection with `event.preventDefault()`. - `textValue` (`string`, default `undefined`): Optional text to use for typeahead filtering. By default, typeahead will use the `.textContent` of the menu item. When the content is more complex, you can provide a string here instead. - `value` (`string`, required): The value of the radio item. Props of `ContextMenu.GroupHeading`: - `inset` (`boolean`): Indent the text to line up with items that show an icon, check or dot. Props of `ContextMenu.Label`: - `inset` (`boolean`): Indent the text to line up with items that show an icon, check or dot. Props of `ContextMenu.Sub`: - `onOpenChange` (`OnChangeFn`): A callback that is called when the menu is opened or closed. - `onOpenChangeComplete` (`OnChangeFn`): A callback that is called when the menu finishes opening/closing animations. - `open` (`boolean`, default `false`, bindable): The open state of the menu. Props of `ContextMenu.SubTrigger`: - `disabled` (`boolean`, default `false`): When `true`, the user will not be able to interact with the menu item. - `inset` (`boolean`): Indent the text to line up with items that show an icon, check or dot. - `onSelect` (`((event: Event) => void)`): A callback fired when the menu item is selected. Prevent default behavior of selection with `event.preventDefault()`. - `openDelay` (`number`, default `100`): The amount of time in ms from when the mouse enters the subtrigger until the submenu opens. This is useful for preventing the submenu from opening as a user is moving their mouse through the menu without a true intention to open that submenu. To disable the behavior, set it to `0`. - `textValue` (`string`, default `undefined`): Optional text to use for typeahead filtering. By default, typeahead will use the `.textContent` of the menu item. When the content is more complex, you can provide a string here instead. Props of `ContextMenu.SubContent`: - `align` (`"start" | "center" | "end"`): The preferred alignment of the anchor to render against when open. This may change when collisions occur. - `alignOffset` (`number`): An offset in pixels from the "start" or "end" alignment options. - `arrowPadding` (`number`): This describes the padding between the arrow and the edges of the floating element. If your floating element has border-radius, this will prevent it from overflowing the corners. - `avoidCollisions` (`boolean`, default `true`): When `true`, overrides the `side` and `align` options to prevent collisions with the boundary edges. - `collisionBoundary` (`Arrayable`): A boundary element or array of elements to check for collisions against. - `collisionPadding` (`number | Partial>`, default `8`): The amount in pixels of virtual padding around the viewport edges to check for overflow which will cause a collision. - `customAnchor` (`string | HTMLElement | Measurable | null`): Use an element other than the trigger to anchor the content to. If provided, the content will be anchored to the provided element instead of the trigger. You can pass a selector string or an HTMLElement. - `dir` (`"ltr" | "rtl"`): The text direction of the content. - `escapeKeydownBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Escape behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press. - `forceMount` (`boolean`): Whether to force mount the component. - `hideWhenDetached` (`boolean`) - `interactOutsideBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Interact outside behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to the parent element. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction. - `loop` (`boolean`, default `false`): When `true`, the menu will loop through items when navigating with the keyboard. - `onCloseAutoFocus` (`EventCallback`): Event handler called when auto-focusing on close. Can be prevented. - `onEscapeKeydown` (`((e: KeyboardEvent) => void)`): Callback fired when escape is pressed. - `onFocusOutside` (`((event: FocusEvent) => void)`): Callback fired when focus leaves the dismissible layer. - `onInteractOutside` (`InteractOutsideEventHandler`): Callback fired when an outside interaction event completes, which is either a `pointerup`, `mouseup`, or `touchend` event, depending on the user's input device. - `onOpenAutoFocus` (`EventCallback`): Event handler called when auto-focusing on open. Can be prevented. - `preventOverflowTextSelection` (`boolean`, default `true`): Passing `true` will prevent the overflow of text selection outside the element, provided the element is the top layer. - `side` (`"top" | "right" | "bottom" | "left"`): The preferred side of the anchor to render against when open. Will be reversed when collisions occur. - `sideOffset` (`number`): The distance in pixels from the anchor to the floating element. - `sticky` (`"partial" | "always"`) - `strategy` (`"absolute" | "fixed"`): The positioning strategy to use for the floating element. - `trapFocus` (`boolean`, default `false`): Whether focus is trapped within the focus scope. - `updatePositionStrategy` (`"always" | "optimized"`, default `"optimized"`): "optimized" will only update the position when necessary, while "always" will update the position on each animation frame, which is useful if the floating content is following something like a mouse cursor. Example: A row Right-click (or long-press) the card. Offer the same actions somewhere visible too. ```svelte Right-click order 1042 (last = 'Open')}> Open ↵ (last = 'Duplicate')}>Duplicate Pinned (last = 'Delete')}>Delete

Chose: {last}{pinned ? ', pinned' : ''}

```