Skip to contents

Draggable

Drag and drop for pointer input, with drop targets, previews, sorting, and auto-scrolling.

Drag me

Card position: 24, 24

Usage guidelines

  • Dragging is pointer-only: Draggable responds only to mouse, touch, and pen input. Anything a user can do by dragging must also work with a keyboard and with clicks or taps that do not require dragging.
  • Build the alternative yourself: For keyboard moves, add shortcuts on the focused item such as Alt+← and Alt+→. Also provide a click or tap alternative, such as a “Move to” menu. Keyboard shortcuts alone don’t meet the WCAG requirement for an alternative to dragging. Have the alternatives call the same function as the drop handler so both paths apply the same rules. After a keyboard move, keep focus on the moved item and announce the result in a live region, as the sortable list demos do. Draggable doesn’t announce moves itself. When a collection component already announces sorting outcomes, use its announcements instead of adding a second live region.
  • Drag handles are not controls: <Draggable.Handle> isn’t focusable and has no keyboard behavior. Mark a decorative icon inside it aria-hidden="true" rather than the handle itself, and give keyboard users another way to start a move.
  • Drags stay within the page: Draggable tracks pointer events rather than the browser’s native drag and drop. It can’t move data between browser windows or receive files from the operating system. See Native file drops.
  • Use it to move items: Reordering lists, moving items between regions, and positioning items on a canvas are good fits. To pick a value from a list, use a component such as Select instead.

Anatomy

Import the component and assemble its parts:

Anatomy

<Draggable.Root> holds a draggable item’s settings and event handlers, and <Draggable.Trigger> inside it is the element the user picks up. Render one trigger per root. <Draggable.Target> is where they drop it. They all need a <Draggable.Provider> above them. The provider and the root render no element of their own.

The remaining parts are optional:

  • <Draggable.Handle> restricts where a drag can start. See Drag handle.
  • <Draggable.Positioner> and <Draggable.Preview> show what follows the pointer, and <Draggable.Portal> moves them out of the page layout. Without them, nothing does. See Drag preview.
  • <Draggable.CollisionProvider> groups items that can be reordered. See Sorting a list.
  • <Draggable.Viewport> marks a scroll container that should auto-scroll during a drag. See Auto-scrolling.

One manager handles every drag on the page, so a <Draggable.Provider> doesn’t isolate its contents from other providers. The provider supplies the default kind for the parts inside it.

Kinds and payloads

A kind identifies a type of draggable item. Create one with Draggable.createKind, pass it to the kind prop of a <Draggable.Root>, and list it in the accept prop of the targets that take it. A target ignores drags of any other kind.

The type argument of createKind sets the type of the item’s payload. The payload is any value you attach to a draggable. Handlers read it as eventDetails.source.payload on the source and on every target and monitor that accepts the kind.

Declaring a kind with a payload

A kind declared with a payload type requires the payload prop. Omit the type argument when the kind alone identifies the item:

A kind without a payload

Base UI compares payloads by identity. Prefer a primitive such as an ID, as above. When the payload has to be an object, memoize it so that unrelated re-renders don’t replace it:

A memoized object payload

Each createKind call returns a new kind, so two calls with the same name don’t match. Declare each kind once, usually at module scope, and share that value between the sources and targets of an interaction. The name is only for debugging.

When you omit both kind and accept, a source and a target match if they’re inside the same <Draggable.Provider>. That’s enough for a single self-contained interaction such as the demo at the top of this page.

Matching several kinds

A target, viewport, or monitor can accept an array of kinds. eventDetails.source.payload is then a union of their payload types. Use a kind’s matches method to narrow it:

Accepting two kinds

Use Draggable.anyKind to accept every drag, for example on a trash zone. Its source.payload is unknown until you narrow it with matches.

Drag events

Drag sources and drop targets call event handlers as a drag progresses. Each handler receives one eventDetails object with the drag source, the target the drag is over, the event reason, the native event, and the drag location. onBeforeMoveStart is the exception. It runs before Base UI looks for a target, so its eventDetails carry the source, the pointer input, and cancel().

Drag source events

<Draggable.Root> fires the handlers below, in this order. onTargetChange and onMove repeat as the pointer moves:

Following a drag from start to end

Commit a successful drop in onMoveEnd. There, eventDetails.target is the target that received the drop. It’s null when the drag was canceled or released elsewhere. eventDetails.canceled is true for a cancel, such as Esc or cancelDrag(), and false for a release. eventDetails.reason gives the specific cause. A source can land on targets of any kind, so eventDetails.target.payload is unknown until you narrow it with the target’s kind:

Committing a drop

Apart from onBeforeMoveStart, every handler’s eventDetails also carry a location history:

  • location.current holds the pointer position for this event and the drop targets under it, innermost first.
  • location.previous is the same information at the previous event. Compare it with location.current to detect what changed.
  • location.initial is where the drag began.
  • location.grabOffset is the pointer’s offset from the source’s top-left corner at pickup.

A drag continues if the source element leaves the DOM, for example when a virtualized list unmounts the dragged row. When the row mounts again with the same payload or previewKey, the drag moves onto the new element. Identify the dragged item by eventDetails.source.payload, not by its element. To stop a drag from code, for example after the dragged record is deleted, call cancelDrag.

To observe every drag on the page rather than one source, use useMonitor.

Drop target events

<Draggable.Target> fires the handlers below. Their eventDetails hold the drag source and the same location history. target means the same as in a source’s handlers: the innermost target under the pointer, which is this target or one nested inside it. currentTarget is the record of the target running the handler, like event.currentTarget in a DOM event:

Reacting to a drag over a target

onDraggableStart fires only if the target is already under the pointer as the drag starts. To observe every drop, whichever target received it, use onMoveEnd on the source or on a monitor and check for the 'drop' reason.

Use onDraggableEnter and onDraggableLeave together to react to a pause over a target. For example, expand a collapsed group after the drag stays over it for 500ms:

Expanding a group on hover

Drop targets

<Draggable.Target> marks where the user can drop an item. Pass the kinds it takes to accept, and handle the drop in onDraggableDrop:

A basic drop target

You can nest targets. The innermost target under the pointer that accepts the drag receives the drop. See Drop target events for the full set of handlers.

Accepting drops

accept filters by kind. For rules that depend on the item being dragged, the target’s current state, or where the pointer is, add canDrop. Base UI calls it every time it looks for a target under the pointer. Return false to skip this target and let an ancestor receive the drop, or 'reject' to block the drop on this target, the targets inside it, and its ancestors:

A column with a capacity

Pass disabled to turn a target off. See Nested drop targets for how these options interact.

Identifying a target

Most targets don’t need extra data. A target rendered for each row or column can use the row or column directly in its handlers:

A target that knows where it is

Pass payload when other code must identify the target, for example a source or monitor handler that reads eventDetails.target. Those handlers read the value as eventDetails.target.payload, and the target’s own handlers as eventDetails.currentTarget.payload:

Identifying the target from its payload

A target can also declare its own kind. A shared handler can then tell target types apart with matches, which also types target.payload:

Telling target types apart

Auto-scrolling

Scroll containers don’t scroll during a drag unless you opt them in. Render <Draggable.Viewport> on each container that should scroll, including nested ones. The board below renders a viewport for each list and slows down the second one.

Drag the card into either list, at the slot you want. Both lists scroll near their edges; the second list scrolls more slowly.

