Skip to content

[draggable] Create new Draggable component - #5487

Open
flaviendelangle wants to merge 263 commits into
mui:masterfrom
flaviendelangle:drag-engine
Open

flaviendelangle wants to merge 263 commits into
mui:masterfrom
flaviendelangle:drag-engine

Conversation

@flaviendelangle

@flaviendelangle flaviendelangle commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Documentation
Feature comparison with dnd kit, React Aria, and Pragmatic drag and drop

Summary

Adds unstyled drag-and-drop components and hooks under the Draggable namespace, with mouse, touch, and pen support:

  • Draggable.Provider supplies a default kind for simple interactions.
  • Draggable.Root holds a draggable item's settings and drag handlers, and renders no element. Draggable.Trigger renders the element the user picks up. Add Draggable.Handle to limit where a drag starts.
  • Draggable.Portal, Draggable.Positioner, and Draggable.Preview render what follows the pointer. Without them, nothing does: the dragged element stays in place with [data-dragging].
  • Draggable.Target accepts drops and exposes target coordinates and snapping helpers.
  • Draggable.CollisionProvider reports which item is under the pointer for sorting. Applications control the order and can update it on drop or while dragging.
  • Draggable.Viewport enables auto-scroll for a container or implements custom scrolling.
  • Draggable.useMonitor observes drag events, Draggable.useActiveDrag reads the active source, and Draggable.useManager provides imperative registration and cancellation.

Basic usage

Simple interactions need no explicit kind or payload. Sources and targets share their provider's default kind:

import { Draggable } from '@base-ui/react/draggable';

<Draggable.Provider>
  <Draggable.Root>
    <Draggable.Trigger>Drag me</Draggable.Trigger>
  </Draggable.Root>
  <Draggable.Target onDraggableDrop={() => console.log('Dropped')}>Drop here</Draggable.Target>
</Draggable.Provider>;

For typed data, share a kind between the source and target. Drop handlers infer source.payload from accept:

const card = Draggable.createKind<Card>('card');

<Draggable.Provider>
  <Draggable.Root kind={card} payload={cardData}>
    <Draggable.Trigger>{cardData.title}</Draggable.Trigger>
  </Draggable.Root>
  <Draggable.Target
    accept={card}
    onDraggableDrop={(eventDetails) => move(eventDetails.source.payload.id)}
  >
    Done
  </Draggable.Target>
</Draggable.Provider>;

Use onBeforeMoveStart and source.updateDragData() to store data decided at pickup, such as the items of a multi-selection. Explicit shared kinds also allow interactions across providers; the drag manager remains page-wide.

Drag preview

The preview parts sit next to the trigger:

<Draggable.Root kind={card} payload={cardData}>
  <Draggable.Trigger className="Card">{cardData.title}</Draggable.Trigger>
  <Draggable.Portal>
    <Draggable.Positioner offset="pointer">
      <Draggable.Preview />
    </Draggable.Positioner>
  </Draggable.Portal>
</Draggable.Root>;
  • Draggable.Preview without children renders the trigger again, as it was when the drag started: the same element, props, and children, without its id, event handlers, and refs. With children, it renders them instead.
  • Draggable.Positioner moves with the pointer. It takes offset and modifiers, and gets [data-ending-style] and [data-dropped] for drop animations.
  • Draggable.Portal moves the preview to <body>, or to its container, out of ancestors that clip or transform it. Without it, the positioner renders in place, next to the trigger, where the surrounding CSS still applies.

The preview renders in the root's React tree, so it reads the context around the root and shows state updates during the drag. When the root unmounts mid-drag, as in a virtualized list, a static copy of the preview stays in place until a remounted root renders it again or the drag ends.

Behavior and styling

Activation thresholds, movement modifiers, data attributes, and CSS variables control drag behavior and styling. Auto-scroll is opt-in for each container through Draggable.Viewport or imperative registration, including separate registration for page scrolling.

