sdxc

Type to search, or start from one of these:

[ @sdxc/ui/mixins ]

contextMenu

Opens a ContextMenu's popover surface at the pointer position when its host receives a right-click, anchoring it with @remix-run/ui/anchor's point-based positioning since no markup can anchor a floating surface to a pointer position.

import { contextMenu } from "@sdxc/ui/mixins";

Usage

Opens the popover surface identified by id at the pointer position on a contextmenu event, or the host's bounding box from the keyboard, since a popover="auto" surface already handles its own Escape/outside-click dismissal. A pointer's menu opens on the release of the press that asked for it, so the surface stays up until the next press rather than being dismissed by that same one.

Signature

contextMenu(id: string, options?: AnchorOptions): MixinDescriptor<HTMLElement>

Parameters

ParameterTypeDescription
idstringid of the popover surface to open.
options?AnchorOptionsAnchor placement and offsets forwarded to @remix-run/ui/anchor; placement defaults to "bottom-start". Safe to omit — contextMenu(id) resets the runtime's trailing current-props argument back to an empty options object.

Examples

<div id="row-1" mix={contextMenu("row-1-menu")}>Row 1</div>
<div id="row-1-menu" popover="auto" role="menu">...</div>

Written by Sergio Xalambrí. Follow @sergiodxa for new packages, or sponsor the work.