Rokkit 1.0.3

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):

svelte
Highlighting code...

Events dispatched by navigable:

EventVertical (default)Horizontal
previousArrowUpArrowLeft
nextArrowDownArrowRight
selectEnter, SpaceEnter, Space
collapseArrowLeft (nested)ArrowUp (nested)
expandArrowRight (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:

svelte
Highlighting code...

All exported actions

ActionPurpose
navigableLightweight keyboard nav — dispatches previous/next/select/collapse/expand on keyup
navigatorFull-featured nav paired with a Rokkit controller from @rokkit/states
keyboardBind keyboard shortcuts with a keymap object
pannablePointer drag with pan/panstart/panend events
swipeableTouch/pointer swipe detection (swipeleft/swiperight/swipeup/swipedown)
fillableFill container on pointer drag — dispatches fill events with progress value
dismissableDismiss on click-outside or Escape key
themableApply data-style attribute dynamically from the vibe store
skinnableApply data-palette attribute dynamically from the vibe store
revealScroll-triggered reveal animation via IntersectionObserver
hoverLiftLift/depth animation on hover
magneticCursor-attraction magnetic effect
rippleMaterial-style ripple on click/tap
delegateKeyboardEventsForward keyboard events from a container to a target element

Related

  • @rokkit/states — Controllers that pair with the navigator action
  • Navigator — How the navigator action and controllers work together