Dragging is pointer-driven. Applications provide equivalent keyboard and click or tap actions through move menus, buttons, or shortcuts. The documentation includes accessibility guidance and sorting examples with keyboard shortcuts.

🤖 Generated with Claude Code

@flaviendelangle flaviendelangle self-assigned this Aug 13, 2026
@flaviendelangle flaviendelangle added type: new feature Expand the scope of the product to solve a new problem. scope: all components Widespread work has an impact on almost all components. labels Aug 13, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

commit: 48d7b8c

@netlify

netlify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 48d7b8c
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6aea18a880ebececdce3c5e2
😎 Deploy Preview https://deploy-preview-5487--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+69.5KB(+13.42%) 🔺+23.9KB(+14.26%)

Details of bundle changes

Performance

No regressions in 36 benchmarks · ran 3m 58s · details


Check out the code infra dashboard for more information about this PR.

@flaviendelangle

Copy link
Copy Markdown
Member Author

CI follow-up: the repo-wide llms-full.txt generation memory fix has been extracted to #5488. The equivalent patch remains on this branch temporarily so this PR can validate cleanly; it will fall out of the diff once #5488 lands.

@atomiks

This comment was marked as resolved.

@flaviendelangle

flaviendelangle commented Aug 17, 2026 •

Copy link
Copy Markdown
Member Author

Updated after the follow-up discussion. The final boundaries are implemented in 2087d871d and 519c1974b.

Final decisions

  • Displacement remains an explicit, zero-DOM Draggable.Displacement part.
  • The explicit full DOM clone boundary has been reverted. A full clone is the default preview again.
  • Inferred auto-scroll is opt-in through a no-DOM DragAutoScroll.Provider; DragAutoScroll.Root remains the per-region configuration API and is still self-sufficient.

Auto-scroll DX

Previously, opting into inferred auto-scroll meant annotating a scrollable region:

<DragAutoScroll.Root>
  <div className={styles.scroller}>
    <Draggable.Root>...</Draggable.Root>
  </div>
</DragAutoScroll.Root>

Now it can be enabled once for every Base UI drag source on the page:

<DragAutoScroll.Provider>
  <App />
</DragAutoScroll.Provider>

Scrollable ancestors are inferred, so individual elements stay ordinary:

<div className={styles.scroller}>
  <Draggable.Root>...</Draggable.Root>
</div>

DragAutoScroll.Provider renders no DOM and only retains the page-global scroll monitor. Use DragAutoScroll.Root when a region needs configuration or a custom scrolling implementation:

<DragAutoScroll.Provider>
  <DragAutoScroll.Root maxSpeed={150}>
    <SlowScroller />
  </DragAutoScroll.Root>
</DragAutoScroll.Provider>

A root also works without a provider. Multiple providers and roots share a ref-counted monitor, so unmounting or disabling one activation does not interfere with the others. Mounting, unmounting, and toggling disabled during a drag are covered by tests.

Displacement DX

// Before
<Draggable.Root trackDisplacement />

// After
<Draggable.Root>
  <Draggable.Displacement />
</Draggable.Root>

Full DOM clone DX

The temporary explicit API has been removed. The final behavior is again:

// Full clone by default
<Draggable.Root>Card</Draggable.Root>

// Configure or disable it when needed
<Draggable.Root>
  Card
  <Draggable.ClonedPreview offset="pointer" />
</Draggable.Root>

Imperative registrations likewise use the normal dragPreview settings object; there is no Draggable.createClonedPreview helper.

Final production bundle snapshot

React is externalized. Values are parsed / gzip bytes.

Entry Parsed Gzip
Draggable.Root 84,001 B 28,083 B
Draggable.Root + Displacement 87,075 B 29,221 B
DragAutoScroll.Provider 58,623 B 19,854 B
DragAutoScroll.Root 63,926 B 21,683 B
DragAutoScroll.Provider + Root 64,027 B 21,719 B
Draggable.Root + Provider 91,640 B 30,451 B
Draggable.Root + DragAutoScroll.Root 92,371 B 30,626 B

