DragDropTree (legacy)
DragDropTree is a legacy migration surface: the Rust crate's mouse-driven tree reorder surface. It renders a div.hk-drag-drop-tree of rows (div.hk-drag-node, each with a ⋮⋮ handle, a title, and its children nested one level deeper), and turns a press-and-release across rows into a drop event. packages/vue/src ships no counterpart; the Vue library's reorder surface is a flat draggable list, not a tree.
RenderDragNode, the recursive node row, is where the press, the ghost and the drop line live — but it is a private #[component] fn, not part of the public surface: its props struct RenderDragNodeProps is re-exported and in the prelude, while the function itself can be named only from inside the crate, so a host can neither call it nor wrap it.
- This is a mouse gesture, not native HTML5 drag. The rows no longer carry draggable; the reorder is bound to mousedown / mousemove / mouseenter / mouseleave / mouseup (see "The gesture"). Native drag interop, the browser's drag image and touch reordering are all gone with it — documented consequences, not missing wiring.
- The tree is a view plus a reorder notification, not a data mutator: it never rewrites data. The host applies the move and re-renders.
- For a plain tree without reordering, use Tree; for the legacy node markup, TreeNode.
Import
use *; // DragDropTree, DragTreeNodeData, DragDropTreeProps, RenderDragNodeProps,
// DropTarget, DropEvent, DropPosition, DragLeaveAction,
// drag_press_armed, drag_leave_action, drag_commit_drop, drag_drop_moves
use *; // DragDropTreeProps, RenderDragNodeProps, rsx!, VNode
DragDropTree is a plain function, DragDropTree(DragDropTreeProps { … }). Inside rsx! every prop may be omitted except data: draggable and drop_allowed default to true, the three callbacks to None. DragTreeNodeData is a #[define_props] struct whose defaults are all empty, so ..Default::default() works when you only need item_key and title.
The gesture
A reorder is a two-step gesture. mousedown on a row only records the press (item_key, client_x, client_y) in a module-level thread_local; the drag is not published until the pointer moves past DRAG_ARM_PX (5px, strictly more than 5) — drag_press_armed is the rule, and it fires from the row's mousemove or from mouseenter, because a fast flick can leave the source row before a move event lands on it. Only at that moment does the ghost appear, the dragged key get written, and allow_drag fire with (key, true).
mouseenter on another row highlights it (hk-drag-node-drag-over) and draws div.hk-drop-line under it; mouseleave clears the highlight. mouseup commits: the row stops propagation, ignores any button but the primary one, and calls drag_commit_drop, which — provided the target is a different row (drag_drop_moves rejects from == to, so a release on the source row is a click, not a reorder) — fires allow_drop and then on_drop with a DropEvent, and retires the gesture either way.
A release on the tree's padding or outside the tree is retired by the root's mouseup / mouseleave, the closest edge a component owns to Vue's document-level pointerup; drag_leave_action is the rule behind the leave path.
The snapshot is a still: the rows and their handles draw, and no gesture state exists because no handler ran.
Drop position, and what a drop actually reports
DropPosition has three values (Before, After, Inside, the first being the default) and DropTarget carries { target_key, position } — but the commit path hard-codes DropPosition::Inside for every drop it emits. The enum's other two variants are never produced by this component, so a host cannot build "insert above / below" from on_drop alone; the reported position always says "inside the target". allow_drop fires first (a notification — its handler returns unit, so it cannot veto), then on_drop.
allow_drag has the same shape: it is a notification at arm time, not a permission check. A row that must not start a drag is refused by draggable: false on the tree or disabled on the node (the press handler checks both before recording anything), not by returning from the callback.
The snapshot is a still: it shows the same rows with the gesture disabled. With draggable: false the ⋮⋮ glyph is gone from every handle (it is gated on draggable and on the node not being disabled), while the rows and the children keep rendering — so the second tree reads as a plain list, which is exactly the shape this flag is for.
Rows, handles and depth
Each node is a div.hk-drag-node (plus hk-drag-node-dragging / -drag-over / -disabled), containing div.hk-drag-handle → the ⋮⋮ glyph (only when draggable and not disabled) → div.hk-node-content with the title, and, while dragging, a div.hk-drag-ghost. Children go into div.hk-node-children, indented by the sheet's --hi-drag-indent (24px).
Nesting is carried by depth, but nothing visible consumes it: the sheet indents through the nested .hk-node-children wrappers, and depth itself only travels down the recursion (it is not written into the markup). A disabled node dims, gets cursor: not-allowed and — by the sheet's rule — pointer-events: none, which takes its whole subtree out of pointer reach, not just the node.
The tree is not flattened and not foldable: every node renders its children unconditionally, so a large tree renders in full and cannot be collapsed.
API
Rust
Props — DragDropTree
| Prop | Type | Default | Description |
|---|---|---|---|
| data | Vec<DragTreeNodeData> | [] | — |
| draggable | bool | true | — |
| drop_allowed | bool | true | — |
| allow_drag | Option<EventHandler<(String, bool)>> | None | — |
| allow_drop | Option<EventHandler<(DropTarget, bool)>> | None | — |
| on_drop | Option<EventHandler<DropEvent>> | None | — |
| class | String | "" | — |
Accessibility
- The whole surface is pointer-only. Rows are divs: no tabindex, no role, no key bindings, and no equivalent of "move up / move down". A keyboard or screen-reader user cannot reorder anything, cannot even learn that reordering exists.
- No tree semantics. The root div.hk-drag-drop-tree has no role="tree", the rows no role="treeitem" and no aria-level, and there is no aria-grabbed / aria-dropeffect (both deprecated, and absent here anyway). Nesting is announced as nothing.
- No live announcement of the gesture. The ghost, the drop line and the highlight are divs with classes only — no text, no aria-live region — so a drop-target change is invisible to a screen reader even if the row were focusable.
- The ⋮⋮ handle is plain text in a span with no label: it reads as two vertical ellipses with no explanation, and it is the only affordance that says "this row moves".
- A disabled node is dimmed and pointer-inert, but nothing announces the state; the hk-drag-node-disabled class is the only carrier.
- The gesture also has an unavoidable pointer-only open: arming requires a mousemove past 5px, and a touch screen produces no mousemove at all, so reordering is unavailable on touch devices.
Related components
- Tree — the supported tree with folding, selection and a keyboard cursor.
- TreeNode — the legacy node markup, without the reorder gesture.
- VirtualTree — the legacy flattening viewport for large trees.
- HkDraggableList — the Vue reorder surface, for a flat list; its arm-distance rule is the one DRAG_ARM_PX follows.