Drag and dock
How dragging a tab or a whole tabset resolves to a stack, a directional split, or a dock at the layout's edge. The landing zones, the pipeline, and the gates. Pointer-only.
Two things can be dragged in dashfoo: a single tab, picked up from its button in the strip, and a whole tabset, picked up from the grip in its toolbar or the empty space in its header. Both share the same landing zones, and which outcome fires depends entirely on where the pointer is when you let go:
- At the layout's edge. The drop docks beside everything else, as a sidebar or a bottom panel.
- Over a tab strip. The drop stacks into that tabset. A tab lands at a specific insertion index, with a thin insertion line marking the slot; a tabset merges all of its tabs onto the end of the target strip.
- Over a tabset body. The drop splits the tabset, creating a new region to the left, right, top, or bottom.
This guide explains how the pointer position resolves to one of those outcomes, the pipeline that carries a drag from the internal drag hooks to a committed model change, and the gates that turn each outcome on or off.
The decision lives in @dashfoo/core
(resolveDropIntent,
built on resolveDockTarget)
and the wiring in @dashfoo/react
(the drag adapter).
The drag adapter directory is the only place in the library that touches
@dnd-kit, and a lint guard keeps it that way. It drives the
framework-agnostic @dnd-kit/dom core imperatively (no React bindings).
Everything it touches downstream is pure and unit-tested.
Pointer-only. Drag-docking uses a pointer sensor; there is no keyboard drag. The arrow keys are already bound to roving-tabindex tab navigation, and dnd-kit's keyboard nudge model conflicts with that, so keyboard docking would need its own interaction design. All other chrome (select, close, rename, maximize, overflow) stays fully keyboard-operable.
The two landing zones
Every drop resolves to one DockLocation, the union the reducer understands:
type DockLocation = "center" | "split-left" | "split-right" | "split-top" | "split-bottom";center stacks. split-* splits. The pointer's position inside a tabset's rect
picks which one.
Over a tab strip: stack at an insertion index
When the pointer is inside the element marked data-dashfoo="tabstrip", the
drop is always a stack. The adapter measures the strip once: its rect and the
rect and data-tab-id of every data-dashfoo="tab-item" in it. The pure
resolveDropIntent
drops the dragged tab from that list and finds the first tab item whose
horizontal midpoint sits to the right of the pointer:
const insertionIndex = (tabs: ReadonlyArray<MeasuredTab>, pointerX: number): number => {
const found = tabs.findIndex((tab) => pointerX < tab.rect.x + tab.rect.width / 2);
return found === -1 ? tabs.length : found;
};If the pointer is past every midpoint, the index is the end of the strip. In a right-to-left strip the tabs run from the right, so the comparison flips: the index is the first tab whose midpoint sits to the left of the pointer, and the insertion line sits on the right edge of that tab.
The dragged tab excludes itself from this measurement. Its own slot never counts toward the order, so the index is measured against the tabs it will land among, not the ones currently rendered. The same index is used at commit time; see Why the index needs no adjustment.
The resulting intent carries location: "center", the target tabset id, and the
computed index:
{ index: insertionIndex(landingTabs(subject, strip), point.x), location: "center", targetId: tabset.id }The on-screen feedback is a thin vertical line (dropIndicator, also in
@dashfoo/core) centered on the slot boundary, spanning the strip's height and
clamped so it never leaves the strip. The index and the line read the same
measurement of whole tab items (label plus close button), so the line always
marks the slot the index names, and the "after the last tab" position sits past
the last close button rather than between the label and the close.
For a tabset dragged by its grip, a strip drop still resolves to center, but
the index does not apply: the committed moveTabset appends every tab from the
dragged tabset to the end of the target strip. See
Dragging a whole tabset.
Over a tabset body: split in a direction
Below the strip, the tabset's own rect decides between stacking and splitting.
resolveDockTarget in @dashfoo/core measures the pointer's fractional distance
from each of the four edges. If the pointer is inside the central area, the drop
stacks; if it lands within the outer band (a fixed 22% of the rect), it
splits toward the closest edge:
const BAND_FRACTION = 0.22;
const resolveDockTarget = (pointer: Point, rect: Rect): DockLocation => {
// a zero-size tabset has no meaningful edges; dividing by its width/height
// yields NaN distances that would silently resolve to a bogus split.
if (rect.width <= 0 || rect.height <= 0) {
return "center";
}
const distances = edgeDistances(pointer, rect);
const min = Math.min(distances.left, distances.right, distances.top, distances.bottom);
if (min > BAND_FRACTION) {
return "center";
}
return closestSplit(distances);
};In a corner, the nearer of the two edges wins. "center" stacks at the end of
the tabset; split-${edge} splits toward that edge. The locations name the
model's row order (split-left means first), so in a right-to-left layout,
where a row paints its first child on the right, resolveDropIntent swaps
split-left and split-right: a drop on the screen's left edge still lands on
the left. The result is already a
DockLocation, the same vocabulary zoneRect and dockZonePolygons speak, so
nothing has to convert it.
- center
- split-left
- split-right
- split-top
- split-bottom
A center drop over the body appends rather than inserting at a mid-strip
slot. resolveDropIntent sets index to the count of remaining tabs so the tab
lands last. A tabset without a strip has no tab order to measure, so its stack
drops carry no index and the reducer appends.
The indicator for a split highlights the matching half of the tabset:
split-left paints the left half, split-top the top half, and so on
(zoneRect).
To see or paint the whole partition at once, dockZonePolygons(rect) enumerates
the five hit regions as polygons: the inner center rect and four edge
trapezoids whose seams run diagonally from each rect corner to the matching
inner corner. It shares the band with resolveDockTarget, so a map
painted from the polygons always agrees with the live hit-test. The demo's
Docking page uses it (with useDropIntent) for a drop-zone visualization that
paints every candidate region during a drag.
Dragging a whole tabset
Each tabset renders a grip button in its toolbar (data-dashfoo="tabset-grip",
aria-label="Move tabset"), and the empty space in its header
(data-dashfoo="tabstrip", around the tabs and toolbar controls) works as a
handle too. Dragging either picks up the entire tabset, tabs and all, and
resolves against the same landing zones. A press on a tab drags that tab, and a
press on a toolbar control operates the control, so only the empty space drags
the tabset. The drag-preview chip is labeled with the tabset's active tab name,
plus how many other tabs come along: Canvas (+2).
Whole-tabset dragging is controlled by the draggableTabsets prop on
<DashfooLayout>. It defaults to true; set it to false and the grip is not
rendered and the header does not drag. A tabset can opt out on its own with
enableDrag: false in the model, and a tabset holding a tab with
enableDrag: false can't be dragged whole either, since moving it would move
that tab. The grip is also hidden while the tabset is maximized.
A grip drop commits a moveTabset action (a tab drop commits moveNode). The
reducer treats the two locations differently:
centermerges: every tab from the dragged tabset is appended to the end of the target tabset, and the now-empty source tabset is removed. The insertion index is ignored.split-*moves: the whole tabset is detached and placed beside the target, reusing the parent row when the orientation already matches, otherwise wrapping both in a new row, the sameplaceBesidepath a tab split uses.
Dropping a tabset onto itself is a no-op; resolveDropIntent suppresses the
intent, decided from the drag subject's kind and id, before the machine ever
sees it, and the reducer guards sourceId === targetId independently. The
reducer likewise ignores a moveNode that splits a one-tab tabset off its own
tab, the tab-drag version of the same self-drop.
Internally the grip and the header each register with dnd-kit under an id built
from the document, the kind, the node id and the handle (the JSON of
[documentId, "tabset", tabsetId, "grip" | "header"]), so they never collide
with each other, with a tab, or with another document's nodes; the real tabset
id rides in the draggable's data and becomes the drag subject's id.
Dropping at the layout's edges
Near the edge of the whole layout (within 12px of its root row), a drop docks beside everything else instead of beside one tabset: drop at the left edge for a full-height sidebar, at the bottom for a full-width bottom panel. The dock indicator previews the quarter of the layout the new panel takes. It works for tab drags, tabset drags and outside sources alike.
The intent targets the layout's root row: { location: "split-left", targetId: model.layout.id }.
The reducer reads a root-row target as an edge dock. When the root already runs
in that direction, the new tabset is added at its start or end with a quarter
of the space; otherwise the root's children are wrapped in a new row and the new
tabset placed beside it. The root keeps its id either way, so the layout stays
addressable. A center drop on the root is ignored. Dispatching the same
action yourself docks at the edge too:
store.dispatch({
location: "split-bottom",
sourceId: "logs",
targetId: model.layout.id,
type: "moveNode",
});Edge docking is on by default. Turn it off with edgeDocking={false} on
<DashfooLayout> (or Layout.Root). It also follows global.enableSplitDock,
since an edge drop is a split. Floats have no edges to dock at: a drop over a
float lands in the float. With a single tabset, docking it (or its only tab) at
its own edge would change nothing, so no edge intent resolves.
Dragging in from outside
Both drags above move nodes that already live in the model. External drag sources add a third kind: an element outside the layout (a widget list, a palette) that inserts a new tab when dropped on a tabset.
Wrap the layout and the sources in DashfooDragProvider so they share one drag
manager and one drag lifecycle, and register each source with
useExternalTabSource:
import { createTabId, tab } from "@dashfoo/core";
import { DashfooDragProvider, DashfooLayout, useExternalTabSource } from "@dashfoo/react";
const WidgetCard = ({ component, name }: { component: string; name: string }) => {
const { ref } = useExternalTabSource({
createTab: () => tab(component, name, { id: createTabId() }),
label: name,
});
return <div ref={ref}>{name}</div>;
};
const App = () => (
<DashfooDragProvider>
<WidgetCard component="metrics" name="Metrics" />
<DashfooLayout defaultModel={model} components={registry} />
</DashfooDragProvider>
);An external drag resolves against the same landing zones (stack on a strip or
body, split on an edge), but the drop commits an addNode action carrying the
TabNode that createTab returned, instead of a moveNode. createTab runs
once per drag (at drag start) and must mint a fresh id each call; the result is
validated against the tab schema, and an invalid node warns and cancels the
drag. A drop outside any tabset is a no-op.
The demo's docking page
pairs each draggable card with an "Add" button that calls addTab on the
imperative handle. Pointer drag is the only drag input, so the button is the
keyboard path.
How resolution layers
For a pointer over a tabset, the drag layer measures the tabset once
(measureTabset: its rect, plus its strip's rect and tab items when it has a
strip) and hands that measurement, the drag subject and the pointer to
resolveDropIntent, which runs the checks in a fixed order:
- Layout edge. With
edgesmeasured andsplitDockon, a pointer within the edge band of the layout resolves a split against the layout's root row. This runs first so a tabset can reach the edge from over itself. - No-op filter. A tabset dragged onto itself, or the sole tab of a tabset dropped back onto that same tabset, resolves to no intent at all. The drop changes nothing once empties collapse, so the indicator never appears.
- Tab strip. Inside the strip, return a
centerstack at the insertion index. - Tabset body. Otherwise resolve
center(append) orsplit-*from the tabset rect, or alwayscenterwhensplitDockis off.
const resolveDropIntent = (
subject: DragSubject,
tabset: MeasuredTabset,
point: Point,
options?: DropIntentOptions,
): DropIntent | null => {
const splitDock = options?.splitDock !== false;
const edgeIntent =
splitDock && options?.edges ? resolveEdgeIntent(subject, tabset, point, options.edges) : null;
if (edgeIntent) {
return edgeIntent;
}
if (isSelfDrop(subject, tabset)) {
return null;
}
const { direction, strip } = tabset;
if (strip && pointInRect(point, strip.rect)) {
return {
index: insertionIndex(landingTabs(subject, strip), point.x, direction),
location: "center",
targetId: tabset.id,
};
}
const location = splitDock
? screenSide(resolveDockTarget(point, tabset.rect), direction)
: "center";
if (location === "center" && strip) {
return { index: landingTabs(subject, strip).length, location, targetId: tabset.id };
}
return { location, targetId: tabset.id };
};The dock indicator reads the same measurement through dropIndicator, so the
rule and its feedback cannot drift apart. Both are pure, and the core unit
tests cover each case on rect fixtures.
The pipeline
A drag travels through five stages. The split is deliberate: the @dnd-kit/dom
pointer sensor owns input, dragDockMachine owns the interaction lifecycle and
never touches the document, and the reducer owns the model.
drag hooks → dnd-kit/dom → dragDockMachine → COMMIT → reducer
(tab + grip + (pointer + (OVER / DROP (moveNode | (action
external hit-test) lifecycle) moveTabset | applied)
draggables) addNode)1. The drag hooks mark the sources
Two internal hooks in
drag-hooks.ts
wire the layout's DOM to the drag system. Neither is exported from
@dashfoo/react. They are described here to explain the flow, not as API.
useNodeDraggable(kind, id, { disabled, handle, label })registers a tab button (kind: "tab") or a tabset grip or header (kind: "tabset") as a@dnd-kit/domDraggable, created imperatively in an effect. Its dnd-kit id is the JSON of[documentId, kind, id, handle], and its data carries the model id, the kind and the owning document.label(the tab's name, or the tabset's active tab name and extra tab count) rides along as the drag-preview label.useTabsetDroppableregisters each tabset as a@dnd-kit/domDroppablewith a custom occlusion-aware collision detector: the winner is the tabset containing the topmost element under the pointer (elementFromPoint), so a tabset covered by a float never becomes a target. dnd-kit's built-in detectors are pure rect geometry and stay unused: they know nothing about paint order.
The public drag hooks sit on the same drag root: useExternalTabSource
registers an outside element as a source (see
Dragging in from outside), and useDragSubject and
useDropIntent read the live drag (see
Rendering your own indicator).
2. The adapter reads the pointer and hit-tests
The drag root constructs one @dnd-kit/dom DragDropManager (minus the
Accessibility plugin and the keyboard sensor), starts one dragDockMachine
actor, and subscribes to the manager's monitor once for the whole tree. Every
Layout.Root mounts the root, so the main tree and its floats share it with no
extra wiring; a root inside another (a layout under DashfooDragProvider, or a
layout nested in a tab) reuses the outer one. On
dragstart it reads the source's data to decide the subject kind (a grip
carries type: "tabset", an external source carries type: "external", a tab
carries its model id and document identity) and sends START.
Each Layout.Root owns one stable documentId, inherited by its main and float
layers. Internal draggable registrations include that identity and the source
kind, so sibling and nested documents may reuse local node IDs safely. A layer
rejects foreign internal subjects; external factories remain importable.
On dragmove and on every collision
pulse it takes the drop target dnd-kit's collision pass resolved, looks up the
layer that registered it, asks that layer to resolve an intent for the
machine's current subject, and sends OVER. On dragend it re-resolves from the final operation state, sends a last
OVER, then DROP.
Each Layout.DragLayer is one such layer: the main tree, plus one per float.
A layer registers only how its own tabsets turn a pointer into an intent and
where a committed action goes, keyed by a layer id that also namespaces its
droppable registrations. It holds no drag state, so a pointer move costs one
intent resolution rather than one per mounted layer. The root sends the
machine an OVER only when the resolved drop differs from the current one, so
a pointer move that lands on the same slot re-renders nothing; only the
indicator, and the hooks that read the drop, update when the target changes. A Layout.DragLayer
needs a Layout.Root above it; without one it warns and renders its children
without drag.
The data-dashfoo="drag-preview" chip is positioned by dnd-kit's Feedback
plugin in overlay mode: the chip element is handed to Feedback's overlay
accessor once at mount, so the dragged tab itself is never promoted or
placeholder-cloned and per-move positioning never re-renders React. The drop
animation is disabled: drops settle immediately.
The final recompute means the drop uses the authoritative final pointer, not
whatever the last dragmove happened to report, so the committed location
matches where the user released.
3. dragDockMachine runs the lifecycle
The XState machine, exported from @dashfoo/core/internal, has two states,
idle and dragging, and its context is one DragState rather than a pair of
independent nullables:
type DragState =
{ kind: "idle" } | { drop: DropResolution | null; kind: "dragging"; subject: DragSubject };START stashes the subject (its kind is "tab", "tabset", or "external",
the last carrying the TabNode to insert) and enters dragging. Each OVER
assigns the live DropResolution ({ indicator, intent, scope }, where scope
names the layer that resolved it and indicator comes from the same tabset
measurement as intent; the root's single dock indicator renders it as given). A drop target with no
subject is not expressible, so "is this drop valid" and "what does it do" are one
total function:
const resolved: { action: Action; scope: string; subject: DragSubject } | null = dropAction(drag);The DROP guard is dropAction(context.drag) !== null, and the emitted
COMMIT carries the same result, so the guard and the action cannot disagree.
CANCEL (or a canceled drop) returns to idle and clears the context. The
machine never mutates the model; it only emits the action.
4. COMMIT forwards the action
The provider subscribes to the machine's COMMIT emission and forwards the
action (moveNode for a tab drag, moveTabset for a grip drag, addNode for
an external source) to the layer named by the emission's scope, which
dispatches it through the Layout.Root above that layer. Both intent resolution
and commit read the current docking permission (editable && restructurable)
and check the original subject's document identity. A layout that becomes
compact during a gesture therefore rejects the pending drop, including an
external widget. enableSplitDock: false still allows center docking.
DashfooLayout wires that straight to store.dispatch.
5. The reducer applies the move
The reducer deep-copies the model (structuredClone, so the input is never
mutated), then applies the action. For moveNode it removes the source tab
from wherever it lives and re-inserts it at the drop target: center stacks
into the target tabset at index; split-* creates a new tabset beside the
target (reusing the parent row when the orientation already matches, otherwise
wrapping both in a new row). For moveTabset it merges (center) or detaches
and re-places the whole tabset (split-*), as described in
Dragging a whole tabset. After the action,
self-healing invariants run (normalize) so the result is always a valid,
canonical model.
Why the index needs no adjustment
moveNode removes the source tab before attaching it:
const tab = removeTab(draft, sourceId);
return tab && attachTab(target, tab, location, index);Because the drag adapter already excluded the dragged tab when measuring the
insertion index, action.index indexes the post-removal array directly. No
off-by-one correction is needed when a tab moves within its own strip.
Gates
These flags decide what a drag can do. Some are global, some per tab, some are layout props.
| Gate | Scope | Where it lives | Default | Effect when off |
|---|---|---|---|---|
editable | whole layout | <DashfooLayout> prop | on | No drags start, and the layout is not a drop target (see below). |
enableSplitDock | global | global.enableSplitDock | on | A drop over a tabset body stacks instead of splitting. |
draggableTabs | whole layout | <DashfooLayout> prop | on | No tab can be picked up; tab.enableDrag becomes moot. |
tabEnableDrag | global | global.tabEnableDrag | on | Tree-wide default behind tab.enableDrag. |
enableDrag | per tab | tab.enableDrag | on | That tab can't be picked up at all. |
draggableTabsets | whole layout | <DashfooLayout> prop | on | No grip is rendered; tabsets can't be dragged whole. |
enableDrag | per tabset | tabset.enableDrag | on | That tabset can't be dragged whole; its tabs still can. |
edgeDocking | whole layout | <DashfooLayout> prop | on | Drops at the layout's edge split the tabset under the pointer. |
dragGroup | whole layout | <DashfooLayout> prop | off | Drops from other layouts are refused. See multiple windows. |
The editable gate
editable={false} makes the layout static. On the source side every internal
draggable is disabled, so no drag can start from it. On the target side the
adapter gates at drag time: the layer resolves no intent for a non-editable
layout (no dock indicator and no drop target) and the COMMIT subscription
drops the action, so even a drag that started before editable flipped off, or
an external-source drag arriving through a shared DashfooDragProvider, cannot
land a structural change. A sibling editable layout under the same provider
still accepts those drags.
Global gate
Layout.Root reads the global flag into the layout store, and each drag layer
passes it to resolveDropIntent as splitDock. It defaults to enabled. The
check is !== false, so an absent flag means on:
const splitDock = model.global.enableSplitDock !== false;When enableSplitDock is off, resolveDropIntent resolves every body drop to a
center stack, so a drop over the body lands as a tab.
Per-tab gate
A tab opts out of dragging by setting enableDrag: false in the model. The tab
button folds that, and the layout's draggableTabs, into the internal
useNodeDraggable hook's disabled argument, with the tab's name as the chip
label:
const { ref } = useNodeDraggable("tab", tab.id, {
disabled: !draggableTabs || tab.enableDrag === false,
label: tab.name,
});The hook returns only a ref. Dragging state is not part of its return value:
the views derive it from the machine's subject (through an internal selector
that matches the subject's kind, id and document against the tab's), which
drives the data-dragging attribute on the source tab's
data-dashfoo="tab-item" wrapper while the overlay chip follows the pointer.
A disabled tab is rendered like any other but can't be picked up, so it can
never become the source of a moveNode.
Tabset grip gate
draggableTabsets is a <DashfooLayout> prop, default true. When false,
the grip button never renders and the header does not drag, so moveTabset
can never originate from a drag. The same happens for one tabset with
enableDrag: false, or holding a tab with enableDrag: false. The grip also
disappears while its tabset is maximized, since a maximized tabset has nowhere
to dock.
Styling the indicator
The drop indicator carries data-dashfoo="dock-indicator". It is one element
for the whole drag, rendered by the drag root rather than inside a tabset, so a
transition slides it from one tabset to the next. Off every target it stays
where it last was with data-idle (and opacity: 0), so it fades instead of
vanishing, and it unmounts when the drag ends. Following the headless contract,
the adapter sets only its geometry, as the custom properties
--dashfoo-dock-left, --dashfoo-dock-top, --dashfoo-dock-width and
--dashfoo-dock-height that @dashfoo/react/styles.css reads. Its z-index is
in styles.css too: auto, beneath floats, and 2 with data-floating when
the target is inside a float. Every visual property is
an overridable CSS custom property with a neutral fallback:
| Variable | Default | Applies to |
|---|---|---|
--dashfoo-dock-fill | oklch(0.556 0 0 / 0.18) | insertion line + split band |
--dashfoo-dock-border | oklch(0.708 0 0 / 0.75) | insertion line + split band |
--dashfoo-dock-border-width | 1px | insertion line + split band |
--dashfoo-dock-radius | 6px | split band |
--dashfoo-dock-line-radius | 2px | insertion line |
--dashfoo-dock-transition | left 60ms, top 60ms, width 60ms, height 60ms, opacity 60ms | every form |
--dashfoo-dock-transition controls how the indicator glides between
positions and fades while idle; set it to none to disable the movement, for example under
prefers-reduced-motion. Override these variables on your theme's
[data-dashfoo="dock-indicator"] rule to control the look. The
theming guide has worked recipes.
Rendering your own indicator
When CSS variables aren't enough, the drag is fully observable from the
outside. useDropIntent() returns the live drop intent: { targetId, location, index? }, or null when nothing is dragging or the pointer is over
no valid target. useDragSubject() returns what is being dragged. Both read the
provider's drag actor, so they work anywhere under a layout or anywhere under a
DashfooDragProvider, including a custom overlay mounted beside the layout
rather than inside it. Outside a provider they return null. Combine them with dockZonePolygons from @dashfoo/core
(the exact hit-region partition resolveDockTarget uses) and the
data-dashfoo="tabset" / "tabstrip" / "tab" markup to paint anything from
a custom highlight to a full drop-zone map. The demo's Docking page renders a
voronoi-style visualization of every candidate region this way.
To draw exactly what the built-in indicator draws, read it: useDropIndicator()
returns the { kind: "edge" | "insertion" | "zone"; rect } the drop was resolved
with, in viewport pixels, or null. It comes from the same tabset measurement as the
intent, so it never disagrees with where the drop lands.
import { useDropIndicator } from "@dashfoo/react";
const indicator = useDropIndicator();For a full zone map like the demo's, measure every tabset the way the library
does. measureTabset(id, element) from @dashfoo/react returns the same
MeasuredTabset the drag layer passes to resolveDropIntent and
dropIndicator, and every tabset root carries data-tabset-id.
See also
resolveDockTargetin@dashfoo/corefor the band math.drop-intent.tsin@dashfoo/corefor the no-op drop filter, the insertion index, thesplitDockoverride, and the insertion line.- The drag adapter
in
@dashfoo/reactfor the root, the layers and the indicator, andmeasure-tabset.tsfor the measurement. dragDockMachinein@dashfoo/corefor the interaction lifecycle.moveTab,moveTabset,attachTabandplaceBesideindocking.tsfor how a drop reshapes the model.- Controlled mode and history for what happens to the committed action after dispatch.