sdxc

Type to search, or start from one of these:

[ @sdxc/ui/mixins ]

longPress

Generic long-press detection for any host element.

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

Usage

Detects a long press on any host element: a primary-pointer pointerdown starts a timer, tracking only one press at a time, and dispatches LongPressEvent once the pointer holds still for the full duration.

Signature

longPress(options?: LongPress.Options): MixinDescriptor<HTMLElement>

Returns a mixin descriptor for a host element's mix prop.

Parameters

ParameterTypeDescription
options?LongPress.OptionsDuration configuration; see LongPress.Options. Reset to an empty object when the mixin runtime passes its trailing current-props argument in its place.

Examples

<li
	id="row-1"
	mix={[
		longPress(),
		on("ui:long-press", (event) => {
			let menu = document.getElementById("row-1-menu");
			if (!menu) return;
			anchor(menu, event.point);
			menu.showPopover();
		}),
	]}
>
	Row 1
</li>
<div id="row-1-menu" popover="auto" role="menu">...</div>

The events, constants and types its module publishes, each imported from @sdxc/ui/mixins too.

Event

LongPressEvent

Dispatched on a host by longPress once a pointer press has held its position for the configured duration, carrying that position as an AnchorPoint so a consumer can anchor a menu, tooltip, or preview to it.

new LongPressEvent(point: AnchorPoint)
PropertyTypeDescription
pointreadonly AnchorPointPointer position the press held, in viewport coordinates, ready to pass straight into @remix-run/ui/anchor's point-based anchoring.
Interface

LongPress.Options

Configuration accepted by longPress.

MemberTypeDescription
duration?numberMilliseconds the pointer must remain pressed, without drifting past the movement tolerance, before LongPressEvent fires. Defaults to 500.

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