Skip to main content
cngx-src documentation

CngxSwipe

DirectivePrimaryv0.1.0WCAG AA

projects/common/interactive/gestures/swipe.directive.ts

Import#

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

Description#

Detects directional swipe gestures via Pointer Events and reports the resolved direction.

Generic navigation atom: unlike CngxSwipeDismiss (one fixed direction, dismiss intent), this emits swiped with the dominant direction so a single host can drive bidirectional flows - carousels, paged views, prev/next steppers. The axis input pins the gesture to horizontal or vertical so an orthogonal scroll never fires it. Exposes swiping, swipeProgress, and swipeDirection signals for real-time feedback mid-gesture.

<section cngxSwipe axis="x" (swiped)="onSwipe($event)">…</section>
onSwipe(direction: SwipeDirection): void {
  if (direction === 'left') {
    this.next();
  } else if (direction === 'right') {
    this.previous();
  }
}

https://cngxjs.github.io/cngx/examples/#/ui/stepper/dot-stepper/mobile-carousel

Metadata#

Host#

Relationships

Index#

Inputs#

input()

Axis the gesture is allowed to register on.

default 'both'
enabled#boolean
input()

Whether the directive is active.

default true
threshold#number
input()

Minimum distance in px on the dominant axis to register a swipe.

default 50

Outputs#

output()

Emitted with the dominant direction when a swipe passes the threshold.

Instance Properties#

swipeDirection#unknown
Readonly

Dominant direction of the in-flight gesture, or null when idle.

this.swipeDirectionState.asReadonly()
swipeProgress#unknown
Readonly

Progress of the current swipe from 0 to 1 (clamped).

this.swipeProgressState.asReadonly()
swiping#unknown
Readonly

Whether a swipe gesture is currently in progress.

this.swipingState.asReadonly()

HostBindings#

BindingExpression
[style.touch-action]touchAction()
[style.user-select]swiping() ? 'none' : null
[style.-webkit-user-select]swiping() ? 'none' : null