Renew passport
Default
Water the plants
Reply to Alex
Book a dentist
Send the invoice
Plan the sprint
Call the bank
Buy groceries
Clean the desk
Book the flights
Review the draft
Update the budget
Move the standup
Copy the keys
Sort the photos
Reboot the router
Wrap the gift
maxSpeed={150}
Pay the rent
Update resume
Back up the laptop
Read the docs
Fix the bug
Write the tests
Email the team
Order supplies
Write the changelog
Bump the deps
Fix the flaky test
Tag the release
Check the metrics
Onboard the intern
Book the retro
Archive the branch

A viewport scrolls while the pointer is near one of its edges and more content remains in that direction. It scrolls on the axes whose overflow is auto or scroll.

Nesting follows the DOM tree. The innermost viewport scrolls first. An ancestor viewport scrolls on the axes the inner one doesn’t use or has scrolled to the end of. In a horizontal board of vertical columns, the board and each column scroll on their own axis.

Pass disabled to pause a viewport, for example while a list is filtered. Pass accept to scroll only for drags of some kinds. To change the speed, restrict the direction, or scroll something that isn’t a scroll container, see the examples.

Auto-scrolling only for cards

Scrolling the page

The page doesn’t scroll during a drag by default. <Draggable.Viewport> renders its own element, so it can’t stand in for the document. Register document.documentElement through useManager instead, with the same options as the viewport part:

Letting the page scroll vertically

Inner viewports take precedence on the axes they use. overflow: hidden on <html> or <body> stops page scrolling on that axis. This includes the scroll lock of a modal Dialog.

Examples

Drag handle

By default, a press anywhere on the element can start a drag. Render <Draggable.Handle> inside the root to start drags from the handle only. The rest of the item stays interactive. A draggable uses its first handle and ignores any others.

Dragging by a handle
Visitors
2,420Last 7 days
Conversion
3.8%Up 0.4%
Drop widget

Disabling a drag

Pass disabled to <Draggable.Root> to stop users from picking up an item. Clicks and context menus on the element keep working.

A pinned item

When the decision depends on the gesture itself, for example on which handle the user pressed or on a modifier key, use onBeforeMoveStart instead. It fires just before a drag starts. Call eventDetails.cancel() to prevent it:

Canceling a drag as it starts

Storing data during a drag

The source and target records can hold drag data that one handler writes and later handlers read. Declare its type as the second type argument of createKind. Write it with updateDragData and read it as dragData. It starts as undefined on each pickup. Set source data in onBeforeMoveStart so it’s ready when Base UI looks for targets and renders the preview:

Recording the grab position

To show drag data in the preview, read it with useActiveDrag, as in Custom preview. The payload is read-only and always follows the payload prop, so store anything decided at pickup, such as the items of a multi-selection drag, as drag data.

Activation

A pointer press doesn’t start a drag right away. By default:

  • Mouse and pen start a drag after 5px of movement.
  • Touch starts a drag after a 250ms hold with less than 5px of movement. Moving further before that lets the page scroll instead.

Releasing before the threshold keeps the normal click or tap.

Single criterion

One activation object.

Multiple criteria

An array of alternatives. The first match starts the drag.

Start
Target
StatusMove 5px while pressed to activate.

Pass activation to change the thresholds. It takes one activation method for every pointer type, or a map keyed by mouse, touch, and pen. Unlisted pointer types keep their defaults.

Custom thresholds

The available methods are:

  • { type: 'distance', distance } starts the drag after the pointer moves by that many pixels.
  • { type: 'press-hold', delay, tolerance? } starts the drag after the pointer holds still for delay milliseconds. Moving more than tolerance pixels cancels the gesture. tolerance defaults to 5.
  • { type: 'immediate' } starts the drag on pointerdown. Use it for a canvas tile that the user drags by its whole area. Pressing a nested button, link, or input still doesn’t start a drag.
  • { type: 'double-click' } starts the drag on a double-click or double-tap. See Double-click pickup.

Pass an array to allow several methods at once. The first one to complete starts the drag. An empty array disables pickup.

Drag or hold

Set a pointer type to false to turn off pickup for it. Only do this if your app offers another way to do the same thing with that input, such as move buttons that work with touch, or a custom pen gesture.

Disable touch and pen pickup

Double-click pickup

With { type: 'double-click' }, a mouse double-click picks the item up. It then follows the pointer without a held button and drops on the next click. With touch or pen, the second tap of a double-tap picks the item up while the pointer is still down, and releasing drops it. Esc or Tab cancels either gesture.

Combine it with another method to keep drag-to-pick-up as well, or use a per-pointer map to enable it for some pointer types only:

Double-click or drag

Avoid this method on items whose double-click already opens or edits content.

For these pickups, eventDetails.reason in onBeforeMoveStart and onMoveStart is 'double-click' instead of 'pointer'.

Constraining movement

A drag follows the pointer freely by default. Pass modifiers to <Draggable.Root> to keep it on one axis, snap it to a grid, or contain it within an element. Modifiers affect both the preview and the point Base UI uses to find drop targets.

Locking a list to one axis

The built-in modifiers are:

  • restrictToVerticalAxis and restrictToHorizontalAxis lock the drag to one axis.
  • restrictToParentElement keeps the drag inside the source’s parent element.
  • restrictToElement(element) keeps the drag inside any element. It accepts an element, a ref, or a function returning one.
  • restrictToWindowEdges keeps the drag inside the browser viewport.
  • snapToGrid(size) snaps the drag to a grid anchored at the pickup point. Pass a number, or { x, y } for a rectangular grid.

Pass an array to apply several modifiers in order. Each one receives the previous one’s result:

Combining modifiers

In the demo below, restrictToElement keeps each widget inside the dashed frame. The modifier constrains the drop position too, so the slot outside the frame never activates.

Visitors
2,420Last 7 days
Conversion
3.8%Up 0.4%
Drop widget
Outside slotThe drag cannot reach this target.

<Draggable.Positioner> also accepts modifiers. These constrain only the preview and run after the root’s modifiers. The drop position still follows the pointer. Use them when leaving an area should cancel the drag instead of dropping on the nearest target. For example, a data grid can keep the preview inside the grid, while a release outside the grid cancels the drag.

Custom modifiers

A modifier is a function that receives the proposed point and returns the point to use. It also receives the initialPoint where the drag started, the pointer position input before this list of modifiers ran, the source and preview rectangles, the element’s scale, and the modifier keys held during the current event.

Snapping to fixed rows

Points are in client pixels, matching getBoundingClientRect(). On a zoomed or scaled canvas, multiply a canvas distance by scale to convert it to client pixels. The ctrlKey, shiftKey, altKey, and metaKey flags let a modifier react to keys held during the drag.

Drag preview

Nothing follows the pointer by default. The trigger stays in place with [data-dragging], which suits a canvas that draws its own feedback. To show a preview, render <Draggable.Positioner> with a <Draggable.Preview> inside, next to the trigger:

Showing the trigger under the pointer

The positioner moves with the pointer, and the preview is what it shows. Both render only while their item is dragged, and until the preview settles after the drop. They are inert and hidden from assistive technology, and the positioner has pointer-events: none, so the drop targets under the preview still respond.

Without children, <Draggable.Preview> renders the trigger again: the same element, props, and children, as they were when the drag started. Components inside it still update, but the trigger’s props aren’t read again during the drag. It leaves out the trigger’s id and event handlers, and the refs of the trigger and of the elements inside it. It takes the trigger’s size through the --drag-source-width and --drag-source-height CSS variables, and its own props replace the trigger’s. Because it renders the children a second time, component state inside them starts fresh, and DOM state such as input values or scroll positions isn’t copied.

Custom preview

Pass children to <Draggable.Preview> to show something else. They render in a <div>. The dashboard below drags each widget as a compact badge:

A badge instead of the widget
Visitors
2,420Last 7 days
Conversion
3.8%Up 0.4%
Drop widget

The preview is part of the root’s React tree, so it reads the context around the root, and state and prop changes show during the drag. To show drag data, read the drag with useActiveDrag, which renders again when the data changes. It returns null once the drag ends, while the preview may still settle, so keep the last value:

Showing the drop time in the preview

The preview takes the size of its content. To match the trigger instead, use the --drag-source-width and --drag-source-height CSS variables:

Matching the trigger size

Preview position

Use the positioner’s offset prop to position the preview relative to the pointer. Positions refer to the <Draggable.Preview> element, so content the positioner renders around it doesn’t shift it:

Positioning the preview

The positioner also accepts modifiers, which constrain only the preview. See Constraining movement.

Preview placement

<Draggable.Portal> renders the preview at the end of <body>, or in the element passed as container. That keeps it out of ancestors that clip it or transform it, but also out of the styles they provide: inherited fonts and CSS variables, and descendant selectors such as .Column .Card. Pass the classes the preview needs to the portal, which renders a <div>:

Passing theme variables to the preview

Without a portal, the positioner renders in place, next to the trigger, where those styles still apply. It has position: fixed, so keep it out of ancestors with a transform, filter, or contain property, which would position it instead of the viewport.

To preview a table row, render the positioner as a table. A separate table lays out its own columns, so give both tables the same column widths, for example with table-layout: fixed and a shared <colgroup>:

Previewing a table row

A drag continues when the root unmounts, as when a virtualized list scrolls the item away or a live reorder moves it to another list. Base UI then keeps a still copy of the preview until a root with the same payload or previewKey mounts and renders the preview again, or the drag ends.

Drag cursor

During a mouse or pen drag, Base UI sets the cursor to grabbing over the whole document, whatever is under the pointer. Pass a different CSS cursor as dragCursor, or false to manage the cursor yourself. Set the resting cursor in your own styles:

Changing the drag cursor
The resting cursor

Base UI injects the cursor rule as a <style> element. See the CSP guide if your content security policy disallows it.

Styling the source and preview

[data-dragging] is present on the trigger during the drag. [data-drag-preview] is present on the preview. An empty preview keeps the trigger’s classes, so use it to style the preview apart:

Dimming the source

With Tailwind CSS, use the data-[drag-preview]: variant, such as data-[drag-preview]:shadow-md.

Base UI prevents text selection on draggables and disables page scrolling during a drag. Avoid setting touch-action on the draggable or its handle, since it interferes with touch dragging. Set it on a wrapper instead.

Animating a drop

After a release, the positioner and the preview receive [data-ending-style], and Base UI keeps them mounted until the animations that state starts have finished. Add a translate transition to the positioner under [data-ending-style] to move the preview to the trigger’s final position, or back to the trigger after a release outside every target. Without one, the preview ends where it was released, so an ending fade runs there. Keep the transition under [data-ending-style]: during the drag, Base UI moves the positioner on every frame, and a transition would make it trail the pointer.

Settling into place

Both parts also have [data-dropped] after a drop on a target. Use it when a drop creates something rather than moving the source, such as an item dragged from a palette. The source stays where it was, so the preview should fade where it was dropped instead of flying back:

Fading out on a drop, sliding back otherwise

The source receives [data-settling] while the preview settles, so you can show it as an empty placeholder until the preview arrives. In a className or render callback, read state.settling. The source also keeps [data-dragging] until then, which state.dragging || state.settling matches:

Hiding the source until the preview arrives

A drop that moves an item to another list usually mounts a new source element there. Base UI finds it by its payload, so the preview moves onto it when the new element gets the same payload object. When the payload is rebuilt, such as an object that includes the item’s list, pass the same previewKey to both elements. Without a match, the preview ends where it was released.

Drop position within a target

A target record’s getLocalPoint() returns where the pointer is within that target, as a fraction of its size. In a target’s own handlers, read it from eventDetails.currentTarget. Each axis is 0 at the left or top edge and 1 at the right or bottom edge. Use it when a drop means a value rather than the target itself, such as a time within a day column:

A drop that means a time

The value isn’t clamped, so clamp it yourself if your data needs it.

canDrop receives getLocalPoint() and getSnappedLocalPoint() too, so a target can accept a drop on part of its box only. Returning false lets an ancestor receive the drop elsewhere. For example, a folder row can take files over its middle and leave its edges to the list behind it, which reorders:

A folder that accepts files over its middle

When the target represents fixed intervals such as 15-minute slots or weekday columns, declare snap and read getSnappedLocalPoint() instead. It rounds the fraction to the nearest step and clamps it between 0 and 1. snap sets a number of steps per axis, so you don’t need the target’s size in pixels.

Both ends are included, so 96 steps give 97 values. A drop in the lower half of the last slot reports 1, which is the end of the day. Cap the result when 1 isn’t a valid value:

A day column with 15-minute slots

When the user moves an element, the value to commit is usually where the element lands rather than where the pointer is. Pass { anchor: 'source' } to snap the dragged element’s top-left corner instead of the pointer:

Snapping the element rather than the pointer

snap only changes the value this target reports. To snap the preview itself, use the snapToGrid modifier.

Nested drop targets

When targets are nested, the innermost one that accepts the drag receives the drop. Return false from canDrop to skip a target and let an ancestor receive the drop instead. In the demo, the frame accepts only the chart, so a note released over the frame lands on the canvas behind it.

An outer target’s handlers still run while the pointer is over a nested target. Their eventDetails.target is then the nested target, and eventDetails.currentTarget is the outer one.

Chart: palette. Note: palette.

Chart
Note
Canvas
Frame (charts only)
Drop the chart into the frame

Returning false means “skip this target” rather than “block this area”. A target nested inside it can still receive the drop. Return 'reject' when a rule must block the drop everywhere within the target. No target inside it or above it receives the drop, so a release there ends with the 'outside-release' reason. For example, a full column should reject cards even over the cards it already contains. A rejecting target receives [data-rejected] while the drag is over it:

Rejecting drops in a full column

Styling drop targets

Targets expose their state through data attributes:

  • [data-accepting] is present on every target that accepts the current drag, from pickup until the drag ends. Use it to highlight every possible destination as soon as a drag starts.
  • [data-drag-over] is present while the drag is over the target or one of its nested targets.
  • [data-drag-over-innermost] is present only on the innermost target, which is the one that would receive the drop.
  • [data-rejected] is present while canDrop returns 'reject' for the current position.
Highlighting targets

[data-accepting] is based on accept alone. A target can carry it and still refuse the drop when canDrop runs.

Tracking these states re-renders the target as the drag moves. Set trackDragOver={false} on targets that don’t use them, for example when every row of a long list is a target. Their handlers still fire and they still receive drops:

A target without drag-over feedback

Native file drops

Base UI drags carry no dataTransfer, so they can’t exchange data with other windows or applications. To accept files from the desktop, add native onDrop and onDragOver handlers next to onDraggableDrop. One target can handle both kinds of drop:

Accepting files from the desktop

One element with two roles

Use the render prop to give one element two roles. For example, an item that accepts drops from other items:

A source that is also a target

Don’t use this pattern to build a sortable list. <Draggable.CollisionProvider> handles that case, including the dragged item’s own position and which side of an item the pointer is on. See Sorting a list.

The render prop combines the other parts too. A scrollable list that accepts drops can be both a target and a viewport:

A target that is also a viewport

Sorting a list

Use <Draggable.CollisionProvider> to reorder a group of draggables. Pass the same kind to the provider and to each <Draggable.Root> inside it. The provider reports which item is under the pointer, and your handlers decide where to insert the dragged item.

Update the order in onMoveEnd. There, eventDetails.target.payload identifies the item under the pointer, and eventDetails.target.getLocalPoint() tells which half of it the pointer is in. For a vertical list, a y above 0.5 means the bottom half. eventDetails.target is null when the drag was canceled, released outside the group, or released over the dragged item itself.

To show an insertion indicator, compute the position in onCollisionChange and store it in state. Its eventDetails include the previousTarget, so you can skip updates when the position hasn’t changed:

Tracking the insertion position

By default, the provider measures each item’s own element. Pass collisionElement to <Draggable.Root> to measure a wrapper instead, for example a padded row so that the gaps between items count too. An empty list has no item to collide with, so render a <Draggable.Target> for it.

Sorting while dragging

To move items during the drag, update the order in onCollisionChange instead of onMoveEnd. Compare eventDetails.location.current.input with eventDetails.location.previous.input to place the item based on which way the pointer moved.

Save the original order in onMoveStart. In onMoveEnd, restore it when eventDetails.reason isn’t 'drop', which means the user canceled the drag or released it outside any target. A release over the dragged item itself has the 'drop' reason but a null target. Keep the current order in that case.

When items animate into their new positions, pass collisionElement to measure a wrapper that stays still during the animation.

Auto-scroll direction

CSS decides which axes can scroll. With overflow-x: auto and overflow-y: hidden, only horizontal scrolling is possible. To restrict it further, cancel a direction in onDragScroll. Base UI calls the handler once per direction on every scrolling frame.

The handler’s eventDetails also carry the drag source, so the allowed direction can depend on what’s being dragged. A grid can scroll vertically for rows and horizontally for columns:

A direction that depends on the item

Auto-scroll speed

maxSpeed sets the auto-scroll speed reached at the container’s edge, in pixels per second. It defaults to 900. Scrolling speeds up as the pointer gets closer to the edge. Lower maxSpeed for a short list or raise it for a large scroll range:

Slower in a short list

Auto-scroll outside the viewport

overflowMargin lets scrolling continue when the drag moves outside a container, as if the pointer were on the edge. Pass one distance in CSS pixels for every edge, or an object with top, right, bottom, and left to set each edge separately:

Keep scrolling above and below a calendar

The default is 0. With only top and bottom set, the drag must stay between the viewport’s left and right edges to keep scrolling. To include the corners, extend left and right too:

Extend every edge

Custom auto-scrolling

When Base UI can’t scroll an element itself, for example a canvas panned with a CSS transform, use onDragScroll to apply the movement yourself. The element doesn’t need scrollable overflow. Edge zones, acceleration, and nesting work the same as for a scroll container.

Archive
Kickoff
Research

Archived: nothing yet

Render the viewport on the element that clips the canvas, not on the transformed content. In the handler, call cancel() to skip the default scroll, apply the movement, and call consume() to claim that direction so no ancestor viewport scrolls on it:

A canvas that pans itself

eventDetails.x and eventDetails.y are the distances Base UI would have passed to scrollBy() this frame, in pixels. A positive x moves the view right, so the content moves left. Apply them synchronously, through a ref rather than React state, because Base UI looks for drop targets again on the next frame.

The handler runs once per direction, with the other axis set to 0. When the canvas reaches a bound, skip consume() so an ancestor can scroll instead:

A canvas with bounds

Typed wrapper component

The following example shows a typed wrapper around <Draggable.Root> for items of any kind. payload stays required whenever the kind declares one. Give Payload a default of undefined so the wrapper also works without a kind:

A wrapper for items of any kind

API reference

Provider

Groups the drag sources, drop targets, and viewports of an interaction. Required above the Draggable parts and useManager. Doesn’t render its own HTML element.

childrenReact.ReactNode—
Description

The parts of the interaction.

Type

Draggable.Provider.PropsHide

Re-Export of Provider props as DraggableProviderProps

Root

Groups the parts of a draggable item and holds its drag settings and event handlers. Doesn’t render its own HTML element: <Draggable.Trigger> renders the element that the user picks up.

activationUnion—
Description

Determines when a pointer press starts a drag. Accepts one activation method for every pointer type, a map with a method per pointer type, or an array to allow several methods. By default, mouse and pen start after 5px of movement, and touch after a 250ms hold. Set a pointer entry to false to disable pickup for that pointer type, overriding all methods in an array.

collisionbooleantrue
Description

Whether this item belongs to the nearest matching collision provider. With false, other items can’t be dropped on it, and the provider treats its drags like drags that started elsewhere: they reach it once they enter another item.

Type
Default
true
collisionElementfunction—
Description

Returns the element measured for collisions, for example a padded row wrapper so that the gaps between items count too. Receives the trigger’s element, which is the default.

Type
dragCursorstring | false'grabbing'
Description

The CSS cursor shown across the document during a mouse or pen drag. Pass false to manage the cursor yourself.

Type
Default
'grabbing'
kindDraggable.Kind<TPayload, TDragData>—
Name
Description

The kind of this item, created with Draggable.createKind. Defaults to the kind of the nearest <Draggable.Provider>, which carries no payload.

Type
modifiersDraggable.Root.Modifiers—
Description

One or more modifiers that constrain the drag, applied in order. They affect both the preview and the drop position. See Constraining movement.

Type
onBeforeMoveStartfunction—
Description

Event handler called just before a drag starts, once the activation threshold is met. Call eventDetails.cancel() to prevent the drag.

Type
onMovefunction—
Name
Description

Event handler called as the pointer moves or a modifier key changes, at most once per animation frame. Use a drop target’s onDraggableMove for hover feedback.

Type
onMoveEndfunction—
Description

Event handler called once when the drag ends, after a drop, a release outside any target, or a cancellation. eventDetails.target is the target that received the drop, or null. eventDetails.canceled tells a cancel from a release. A drag canceled during pickup fires this handler without a preceding onMoveStart.

Type
onMoveStartfunction—
Description

Event handler called once when the drag starts. The source is measured by then, so it can be restyled safely.

Type
onTargetChangefunction—
Description

Event handler called when the drop targets under the pointer change, including when the drag ends. Cancel-specific cleanup belongs in onMoveEnd, whose eventDetails.canceled flags a cancel.

Type
payloadTPayload—
Description

The data attached to this item, available as source.payload in the event details of every drag handler and in a drop target’s canDrop. Its type comes from kind, and it is required when the kind declares one.

Type
previewKeystring | number—
Description

A stable key that lets the drag and its settling preview find this item again after it remounts, for example when a virtualized list recreates it or a drop moves it to another list. Needed only when the remounted item gets a new payload object.

Type
snapUnion—
Name
Description

Divides this item into equal steps for getSnappedLocalPoint() when another item is dragged over it. Accepts step counts or a function returning them. Doesn’t affect the preview’s position.

Type
disabledbooleanfalse
Description

Whether dragging is disabled. Pointer presses keep their normal behavior. Use onBeforeMoveStart when the decision depends on the gesture.

Type
Default
false
childrenReact.ReactNode—
Type

Draggable.Root.PropsHide

Re-Export of Root props as DraggableRootProps

Draggable.Root.ActivationHide

Draggable.Root.ActivationConfigHide

Draggable.Root.BeforeMoveStartEventDetailsHide

Draggable.Root.BeforeMoveStartEventReasonHide

