# longPress

> Generic long-press detection for any host element: a `pointerdown` starts a timer, and once the pointer has held still for a configurable duration, the host dispatches a namespaced `ui:long-press` event carrying the pointer's position, so a consumer can anchor a menu, tooltip, or preview to the exact spot the press held.

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

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

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

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

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `options?` | `LongPress.Options` | Duration configuration; see LongPress.Options. Reset to an empty object when the mixin runtime passes its trailing current-props argument in its place. |

## Examples

```tsx
<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>
```

## Used with it

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

### 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.

#### Signature

```ts
new LongPressEvent(point: AnchorPoint)
```

#### Properties

| Property | Type | Description |
| --- | --- | --- |
| `point` | `readonly AnchorPoint` | Pointer position the press held, in viewport coordinates, ready to pass straight into `@remix-run/ui/anchor`'s point-based anchoring. |

### LongPress.Options

Configuration accepted by longPress.

#### Members

| Member | Type | Description |
| --- | --- | --- |
| `duration?` | `number` | Milliseconds the pointer must remain pressed, without drifting past the movement tolerance, before LongPressEvent fires. Defaults to 500. |
