Skip to main content
cngx-src documentation

CngxLongPress

DirectivePrimaryv0.1.0WCAG AA

projects/common/interactive/gestures/long-press.directive.ts

Import#

import { CngxLongPress } from '@cngx/common/interactive'

Description#

Detects long-press gestures via Pointer Events.

Fires longPressed after the pointer is held down for the threshold duration without moving more than 10px. Cancels on pointer move (prevents accidental triggers during scrolling), pointer up, pointer cancel, and pointer leave.

Exposes longPressing signal for real-time visual feedback while the user holds.

Context menu on long press

<div cngxLongPress (longPressed)="showContextMenu($event)">
  Long press me
</div>

With visual feedback

<div cngxLongPress #lp="cngxLongPress"
     [class.holding]="lp.longPressing()">
  Hold for action
</div>

https://cngxjs.github.io/cngx/examples/#/common/interactive/gestures/long-press/custom-threshold https://cngxjs.github.io/cngx/examples/#/common/interactive/gestures/long-press/long-press-with-visual-feedback

Metadata#

Index#

Inputs#

enabled#boolean
input()

Whether the directive is active.

default true
moveThreshold#number
input()

Maximum pointer movement in px before the gesture is cancelled.

default 10
threshold#number
input()

Time in ms the pointer must be held to trigger.

default 500

Outputs#

longPressed#PointerEvent
output()

Emitted when a long-press gesture completes.

Instance Properties#

longPressing#unknown
Readonly

Whether a long-press gesture is currently building (pointer held, timer running).

this.longPressingState.asReadonly()