Consequences:

  • Displacement costs 3,074 B parsed / 1,138 B gzip when composed with the final Draggable.Root.
  • The provider leaf is 5,303 B parsed / 1,829 B gzip smaller than the configurable root leaf.
  • Page-wide inferred auto-scroll adds 7,639 B parsed / 2,368 B gzip to Draggable.Root.
  • Choosing the provider instead of a per-region root saves 731 B parsed / 175 B gzip in that composition.
  • Apps importing neither DragAutoScroll.Provider nor DragAutoScroll.Root retain none of the auto-scroll subsystem.
  • Restoring the default full clone adds 3,165 B parsed / 1,036 B gzip to bare Draggable.Root versus the temporary explicit/no-clone snapshot. We accept that cost to preserve the expected zero-configuration preview behavior.

Bundle entries and enforceable budgets cover the bare leaves and composed boundaries. Validation passed: TypeScript, ESLint, Stylelint, Prettier, generated API docs and docs validation, package build, all 17 drag-and-drop bundle budgets, 656 jsdom drag-engine tests, focused provider tests in jsdom and Chromium, and the existing draggable/root suites.

@flaviendelangle

flaviendelangle commented Aug 17, 2026 •

Copy link
Copy Markdown
Member Author

🟠 Make the full-fidelity DOM clone an explicit feature boundary

For this one, we decided to have the default preview be a clone of the dragged element.
I don't think the bundle size cost measured justifies changing this default behavior.

For the two others, I'm refining the DX but we can probably make them opt-in.
Just keep in mind that, for the auto-scroll, any app with a complex-enough dnd use case will have to bundle it anyway. Anyone with a data grid, any one with a scheduler, any one with a tree etc...

flaviendelangle and others added 5 commits August 17, 2026 12:55
Whole-registry baselines and sweeps read up to five layout properties per
tracked element on every commit of a drag, so an unwindowed 5,000-item list
paid ~25,000 synchronous layout reads per sweep, 7-9 times per gesture.
A per-window IntersectionObserver now maintains a visibility flag per
tracked element; baselines and sweeps skip off-viewport elements, whose
motion cannot be seen anyway. An element entering the viewport mid-drag
adopts its current position, so its later moves animate but the arrival
does not. Environments without IntersectionObserver keep the previous
whole-registry behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jjenzz

jjenzz commented Aug 17, 2026

Copy link
Copy Markdown
Member

@flaviendelangle i think i may have found a bug? something to investigate while i review anyway. it seems dropping quickly doesn't always work, i also slow down a bit in one of the attempts here and it still failed:

CleanShot.2026-08-17.at.17.21.53.mp4

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 16, 2026
flaviendelangle and others added 2 commits November 2, 2026 12:16
Records no longer have an imperative `updatePayload` method. `payload` is
read-only and follows the `payload` prop; anything decided at pickup, such
as a multi-selection, belongs in drag data.

- Delete the participant payload store, which only existed to keep
  `updatePayload` overrides across renders and drags. Source and target
  records now read `payload` through their registration and keep the last
  value once it unregisters or changes kind.
- Publish a `payload` prop change to `useActiveDrag` by comparing with the
  published source, so an unrelated render doesn't republish it.
- Keep the Root owner for preview retargeting on the draggable registry.
- Move the calendar experiment's timed-create anchor to drag data, and
  update the docs and generated API reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the drag engine's interactive-element selector import to the
