Repository navigation
[draggable] Create new Draggable component - #5487
flaviendelangle wants to merge 263 commits into
Conversation
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Bundle size
PerformanceNo regressions in 36 benchmarks · ran 3m 58s · details Check out the code infra dashboard for more information about this PR. |
This comment was marked as resolved.
This comment was marked as resolved.
|
Updated after the follow-up discussion. The final boundaries are implemented in Final decisions
Auto-scroll DXPreviously, 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>
<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 Displacement DX// Before
<Draggable.Root trackDisplacement />
// After
<Draggable.Root>
<Draggable.Displacement />
</Draggable.Root>Full DOM clone DXThe 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 Final production bundle snapshotReact is externalized. Values are parsed / gzip bytes.
Consequences:
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. |
For this one, we decided to have the default preview be a clone of the dragged element. For the two others, I'm refining the DX but we can probably make them opt-in. |
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>
|
@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 |
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>
`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>
…-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>
Documentation
Feature comparison with dnd kit, React Aria, and Pragmatic drag and drop
Summary
Adds unstyled drag-and-drop components and hooks under the
Draggablenamespace, with mouse, touch, and pen support:Draggable.Providersupplies a default kind for simple interactions.Draggable.Rootholds a draggable item's settings and drag handlers, and renders no element.Draggable.Triggerrenders the element the user picks up. AddDraggable.Handleto limit where a drag starts.Draggable.Portal,Draggable.Positioner, andDraggable.Previewrender what follows the pointer. Without them, nothing does: the dragged element stays in place with[data-dragging].Draggable.Targetaccepts drops and exposes target coordinates and snapping helpers.Draggable.CollisionProviderreports which item is under the pointer for sorting. Applications control the order and can update it on drop or while dragging.Draggable.Viewportenables auto-scroll for a container or implements custom scrolling.Draggable.useMonitorobserves drag events,Draggable.useActiveDragreads the active source, andDraggable.useManagerprovides imperative registration and cancellation.Basic usage
Simple interactions need no explicit kind or payload. Sources and targets share their provider's default kind:
For typed data, share a kind between the source and target. Drop handlers infer
source.payloadfromaccept:Use
onBeforeMoveStartandsource.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.Previewwithout children renders the trigger again, as it was when the drag started: the same element, props, and children, without itsid, event handlers, and refs. With children, it renders them instead.Draggable.Positionermoves with the pointer. It takesoffsetandmodifiers, and gets[data-ending-style]and[data-dropped]for drop animations.Draggable.Portalmoves the preview to<body>, or to itscontainer, 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.Viewportor 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