Skip to main content

Drag

Makes its child subtree draggable along X and/or Y, reporting position and drag signals, with animated snap-to-position.

Drag is a visual container: whatever you place inside it can be dragged with the pointer. axis restricts movement ('x' by default, 'y' or 'both'), enabled turns dragging on/off, and useParentBounds (Constrain to parent, default true) keeps the content inside its parent's box. While dragging, positionX/positionY (Drag X/Y) hold the current offset in pixels and deltaX/deltaY the per-move change; onStart (Drag Started), onDrag (Drag Moved) and onStop (Drag Ended) are signals bracketing the gesture. The position can also be driven from the graph: setting inputPositionX/inputPositionY (Start Drag X/Y) moves the content and updates the outputs, and the snapToPositionX.do/snapToPositionY.do signals animate to snapToPositionX.value over snapToPositionX.duration milliseconds (default 300).

When to use it

Sliders, swipeable cards, drawers, reorder handles — any direct-manipulation gesture where you need the live drag offset. For scrolling content use a Group with scrolling enabled instead; for purely programmatic motion use an Animation on a node's Pos X/Y rather than a Drag no one touches.

At a glance

CategoryVisual
Type nameDrag
Available inbrowser
SSR compatibilitysafe
Provided bynoodl-viewer-react

Inputs

Values

NameTypeDefaultDescription
axisEnum (x, y, both)xWhich axes dragging is allowed on
cssClassNameString``Extra CSS class names to put on this element, for styling from a stylesheet you supply
enabledBooleantrueLets the user drag this element; when off it still renders and still responds to the Snap actions
inputPositionXNumberSets the X position the element starts at, before any dragging
inputPositionYNumberSets the Y position the element starts at, before any dragging
mountedBooleantrueRemoves the element from the page entirely when false, unlike Visible which leaves its space behind
scaleNumber1Divides pointer movement before it becomes element movement, so 2 makes the element move half as far as the pointer
snapToPositionX.durationNumber300How long the X snap animation takes, in milliseconds
snapToPositionX.valueNumber0X position the element animates to when Snap To Position X — Do fires. An empty value leaves the current position alone
snapToPositionY.durationNumber300How long the Y snap animation takes, in milliseconds
snapToPositionY.valueNumber0Y position the element animates to when Snap To Position Y — Do fires. An empty value leaves the current position alone
styleCssString/* background-color: red; */Raw CSS declarations applied to this element, overriding the styling ports above
useParentBoundsBooleantrueStops the element being dragged outside its parent's bounds
variantStringName of a saved variant of this node type to apply, replacing the styling set here

Signals

NameTypeDefaultDescription
snapToPositionX.doSignalAnimates the element to Value on the X axis; does nothing if it is already there
snapToPositionY.doSignalAnimates the element to Value on the Y axis; does nothing if it is already there

Outputs

Values

NameTypeDefaultDescription
boundingHeightNumberHeight this element actually ended up with after layout, in pixels
boundingWidthNumberWidth this element actually ended up with after layout, in pixels
childIndexNumberThis element's position among its parent's children, counting from 0
childrenCountNumberHow many child elements are currently mounted inside this one
deltaXNumberHow far the element moved on X since the last Drag Moved
deltaYNumberHow far the element moved on Y since the last Drag Moved
positionXNumberCurrent X position of the element relative to where it started
positionYNumberCurrent Y position of the element relative to where it started
screenPositionXNumberDistance in pixels from the left edge of the window to this element's left edge
screenPositionYNumberDistance in pixels from the top edge of the window to this element's top edge
thisReferenceA reference to this node itself, for ports that take a node rather than a value

Signals

NameTypeDefaultDescription
completedSignalFires after every invocation, whatever the outcome — wire this to carry on regardless. Failure still fires and still carries its reason, so this cannot hide an error
didMountSignalFires once this element has been added to the page and can be measured
doneSignalFires once a snap animation has been started on the element
onDragSignalFires on every frame the element moves while being dragged
onStartSignalFires when the user starts dragging
onStopSignalFires when the user releases the element, including when the pointer leaves the window
willUnmountSignalFires just before this element is removed from the page, while it still exists

Failure outputs

NameTypeDefaultDescription
failureSignalFires when the snap never reached the element, because it has still not mounted

Patterns

  • Snap back: onStopsnapToPositionX.do with snapToPositionX.value 0 — released content animates home.
  • Swipe threshold: positionX → Expression/Condition deciding on onStop whether to snap to the open or closed position.

Watch out for

  • Rebuilding a scroll view out of Drag — a Group with scrolling enabled handles momentum, wheel and touch for free.

Examples

Draggable chip that snaps back on release

Drag is a visual container that makes its children draggable. Its onStop signal fires when the user releases; wiring it to the snapToPositionX.do/snapToPositionY.do signal inputs animates the chip back to the configured snap position (0,0 here) over the given duration. positionX/positionY report the live offset while dragging — here mapped into the label.

Group, Animation, Condition, States

Generated

This page is generated from node-catalog-enriched.json. Do not edit it by hand — run npm run docs:nodes to regenerate, and fix the source enrichment instead.