Svelte actions are plain functions applied to DOM elements via the use: directive.
They run when the element mounts, set up event listeners or observers, and clean up
automatically on destroy. @rokkit/actions provides actions for keyboard navigation, gestures,
and visual effects.
How actions work
Apply an action with use:actionName or use:actionName={options}.
The action sets up its behavior on mount and tears down on destroy — no lifecycle management
needed:
<div use:someAction={options} onsomeevent={handler}>...</div> navigable — keyboard navigation
The lightweight keyboard navigation action. Add use:navigable to any container and
handle the custom events it dispatches. Events fire on keyup (not keydown). Default
orientation is vertical (ArrowUp/Down = previous/next):
Events dispatched by navigable:
| Event | Vertical (default) | Horizontal |
|---|---|---|
previous | ArrowUp | ArrowLeft |
next | ArrowDown | ArrowRight |
select | Enter, Space | Enter, Space |
collapse | ArrowLeft (nested) | ArrowUp (nested) |
expand | ArrowRight (nested) | ArrowDown (nested) |
Options: orientation ('vertical'|'horizontal'), nested (boolean — enable collapse/expand), enabled (boolean — disable all key handling).
Visual and interaction actions
Additional actions for visual effects and interaction patterns:
All exported actions
| Action | Purpose |
|---|---|
navigable | Lightweight keyboard nav — dispatches previous/next/select/collapse/expand on keyup |
navigator | Full-featured nav paired with a Rokkit controller from @rokkit/states |
keyboard | Bind keyboard shortcuts with a keymap object |
pannable | Pointer drag with pan/panstart/panend events |
swipeable | Touch/pointer swipe detection (swipeleft/swiperight/swipeup/swipedown) |
fillable | Fill container on pointer drag — dispatches fill events with progress value |
dismissable | Dismiss on click-outside or Escape key |
themable | Apply data-style attribute dynamically from the vibe store |
skinnable | Apply data-palette attribute dynamically from the vibe store |
reveal | Scroll-triggered reveal animation via IntersectionObserver |
hoverLift | Lift/depth animation on hover |
magnetic | Cursor-attraction magnetic effect |
ripple | Material-style ripple on click/tap |
delegateKeyboardEvents | Forward keyboard events from a container to a target element |
Related
- @rokkit/states — Controllers that pair with the
navigatoraction - Navigator — How the navigator action and controllers work together