Draggable.Root.ElementReferenceHide

Draggable.Root.ModifierContextHide

Draggable.Root.ModifiersHide

Draggable.Root.MoveEndEventDetailsHide

Draggable.Root.MoveEndEventReasonHide

Draggable.Root.MoveEventDetailsHide

Draggable.Root.MoveEventReasonHide

Draggable.Root.MoveStartEventDetailsHide

Draggable.Root.MoveStartEventReasonHide

Draggable.Root.RecordHide

Draggable.Root.TargetChangeEventDetailsHide

Draggable.Root.TargetChangeEventReasonHide

Trigger

The element the user picks up and drops on a matching drop target. An empty <Draggable.Preview> renders it again to show it under the pointer. Render one per <Draggable.Root>. Renders a <div> element.

classNamestring | function—
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function—
Name
Description

Style applied to the element, or a function that returns a style object based on the component’s state.

Type
renderReactElement | function—
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-dragging

Present on the source element while it is being dragged, and until its preview has settled after the drop. A preview never carries this attribute, so a [data-dragging] rule that dims or hides the source leaves the preview fully visible.

data-disabled

Present while the draggable is disabled.

data-settling

Present on the source after a deliberate release, on a target or outside every target, until its preview’s ending animation finishes. Use it to keep the source styled as a placeholder until then.

Attribute
Description
data-dragging

Present on the source element while it is being dragged, and until its preview has settled after the drop. A preview never carries this attribute, so a [data-dragging] rule that dims or hides the source leaves the preview fully visible.

data-disabled

Present while the draggable is disabled.

data-settling

Present on the source after a deliberate release, on a target or outside every target, until its preview’s ending animation finishes. Use it to keep the source styled as a placeholder until then.

Draggable.Trigger.PropsHide

Re-Export of Trigger props as DraggableTriggerProps

Draggable.Trigger.StateHide

Handle

The area of a draggable that starts a drag. The rest of the draggable stays interactive. Omit it to make the whole draggable start a drag. Renders a <span> element.

classNamestring | function—
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function—
Name
Description

Style applied to the element, or a function that returns a style object based on the component’s state.

Type
renderReactElement | function—
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-disabled

Present while the handle’s Draggable.Root is disabled.

Attribute
Description
data-disabled

Present while the handle’s Draggable.Root is disabled.

Draggable.Handle.PropsHide

Re-Export of Handle props as DraggableHandleProps

Draggable.Handle.StateHide

Draggable.Handle.ReferenceHide

Portal

A portal element that moves the drag preview to a different part of the DOM, out of ancestors that clip or transform it. By default, the portal element is appended to <body>. Renders only while its item is dragged, and until the preview settles after the drop. Renders a <div> element.

containerUnion—
Description

A parent element to render the portal element into.

Type
classNamestring | function—
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function—
Name
Description

Style applied to the element, or a function that returns a style object based on the component’s state.

Type
renderReactElement | function—
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type

Draggable.Portal.PropsHide

Re-Export of Portal props as DraggablePortalProps

Draggable.Portal.StateHide

Positioner

Moves the drag preview with the pointer. Renders only while its item is dragged, and until the preview settles after the drop. Renders a <div> element.

modifiersDraggable.Root.Modifiers—
Description

One or more modifiers that constrain the preview only. The drop position still follows the pointer. To constrain the drag itself, use modifiers on Draggable.Root. Read when the preview first renders.

Type
offsetDraggable.Positioner.Offset'source'
Name
Description

Where the preview sits relative to the pointer. Positions refer to the Draggable.Preview inside the positioner. Read when the preview first renders.

Default
'source'
classNamestring | function—
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function—
Name
Description

Style applied to the element, or a function that returns a style object based on the component’s state.

Type
renderReactElement | function—
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-dropped

Present while the preview ends after a drop on a target. Absent when it ends after a release outside every target.

data-ending-style

Present while the preview ends after a deliberate release. A translate transition on the positioner then moves it to the source’s final position, or back to the source after a release outside every target. Without one, it ends where it was released. The preview stays mounted until animations started by this state finish.

Attribute
Description
data-dropped

Present while the preview ends after a drop on a target. Absent when it ends after a release outside every target.

data-ending-style

Present while the preview ends after a deliberate release. A translate transition on the positioner then moves it to the source’s final position, or back to the source after a release outside every target. Without one, it ends where it was released. The preview stays mounted until animations started by this state finish.

--drag-source-height

The height of the element the drag was lifted from.

--drag-source-width

The width of the element the drag was lifted from.

CSS Variable
Description
--drag-source-height

The height of the element the drag was lifted from.

--drag-source-width

The width of the element the drag was lifted from.

Draggable.Positioner.PropsHide

Re-Export of Positioner props as DraggablePositionerProps

Draggable.Positioner.StateHide

Draggable.Positioner.OffsetHide

Draggable.Positioner.OffsetParametersHide

Preview

The content that follows the pointer during a drag. Without children, it renders the trigger again: its element, props and children as they were when the drag started, without its id, event handlers, and the refs of its element and children. Render it inside <Draggable.Positioner>. Renders a <div> element, or the trigger’s element when empty.

classNamestring | function—
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function—
Name
Description

Style applied to the element, or a function that returns a style object based on the component’s state.

Type
renderReactElement | function—
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-drag-preview

Always present. An empty preview keeps the trigger’s classes, so use it in CSS to style the preview apart from the trigger.

data-dropped

Present while the preview ends after a drop on a target. Absent when it ends after a release outside every target.

data-ending-style

Present while the preview ends after a deliberate release.

Attribute
Description
data-drag-preview

Always present. An empty preview keeps the trigger’s classes, so use it in CSS to style the preview apart from the trigger.

data-dropped

Present while the preview ends after a drop on a target. Absent when it ends after a release outside every target.

data-ending-style

Present while the preview ends after a deliberate release.

Draggable.Preview.PropsHide

Re-Export of Preview props as DraggablePreviewProps

Draggable.Preview.StateHide

Target

An area where a matching draggable can be dropped. Renders a <div> element.

acceptUnion—
Name
Description

One or more kinds of draggable this target accepts. Defaults to the kind of the nearest <Draggable.Provider>. Pass Draggable.anyKind to accept every drag, with source.payload typed as unknown.

Drags of other kinds ignore this target, but an ancestor target can still accept them.

Type
canDropfunction—
Description

Decides whether the current drag can be dropped on this target. Runs after accept.

Return false to skip this target and let an ancestor receive the drop. Return 'reject' to block the drop on this target, its nested targets, and its ancestors, for example when a column is full. The target then has [data-rejected].

Its argument has getLocalPoint(), so a target can accept the drop on part of its box only.

Type
kindUnion—
Name
Description

The kind of this target, created with Draggable.createKind. Use its matches method to tell target kinds apart in a shared handler, which also types target.payload. This differs from accept, which lists the kinds of draggable this target takes.

Type
onDraggableDropfunction—
Description

Event handler called when the drag is released over this target. Only the innermost target under the pointer receives it, and it never fires on a cancel. Use the source’s or a monitor’s onMoveEnd to observe every drag end.

Type
onDraggableEnterfunction—
Description

Event handler called when the drag moves over this target.

Type
onDraggableLeavefunction—
Description

Event handler called when the drag moves off this target, or ends. eventDetails.reason tells which. Cancel-specific cleanup belongs in the source’s or a monitor’s onMoveEnd, whose eventDetails.canceled flags a cancel.

Type
onDraggableMovefunction—
Description

Event handler called on every animation frame the pointer moves or a modifier key changes while the drag is over this target, starting with the frame it enters. Put hover feedback such as drop indicators here.

Type
onDraggableStartfunction—
Description

Event handler called when a drag starts while this target is already under the pointer. Use a monitor’s onMoveStart to observe drags starting elsewhere.

Type
payloadTTargetPayload—
Description

The data attached to this target, available as eventDetails.currentTarget.payload in its handlers and on its record in location.current.targets.

Type
snapUnion—
Name
Description

Divides the target into equal steps for getSnappedLocalPoint(). For example, { y: 96 } splits a day column into 15-minute slots, whatever its height. Accepts step counts, or a function that returns them for the current drag.

It only changes the value this target reports. Use the snapToGrid modifier to snap the preview itself.

Type
trackDragOverbooleantrue
Description

Whether to track the drag-over state and expose it through data attributes. Disable it on targets that don’t use them to avoid re-rendering as the drag moves.

Type
Default
true
disabledbooleanfalse
Description

Whether the target ignores drags. A disabled target is skipped, so drags fall through to ancestor targets.

Type
Default
false
classNamestring | function—
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function—
Name
Description

Style applied to the element, or a function that returns a style object based on the component’s state.

Type
renderReactElement | function—
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-disabled

Present while the drop target is disabled.

data-accepting

Present while a drag this target accepts is active, regardless of pointer position. Use it to highlight every compatible drop target. Absent when trackDragOver is false.

data-drag-over

Present while a matching drag source is over the target or a nested target. Absent when trackDragOver is false.

data-drag-over-innermost

Present while the target is the innermost one under the pointer. Absent when trackDragOver is false.

data-rejected

Present while canDrop returns 'reject' for the current position. Use it to show feedback, such as a full column. Absent when trackDragOver is false.

Attribute
Description
data-disabled

Present while the drop target is disabled.

data-accepting

Present while a drag this target accepts is active, regardless of pointer position. Use it to highlight every compatible drop target. Absent when trackDragOver is false.

data-drag-over

Present while a matching drag source is over the target or a nested target. Absent when trackDragOver is false.

data-drag-over-innermost

Present while the target is the innermost one under the pointer. Absent when trackDragOver is false.

data-rejected

Present while canDrop returns 'reject' for the current position. Use it to show feedback, such as a full column. Absent when trackDragOver is false.

Draggable.Target.PropsHide

Re-Export of Target props as DraggableTargetProps

Draggable.Target.StateHide

Draggable.Target.DropEventDetailsHide

Draggable.Target.DropEventReasonHide

Draggable.Target.EnterEventDetailsHide

Draggable.Target.EnterEventReasonHide

Draggable.Target.LeaveEventDetailsHide

Draggable.Target.LeaveEventReasonHide

Draggable.Target.LocalPointHide

Draggable.Target.MoveEventDetailsHide

Draggable.Target.MoveEventReasonHide

Draggable.Target.RecordHide

Draggable.Target.ResolutionContextHide

Draggable.Target.SnappedLocalPointOptionsHide

Draggable.Target.SnapStepsHide

Draggable.Target.StartEventDetailsHide

Draggable.Target.StartEventReasonHide

Viewport

A scroll container that scrolls automatically when a drag nears its edges. Each container, including nested ones, needs its own viewport. Renders a <div> element.

acceptUnion—
Name
Description

One or more kinds of draggable that scroll this container. Omit it to scroll for every drag.

Type
maxSpeedUnion900
Description

The scrolling speed reached at the container’s edge, in pixels per second. Accepts a number or a function called on every scrolling frame. 0 stops this container and lets an ancestor viewport scroll instead.

Type
Default
900
onDragScrollfunction—
Description

Event handler called once per direction on every scrolling frame. Call eventDetails.cancel() to prevent scrolling in that direction, or to apply the movement yourself for an element Base UI can’t scroll, such as a panned canvas. After moving, call eventDetails.consume() to keep an ancestor viewport from scrolling on the same axis. Don’t call it at a bound the element can’t move past, so an ancestor can scroll instead.

Type
overflowMarginDraggable.Viewport.OverflowMargin0
Description

How far outside the container a drag can continue auto-scrolling, in CSS pixels. The drag must enter the container first, and enter it again after moving beyond the margin or while the container is disabled. A number applies to every edge. An object sets each physical edge separately. Omitted, negative, and non-finite edge values are treated as 0. Beyond an edge, scrolling runs as if at the very edge, without restarting the speed ramp. Viewports containing the drag position take priority over outside margins. Does not change drop targets, layout, or page scrolling.

Default
0
disabledbooleanfalse
Description

Whether auto-scrolling is disabled. An ancestor viewport can then scroll instead. Changing it during a drag pauses or resumes scrolling. Scrolling from overflowMargin resumes once the drag enters the container again. Use onDragScroll for a decision that depends on the drag.

Type
Default
false
classNamestring | function—
Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type
styleReact.CSSProperties | function—
Name
Description

Style applied to the element, or a function that returns a style object based on the component’s state.

Type
renderReactElement | function—
Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type
data-disabled

Present while auto-scrolling is disabled.

Attribute
Description
data-disabled

Present while auto-scrolling is disabled.

Draggable.Viewport.PropsHide

Re-Export of Viewport props as DraggableViewportProps

Draggable.Viewport.StateHide

Draggable.Viewport.DragScrollDirectionHide

Draggable.Viewport.DragScrollEventDetailsHide

Draggable.Viewport.DragScrollEventReasonHide

Draggable.Viewport.MaxSpeedContextHide

Draggable.Viewport.OverflowMarginHide

CollisionProvider

Groups draggables of the same kind and reports which one is under the pointer, for sorting. Doesn’t render its own HTML element.

canCollidefunction—
Description

Whether the dragged item can be dropped on a given item of this group. Receives the drag source, the pointer input, the item’s payload and element, and getLocalPoint() for where the pointer is within the item. Return false to skip the item, or 'reject' to block the drop.

Type
kind*Draggable.Kind<TPayload, TDragData>—
Name
Description

The kind of the items in this group. Pass the same kind to each <Draggable.Root>.

Type
onCollisionChangefunction—
Description

Event handler called when the item under the pointer changes, including when the pointer leaves the group. eventDetails.target is the item under the pointer, or null when outside the group or over the dragged item. Compare it with eventDetails.previousTarget to skip updates when the insertion position hasn’t changed.

Type
onMoveEndfunction—
Description

Event handler called when a drag that involved this group ends. Use eventDetails.target to apply the final position. It is null when the drag was canceled, released outside the group, or released over the dragged item. eventDetails.canceled tells a cancel from a release.

Type
onMoveStartfunction—
Description

Event handler called when an item of this group starts dragging, or when a drag that started elsewhere first enters the group.

Type
childrenReact.ReactNode—
Type

Draggable.CollisionProvider.PropsHide

Re-Export of CollisionProvider props as DraggableCollisionProviderProps

Draggable.CollisionProvider.CollisionChangeEventDetailsHide

Draggable.CollisionProvider.CollisionChangeEventReasonHide

Draggable.CollisionProvider.MoveEndEventDetailsHide

Draggable.CollisionProvider.MoveEndEventReasonHide

Draggable.CollisionProvider.MoveStartEventDetailsHide

Draggable.CollisionProvider.MoveStartEventReasonHide

createKind

Creates a kind to pass to a draggable’s kind prop and to a target’s accept prop.

Parameters

name*string—
Name
Type

Return value

Draggable.Kind

namestring
Name
Description

The name or global key the kind was created with. A debugging aid only.

Type
idsymbol
Name
Description

The kind’s identity. Unique per createKind call, and shared by createGlobalKind calls with the same key.

Type
matchesmatches
Description

Whether a drag source is of this kind. Narrows its payload type.

Type

createGlobalKind

createKind matches kinds by identity. A target accepts a source only if both use the same kind object, usually a constant they both import. That doesn’t work when the source and the target live in code that doesn’t share modules, such as a plugin loaded at runtime, a micro-frontend, or two copies of the same package on one page. createGlobalKind uses a string key as the identity instead. Two calls with the same key, from anywhere on the page, return kinds that match each other:

The same kind declared in two separate bundles

Keys are shared by the whole page, so a bare name like 'card' could collide with a kind from another library. Prefix keys with your app or package name. Both sides must also agree on the payload type. TypeScript can’t check that across bundles, so a mismatch only shows up at runtime.

Prefer createKind whenever the source and the target can import the same constant.

Parameters

key*string—
Name
Description

A key such as 'myapp/card'.

Type

Return value

Draggable.Kind

namestring
Name
Description

The name or global key the kind was created with. A debugging aid only.

Type
idsymbol
Name
Description

The kind’s identity. Unique per createKind call, and shared by createGlobalKind calls with the same key.

Type
matchesmatches
Description

Whether a drag source is of this kind. Narrows its payload type.

Type

anyKind constant

A kind that matches every drag. Pass it to a target’s accept prop to accept everything. The resulting source.payload is unknown until you narrow it with a specific kind’s matches method.

Accepting every drag

Modifiers

These are the built-in movement modifiers. Pass them to the modifiers prop of <Draggable.Root> or <Draggable.Positioner>. To write your own, type it as Draggable.Root.Modifier, as shown in Custom modifiers.

restrictToVerticalAxis

Locks the drag to the vertical axis.

Parameters

Draggable.Root.ModifierContext

point*Draggable.Position
Name
Description

The point to constrain, in client pixels. On Draggable.Root, it’s the pointer position. On Draggable.Positioner, it’s the preview’s proposed top-left corner.

initialPoint*Draggable.Position
Description

The same point when the drag started. Axis locks and grid snaps anchor to it.

input*Draggable.Position
Name
Description

The pointer position in client pixels. On Draggable.Root, it’s point before any modifier ran. On Draggable.Positioner, it already includes the root’s modifiers, and it’s the pointer, not the preview’s top-left corner.

sourceElement*HTMLElement
Description

The drag source element.

sourceRect*DOMRect
Description

The source element’s bounding rectangle when the drag started.

scale*Draggable.Position
Name
Description

The scale applied to the element by CSS transform or zoom, including its ancestors. { x: 1, y: 1 } when nothing is scaled. Multiply a distance in the element’s own units by this value to convert it to client pixels.

previewRect*DOMRect | null
Description

The preview element’s current bounding rectangle, or null when there is no preview.

Type
previewOffset*Draggable.Position
Description

The offset from the preview’s top-left corner to point. { x: 0, y: 0 } on Draggable.Positioner and when there is no preview.

ctrlKey*boolean
Description

Whether the Control key is held. Pressing or releasing a modifier key reapplies the modifiers on the next frame.

Type
shiftKey*boolean
Description

Whether the Shift key is held.

Type
altKey*boolean
Name
Description

Whether the Alt key is held.

Type
metaKey*boolean
Description

Whether the Meta (Command or Windows) key is held.

Type
ownerWindow*Window
Description

The window of the source’s document.

Type

Return value

Draggable.Position

xnumber
Name
Type
ynumber
Name
Type

restrictToHorizontalAxis

Locks the drag to the horizontal axis.

Parameters

Draggable.Root.ModifierContext

point*Draggable.Position
Name
Description

The point to constrain, in client pixels. On Draggable.Root, it’s the pointer position. On Draggable.Positioner, it’s the preview’s proposed top-left corner.

initialPoint*Draggable.Position
Description

The same point when the drag started. Axis locks and grid snaps anchor to it.

input*Draggable.Position
Name
Description

The pointer position in client pixels. On Draggable.Root, it’s point before any modifier ran. On Draggable.Positioner, it already includes the root’s modifiers, and it’s the pointer, not the preview’s top-left corner.

sourceElement*HTMLElement
Description

The drag source element.

sourceRect*DOMRect
Description

The source element’s bounding rectangle when the drag started.

scale*Draggable.Position
Name
Description

The scale applied to the element by CSS transform or zoom, including its ancestors. { x: 1, y: 1 } when nothing is scaled. Multiply a distance in the element’s own units by this value to convert it to client pixels.

previewRect*DOMRect | null
Description

The preview element’s current bounding rectangle, or null when there is no preview.

Type
previewOffset*Draggable.Position
Description

The offset from the preview’s top-left corner to point. { x: 0, y: 0 } on Draggable.Positioner and when there is no preview.

ctrlKey*boolean
Description

Whether the Control key is held. Pressing or releasing a modifier key reapplies the modifiers on the next frame.

Type
shiftKey*boolean
Description

Whether the Shift key is held.

Type
altKey*boolean
Name
Description

Whether the Alt key is held.

Type
metaKey*boolean
Description

Whether the Meta (Command or Windows) key is held.

Type
ownerWindow*Window
Description

The window of the source’s document.

Type

Return value

Draggable.Position

xnumber
Name
Type
ynumber
Name
Type

restrictToParentElement

Keeps the drag inside the source element’s parent.

Parameters

Draggable.Root.ModifierContext

point*Draggable.Position
Name
Description

The point to constrain, in client pixels. On Draggable.Root, it’s the pointer position. On Draggable.Positioner, it’s the preview’s proposed top-left corner.

initialPoint*Draggable.Position
Description

The same point when the drag started. Axis locks and grid snaps anchor to it.

input*Draggable.Position
Name
Description

The pointer position in client pixels. On Draggable.Root, it’s point before any modifier ran. On Draggable.Positioner, it already includes the root’s modifiers, and it’s the pointer, not the preview’s top-left corner.

sourceElement*HTMLElement
Description

The drag source element.

sourceRect*DOMRect
Description

The source element’s bounding rectangle when the drag started.

scale*Draggable.Position
Name
Description

The scale applied to the element by CSS transform or zoom, including its ancestors. { x: 1, y: 1 } when nothing is scaled. Multiply a distance in the element’s own units by this value to convert it to client pixels.

previewRect*DOMRect | null
Description

The preview element’s current bounding rectangle, or null when there is no preview.

Type
previewOffset*Draggable.Position
Description

The offset from the preview’s top-left corner to point. { x: 0, y: 0 } on Draggable.Positioner and when there is no preview.

ctrlKey*boolean
Description

Whether the Control key is held. Pressing or releasing a modifier key reapplies the modifiers on the next frame.

Type
shiftKey*boolean
Description

Whether the Shift key is held.

Type
altKey*boolean
Name
Description

Whether the Alt key is held.

Type
metaKey*boolean
Description

Whether the Meta (Command or Windows) key is held.

Type
ownerWindow*Window
Description

The window of the source’s document.

Type

Return value

Draggable.Position

xnumber
Name
Type
ynumber
Name
Type

restrictToElement

Keeps the drag inside an element. Accepts the element, a ref to it, or a function returning it. The element is measured on every move, so it can scroll or resize during the drag.

Parameters

element*Draggable.Root.ElementReference—

restrictToWindowEdges

Keeps the drag inside the browser viewport.

Parameters

Draggable.Root.ModifierContext

point*Draggable.Position
Name
Description