relocated `utils/popups/constants`, applies master's stricter lint rules to
the branch's files, and marks the fake browser's paste focus test as an
expected failure: since mui#5960, a Menu closed through its controlled `open`
prop no longer notifies its Menubar, which then reopens it on focus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 2, 2026
flaviendelangle and others added 24 commits November 2, 2026 13:22
`Draggable.Root` no longer renders an element. It holds the drag settings
and event handlers, and the new `Draggable.Trigger` part renders the
element the user picks up, with the `dragging`, `settling` and `disabled`
state and data attributes. `Draggable.Handle` and `Draggable.Preview` are
unchanged and work anywhere inside the root.

Every test, demo, experiment and docs example now renders a trigger inside
its root. `DraggableRootDataAttributes` is now
`DraggableTriggerDataAttributes`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Puts back the comments the conversion lost between JSX attributes, and the
demo highlight markers around the props they point at, and migrates the
end-to-end fixtures to `Draggable.Trigger`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…error

The utils index lists each part of the API reference, so it needs the new
trigger. The preview data attribute's JSDoc ended a line with "CSS", which
master's new Vale rule rejects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the review rounds:
- A root registers one trigger, so a second `Draggable.Trigger` replaced the
  first registration. It now warns in development, and the docs say to
  render one trigger per root.
- `collisionElement` now describes the trigger's element as the default.

Simplifications:
- `readSourceParameters` replaces the two copies of "the source's latest
  parameters, if it still has the drag's kind" in the record's `payload` and
  the session's handler lookup.
- `refreshDragSource` compares the published payload with `source.payload`
  instead of repeating its checks.
- The collision options no longer duplicate the root's `payload`.
- The calendar experiment stores a timed create's anchor as plain drag data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…view

Nothing follows the pointer by default anymore. A preview is rendered with
three parts next to the trigger, as in Jenna's proposal:

- `Draggable.Portal` moves the preview out of ancestors that clip or
  transform it. It renders a `<div>` in `<body>`, or in its `container`.
- `Draggable.Positioner` is the element the engine moves. It takes the
  `offset` and `modifiers` that `Draggable.Preview` took, and receives
  `[data-ending-style]` and `[data-dropped]` for the drop transition.
- `Draggable.Preview` renders its children, or the trigger again when it
  has none: the same element, props and children, without the trigger's
  `id`, event handlers and render element ref.

The parts render inside the root's React tree, so the preview reads the
context around the root and shows state updates during the drag. When the
root unmounts mid-drag, the engine keeps a copy of the positioner until a
remounted root attaches again or the preview settles. Draggable parts
rendered inside a preview don't register.

This removes the DOM clone pipeline, the off-document render and copy of
custom content, the provider's preview overlay, `Draggable.updatePreview()`
and the `preview` option of `registerSource`. Every demo and experiment that
relied on the default clone now renders the parts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One item per kind of preview, and an inbox to drop them on: no preview, the
trigger rendered again in a portal, custom content with live state, the
trigger rendered again in place, and a table row inside a positioner table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The engine positions a Draggable.Positioner now, not a clone in the top
layer, so the comments about clones and popovers no longer applied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The preview that renders the trigger again:
- Leaves out the `id`, event handlers and refs of the trigger's `render`
  element or function output, and the refs of the elements inside it.
- Accepts a `render` element the server sends as a lazy wrapper.
- Keeps Base UI list items it renders again out of the trigger's list, so a
  copied tab no longer loops on its highlight.
- Gets its size from the engine, in the positioner's own CSS pixels, so a
  scaled or zoomed trigger is no longer enlarged twice.

The positioner follows a new element the preview renders mid-drag, and
measures again when content around the preview changes size.

The copy left when a root unmounts mid-drag keeps its position, scroll
offsets, canvas pixels, select options, `indeterminate` and grouped
disclosures. It moves back into the page, or the shadow root its portal was
in, when an ancestor is removed later.

The drop transitions of four experiments move to the positioner, and the
docs say how to keep the drop time of a preview, and how a registered source
gets a preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rendering a preview added React commits to every drag:

