Utilities
SwipeTrap
SwipeTrap traps swipe gestures - touch, mouse or pen - on its content and reports them as start, move, end and trigger events carrying distance, velocity, duration and direction. It locks an axis, triggers by distance or by a flick, filters what it responds to, and lets the arrow keys trigger it as the keyboard's alternative.
Notes
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Trigger
OrientationLock
Threshold & Throttle
Filtering
Keyboard
List
Advanced
bit BlazorUI
Swipe left or right
Left Menu
Right Menu
Cascading parameters
Style & Class
RTL
CSS variables
The public custom properties this component reads off its root, for what no parameter covers.
Every variable is read with a fallback and never declared by the component, so it inherits like any other custom property:
set one on :root (or in a [bit-theme] block) to restyle every instance, on any ancestor to restyle the ones inside it,
or on the Style of one instance to restyle that one alone. Leave a variable unset and the component falls back to the theme token beside it.
BitSwipeTrap CSS variables
| Name | Default value | Description |
|---|---|---|
| --bit-SwipeTrap-cursor | inherit | Pointer cursor over the trap at rest, e.g. grab. |
| --bit-SwipeTrap-swiping-cursor | grabbing | Pointer cursor while a swipe is being trapped. |
| --bit-SwipeTrap-focus-color | --bit-clr-pri-focus | Focus ring color of a trap the keyboard can reach (KeyboardTrigger). |
API
Every parameter, public member, sub-class and enum this component exposes.
BitSwipeTrap parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| ChildContent | RenderFragment? | null | The content of the swipe trap. |
| KeyboardTrigger | bool | false | Lets the arrow keys raise OnTrigger in their own direction while the trap itself has the focus. Makes the trap a tab stop, names the keys in aria-keyshortcuts and honors a Horizontal or Vertical OrientationLock. The event carries zero distances and a PointerType of "keyboard". |
| OnStart | EventCallback<BitSwipeTrapEventArgs> | Raised when a swipe starts on the trap. | |
| OnMove | EventCallback<BitSwipeTrapEventArgs> | Raised while a swipe moves, at most once per Throttle milliseconds. | |
| OnEnd | EventCallback<BitSwipeTrapEventArgs> | Raised when a swipe is released, or canceled (IsCanceled) by the browser, by leaving the trap before it was trapped, or by Escape. | |
| OnTrigger | EventCallback<BitSwipeTrapTriggerArgs> | Raised on the release of a swipe that passed Trigger or was flicked faster than TriggerVelocity, and on an arrow key with KeyboardTrigger. | |
| OrientationLock | BitSwipeOrientation? | null | Locks the trap to one axis. Horizontal and Vertical trap and report only that axis for the whole gesture, leaving the other to the browser (it reads zero); Auto locks to the axis the gesture moves along first. |
| SkipSelector | string? | null | A CSS selector of descendants on which a swipe never starts, such as inputs or nested sliders. |
| Threshold | decimal? | null | The distance in pixels a gesture covers before the trap takes it over; it also decides the axis of a diagonal one. Defaults to 0. |
| Throttle | int? | null | The least time in milliseconds between two OnMove events; the latest move of a window still arrives when it closes. Defaults to 0 (no throttling). |
| TouchOnly | bool | false | Ignores mouse swipes, trapping only touch and pen gestures. |
| Trigger | decimal? | null | How far a swipe travels before its release triggers: a fraction of the trap's size per axis below 1, pixels from 1 up. Defaults to 0.25. |
| TriggerVelocity | decimal? | null | The release velocity in px/ms that triggers a flick short of Trigger. Defaults to 0 (off). |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| Disabled | bool | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitSwipeTrapEventArgs properties
The event arguments of the SwipeTrap events.
| Name | Type | Default value | Description |
|---|---|---|---|
| StartX | decimal | 0 | The horizontal start point of the swipe action in pixels, relative to the viewport. |
| StartY | decimal | 0 | The vertical start point of the swipe action in pixels, relative to the viewport. |
| DiffX | decimal | 0 | The horizontal difference of swipe action in pixels. |
| DiffY | decimal | 0 | The vertical difference of swipe action in pixels. |
| VelocityX | decimal | 0 | The horizontal velocity of the swipe action in pixels per millisecond. |
| VelocityY | decimal | 0 | The vertical velocity of the swipe action in pixels per millisecond. |
| PointerType | string? | null | The type of the pointer that performed the swipe action: "mouse", "touch" or "pen". |
| IsCanceled | bool | false | Whether the swipe was canceled (the browser took it over, it left the trap before being trapped, or Escape was pressed) rather than released. Only meaningful in OnEnd. |
| Duration | decimal | 0 | The elapsed time of the swipe action in milliseconds, measured from the moment it started. |
BitSwipeTrapTriggerArgs properties
The event arguments of the SwipeTrap trigger event.
| Name | Type | Default value | Description |
|---|---|---|---|
| Direction | BitPlacement | The swipe direction in which the action triggered. It is always one of the physical four - Top, Bottom, Left or Right - read off the screen rather than off the reading direction. | |
| DiffX | decimal | 0 | The horizontal difference of swipe action in pixels. |
| DiffY | decimal | 0 | The vertical difference of swipe action in pixels. |
| VelocityX | decimal | 0 | The horizontal velocity of the swipe action in pixels per millisecond. |
| VelocityY | decimal | 0 | The vertical velocity of the swipe action in pixels per millisecond. |
| PointerType | string? | null | The type of the pointer that performed the swipe action: "mouse", "touch" or "pen" - or "keyboard" for an arrow key with KeyboardTrigger. |
| Duration | decimal | 0 | The elapsed time of the swipe action in milliseconds, measured from the moment it started. |
BitSwipeOrientation enum
| Name | Value | Description |
|---|---|---|
| None | 0 | No orientation lock for the swipe trap. |
| Horizontal | 1 | Horizontal orientation lock of trapping the swipe action. |
| Vertical | 2 | Vertical orientation lock of trapping the swipe action. |
| Auto | 3 | Locks the trap to the first orientation the gesture moves along, trapping that axis and zeroing the other. |
BitPlacement enum
| Name | Value | Description |
|---|---|---|
| Top | 0 | The top edge. |
| Bottom | 1 | The bottom edge. |
| Start | 2 | The edge the reading direction starts from - the left in LTR, the right in RTL. On the vertical axis, which does not turn around, it is the top. |
| End | 3 | The edge the reading direction ends at - the right in LTR, the left in RTL. On the vertical axis, which does not turn around, it is the bottom. |
| Left | 4 | The left edge, in both reading directions. |
| Right | 5 | The right edge, in both reading directions. |
| Center | 6 | The middle of the axis, against neither edge. |
| TopAndBottom | 7 | Both edges of the block axis at once. |
| StartAndEnd | 8 | Both edges of the inline axis at once, following the reading direction the way Start and End do. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.