The point to constrain, in client pixels. On Draggable.Root, it’s the pointer position. On Draggable.Positioner, it’s the preview’s proposed top-left corner.

initialPoint*Draggable.Position
Description

The same point when the drag started. Axis locks and grid snaps anchor to it.

input*Draggable.Position
Name
Description

The pointer position in client pixels. On Draggable.Root, it’s point before any modifier ran. On Draggable.Positioner, it already includes the root’s modifiers, and it’s the pointer, not the preview’s top-left corner.

sourceElement*HTMLElement
Description

The drag source element.

sourceRect*DOMRect
Description

The source element’s bounding rectangle when the drag started.

scale*Draggable.Position
Name
Description

The scale applied to the element by CSS transform or zoom, including its ancestors. { x: 1, y: 1 } when nothing is scaled. Multiply a distance in the element’s own units by this value to convert it to client pixels.

previewRect*DOMRect | null
Description

The preview element’s current bounding rectangle, or null when there is no preview.

Type
previewOffset*Draggable.Position
Description

The offset from the preview’s top-left corner to point. { x: 0, y: 0 } on Draggable.Positioner and when there is no preview.

ctrlKey*boolean
Description

Whether the Control key is held. Pressing or releasing a modifier key reapplies the modifiers on the next frame.

Type
shiftKey*boolean
Description

Whether the Shift key is held.

Type
altKey*boolean
Name
Description

Whether the Alt key is held.

Type
metaKey*boolean
Description

Whether the Meta (Command or Windows) key is held.

Type
ownerWindow*Window
Description

The window of the source’s document.

Type

Return value

Draggable.Position

xnumber
Name
Type
ynumber
Name
Type

snapToGrid

Snaps the drag to a grid anchored where the drag started. Pass a number for a square grid, or { x, y } for a rectangular one. A step of 0 leaves that axis free.

The step is in the source’s own units, so snapToGrid(20) still snaps to a 20-unit grid on a zoomed canvas.

Parameters

size*Union—
Name
Type

useActiveDrag

Returns the source of the drag in progress, or null when no drag is active. The calling component re-renders when a drag starts or ends, or when the source’s payload or drag data changes. It doesn’t re-render as the pointer moves. It works anywhere on the page, with or without a <Draggable.Provider>.

Pass a kind, or an array of kinds, to observe only those drags and type source.payload. Other drags return null.

Reading the active drag

Parameters

accept*Draggable.Accept<unknown>—
Name
Type

Return value

Draggable.useActiveDrag.ReturnValueHide

useMonitor

Observes drags anywhere on the page without an element or a <Draggable.Provider>. Use it for status indicators, analytics, or handling drops in one place.

Pass accept to filter by kind and infer the type of eventDetails.source.payload. Omit it to observe every drag with an unknown payload.

Reacting to every stage of a drag

Monitors support the same handlers as <Draggable.Root>, except onBeforeMoveStart.

Parameters

parameters*DragParametersWithInferredAccept< UseDraggableMonitorParameters< TPayload | unknown, TDragData | unknown >, Draggable.Accept<unknown> >—
Type

Return value

Draggable.useMonitor.ParametersHide

Draggable.useMonitor.ReturnValueHide

useManager

Returns the page-wide drag manager. Use it to register existing DOM elements as drag sources, drop targets, or scroll containers. The hook requires a <Draggable.Provider> above the calling component.

All managers share the page’s drag session, so cancelDrag() ends the active drag whichever feature started it. Use distinct kinds to keep unrelated features apart.

Getting the manager

registerSource, registerTarget, and registerViewport take an element and a function that returns its options. registerMonitor takes only the options function. Each method returns a cleanup function, so register in an effect and return the cleanup:

Registering from an effect

registerSource

Registers a drag source. kind is required here. It accepts the options of <Draggable.Root> except collision, collisionElement, and snap. It also takes handle to restrict pickup to an element. A registered source shows no preview. To show one, use <Draggable.Root> and <Draggable.Trigger> instead of registerSource, and render the preview parts inside the root.

Registering a source

registerTarget

Registers a drop target. It accepts the options of <Draggable.Target>, except trackDragOver. accept is required here.

Registering a target

registerViewport

Registers a scroll container, with the options of <Draggable.Viewport>. Use it to scroll the page, or for a container rendered by code you don’t control:

A container that appears later

registerMonitor

Registers a monitor with the options of useMonitor:

Registering a monitor

cancelDrag

Ends the drag in progress. onMoveEnd fires with a null target and the 'imperative-action' reason. It does nothing when no drag is active. Use it when a route change, a dialog, or a deleted record invalidates the drag:

Canceling on navigation

refresh

Most changes to an element’s options apply on their own. Call refresh(element) to apply one right away, such as disabling a source or changing a target’s accept during a drag:

Locking a source while it saves

Return value

UseDraggableManagerReturnValue

registerSourcefunction
Description

Registers an element as a drag source, with the options of Draggable.Root. Returns a cleanup function that unregisters it.

Type
registerTargetfunction
Description

Registers an element as a drop target, with the options of Draggable.Target. Returns a cleanup function that unregisters it.

Type
registerViewportfunction
Description

Registers a scroll container, with the options of Draggable.Viewport. Pass document.documentElement to scroll the page. Returns a cleanup function that unregisters it.

Type
registerMonitorfunction
Description

Registers a monitor, with the options of useMonitor. Returns a cleanup function that unregisters it.

Type
cancelDragfunction
Description

Cancels the drag in progress, if any. onMoveEnd fires with a null target and the 'imperative-action' reason.

Type
refreshfunction
Description

Applies a change to an element’s options right away. Most changes don’t need it, because Base UI calls the options function each time it needs a value. Call refresh when one of these changes:

  • A source’s disabled or handle. Otherwise its idle styles, which prevent text selection and the long-press menu on the source or its handle, are updated only on the next press.
  • A source’s payload during its drag, so useActiveDrag() returns the new value.
  • A target’s disabled, accept, or canDrop during a drag. Otherwise a target under a pointer that doesn’t move keeps its hover state, and onDraggableEnter and onDraggableLeave wait for the pointer to move.
  • A viewport’s options during a drag. Otherwise auto-scrolling starts or stops only when the pointer moves.

It updates every source, target, and viewport registered on the element, and does nothing for an element that isn’t registered. Draggable.Root, Draggable.Target, and Draggable.Viewport do this themselves when their props change.

Type

Draggable.useManager.RegisterMonitorParametersHide

Draggable.useManager.RegisterSourceParametersHide

Draggable.useManager.RegisterTargetParametersHide

Draggable.useManager.RegisterViewportParametersHide

Draggable.useManager.ReturnValueHide

Draggable.AcceptHide

Draggable.AcceptedKindHide

Draggable.anyKindHide

Draggable.InputHide

Draggable.KindHide

Draggable.LocationHide

Draggable.LocationHistoryHide

Draggable.PointerTypeHide

Draggable.PositionHide

DraggableHandleDataAttributesHide

DraggableManagerRegisterMonitorParametersHide

DraggableManagerRegisterSourceParametersHide

DraggableManagerRegisterTargetParametersHide

DraggableManagerRegisterViewportParametersHide

DraggablePositionerCssVariablesHide

DraggablePositionerDataAttributesHide

DraggablePreviewDataAttributesHide

DraggableTargetDataAttributesHide

DraggableTriggerDataAttributesHide

DraggableViewportDataAttributesHide

UseActiveDragReturnValueHide

UseDraggableManagerReturnValueHide

UseDraggableMonitorParametersHide