- `Draggable.Portal` resolved its container and its node through state, so
  the preview mounted two commits after the one that starts the drag. It now
  resolves the container while rendering and portals its element directly.
  A container ref set later in the same commit gets one retry.
- `Draggable.Trigger` published its props to a store on every render, and
  every `Draggable.Preview` subscribed to it, so each render of a dragged
  trigger rendered the preview again in a second commit. The trigger now
  keeps its committed props without notifying, and an empty preview reads
  them once per drag: it shows the trigger as it was when the drag started.
  A preview with children no longer reads them at all.

A dragged item with a preview now commits as often as one without, except
for the preview settling after the drop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
React 18 appends px to a numeric scale style, which makes it invalid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The walks and hit-tests now read one index of closed shadow roots, held by
the registrations that live in them, instead of taking a map from each caller.
The zoom, scale and RTL walks and the pickup measurement, which passed no map,
now see through slots of closed shadow roots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each Draggable.Root now reads its drag phase and preview from one store that
the preview module writes, instead of the active source store, the settling
sources store and a scan of the live previews. A remounted root takes the drag
over in one step, and the duplicated root preview tests moved to their parts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A root now joins its collision provider through its own registration, which
reads the payload from the source's registration. A provider or collision
change re-registers only the participant, so the deferral that kept the
source registered during a drag is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The press and the drag are now two phases of one gesture record, which holds
everything the gesture acquires and releases it through one function on every
end path. The two modules no longer import each other, and the gesture-only
helpers moved out of the shared utils.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Removing a drop target now finishes in the registry before the session hears
about it, so the getter stack is a plain stack again. The hover ledger records
which registration got each enter and sends the owed leave there, and the
session no longer takes the target's getter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Remove dead code: the unused strict linear-transform mode, the preview's
  sourceRect, and a stale comment.
- Share one terminal-leaves helper between the drop and recovery paths, and
  pass isLive to the hover ledger once.
- Reuse existing helpers: resolveClassName, resolveStyle, useForcedRerendering,
  addEventListener, NOOP, runAllCleanups, getOrCreate and the composite list
  default context.
- Replace paired flags with single values and drop forwarding wrappers.
- Skip retargeting work when no drag is live, and stop holding the last
  source in the collision provider between drags.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a handler throws, the recovery now releases the sensor before it delivers
the terminal leaves and onMoveEnd, as a cancel and a drop already do, so
onMoveEnd no longer sees a held pointer, locks and preview. Also remove the
checks after the source's onMoveEnd that only a test reset could reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Delete tests that could not fail or replay a stronger test of the same
  contract, and the splitEnd shim that rebuilt the removed source onDrop.
- Make the lifecycle's sensor required; the tests pass a no-op sensor.
- Rewrite the anyKind identity test against createGlobalKind so it can fail.
- Move tests to the part that owns their behavior, and merge data-only
  variants into it.each tables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove comments that restate the code, shorten the ones that explain why,
and fix stale references. Add short comments where the code was unexplained,
and name two magic numbers. Public JSDoc is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
flaviendelangle added a commit to flaviendelangle/mui-x that referenced this pull request Nov 10, 2026
…-drag-engine

Bump the Base UI preview to the latest commit of mui/base-ui#5487 (48d7b8ce0).

Port the master changes to the Base UI drag engine:
- Drag data and drop dates are timestamps, and the day cells compare plain dates.
- The time columns map the pointer through their wall-clock axis on DST days, and an
  overnight event moves without being clamped to its day.
- The timeline rows and the drag auto-scroll read RTL from the inline-start edge, and a
  start in the repeated hour of a fall-back day keeps no hidden remainder.
- The dependencies feature provides the event drop target as a component.
- The new dependency dialog moves through a Draggable handle, like the event dialog.
- Read-only events are valid dependency targets, and the rejections use localeText.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: out-of-date The pull request has merge conflicts and can't be merged. scope: all components Widespread work has an impact on almost all components. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants