Task Moving Implementation in Vanilla-Gantt
A bar moves horizontally on its own row, by whole days, with the mouse or
pen, by a touch hold, or with Shift+ArrowLeft / Shift+ArrowRight on the
selected task with focus in the timeline (the keyboard alternative to
dragging that WCAG 2.2 § 2.5.7 asks for). The move pushes the successors it would break, transitively, rolls the
summaries up, and is stored through the DataManager's updateTasks(). The
read-only attribute (readOnly property, readOnly option) turns moving off
everywhere; a press on a bar still selects its task.
1. Push rules
VanillaGanttScheduling.computeMove(model, links, task, delta)
(features/scheduling.feature.js) is pure: it reads the task model and the
resolved links (Dependencies § 1) and
returns the change set, writing neither.
- The move. The moved task keeps its duration and shifts by
deltadays. A summary's whole subtree shifts bydelta. - Push forward only. A successor of a changed task whose link is now violated (zero lag) shifts later by the smallest whole-day amount that satisfies it, keeping its duration; a summary successor shifts its subtree. Breadth-first over each task's outgoing links (built once per link set, CSR). A task already pushed is pushed again only if a later push needs more days.
- Never pulled. Moving a task earlier pulls nothing: a predecessor link it now breaks stays violated, and shows so.
- Roll-up. Every ancestor of a changed task is recomputed to span its children with a bar, both ways (it can grow or shrink), deepest first. A summary whose span changed pushes its own successors in turn, so a link from a summary is honoured too.
- Cycles refuse. The move is refused when a push reaches the moved task or its subtree, or goes round a cycle. A push path visits each changed task at most once, so a path longer than the number of changed tasks has looped; that is how a cycle is detected without walking the graph first. A cycle the move does not reach never blocks it.
A task with no valid dates is neither moved nor pushed. changes lists every
task whose dates change, in the order they first changed, the moved subtree
first.
Cost. O(changed tasks + their outgoing links + their ancestors' children).
A push through a 1,000,000-task finish-to-start chain takes about 950 ms in
Node (measured 2026-10-23); a typical move, a few tasks, takes well under a
millisecond. While dragging, the push is recomputed each time the snapped day
changes, so the preview passes a limit: it stops pushing after 20,000 changed
tasks (truncated: true, and a cycle further on goes unseen until the drop).
The lanes show only the rendered rows anyway. The drop recomputes the whole
change set. scheduling.feature.js is in GANTT_BUNDLE_FAST_PATH.
2. Pointer and touch
features/task-move.feature.js, on pointerdown over a bar (delegated from the
lane block):
- The press focuses the timeline (§ 4); bars are never focused. Its
release selects the task in the task grid with
setSelectedKeys([key]), drag or not, so the selection's cost never lands mid-drag. A press on the selected task's bar keeps it selected: a bar press never clears. Read-only, the press only selects (no drag starts), and a touch that pans first selects nothing. - Mouse and pen. The drag starts after 3px of horizontal movement; less is a click. The press's default is prevented, so no text is selected.
- Touch. A hold of 120 ms starts the drag, and moving more than 8px before
it cancels it, as the grid's touch column reorder does
(Column Reordering § 4).
A gesture that moves first is a pan: horizontally the timeline's native
scroll, vertically the grid through
scrollTopBy()(Timeline § 5). Once the hold wins, a non-passivetouchmovelistener prevents the native pan, and the vertical forwarding ignores the finger. - While dragging. The pointer's canvas x (client x, the scroller's left
edge, and the scroller's own
scrollLeft, read on each move rather than the cached value, which follows the scroll handler a frame late) gives the day offset, rounded to whole days, whatever the vertical motion: the bar keeps its row. When it changes, the move is recomputed and previewed: the moved subtree withvn-gantt-bar-dragging, every other changed bar (pushed successors, rolled-up summaries) withvn-gantt-bar-pushed, and the links follow the previewed dates. Nothing is stored. Within 32px of the timeline's left or right edge it auto-scrolls, up to 16px per frame, and the offset follows what scrolls under the pointer. - Release commits the move (§ 3) when the offset is not zero.
Escape,pointercancel, turningread-onlyon, or destroying the Gantt cancels it: every previewed bar goes back. - Double-click. Two presses on the same task's bar within 300 ms, the
grid's row double-click window
(Selection § 6.2), fire
vn-gantt-task-dblclickwith{ task, pane: 'timeline' }on the second press, for mouse, pen and touch, read-only too. The pair is keyed on the task, not the node, so a lane the pool rotates between the presses keeps it. A press that became a drag (past 3px, or a touch hold past 120 ms) or was cancelled never counts as the first, and any other press on the lane block breaks a pair. The second press prevents its default (no word selected) and starts no drag; the first one's release has already selected the task. A double-click beside the bar, on the lane's empty part, fires nothing, as a click there selects nothing (§ 4). On a task's grid row the grid's own detector decides: the Gantt listens forvn-grid-row-dblclickon its grid, selects the task (the grid alone would leave the selection as it was), then fires the event withpane: 'grid', before the grid's event bubbles on to<vn-gantt>. Either way the task double-clicked ends selected. No key fires it.
3. The commit pipeline
The same for a drop and a key press, queued so that commits run one after
another, each waiting for the previous updateTasks():
- Compute the whole change set (§ 1). A cycle fires
vn-gantt-task-move-failedwithcode: 'dependency-cycle'and changes nothing. No change (a move onto the same dates) fires nothing. - Dispatch
vn-gantt-task-move, cancelable, with{ task, changes, source }:changesas{ id, start, end }, dates as'YYYY-MM-DD';source'pointer'(mouse, pen and touch) or'keyboard'.preventDefault()leaves every bar where it was. - Apply optimistically: the model's day arrays and the task objects'
start/endstrings, the range grown when a date lands outside it (the date at the timeline's centre kept in place), the lanes and links redrawn, and the task grid's cells re-rendered withrefresh({ preserveScroll: true })so its start, end and duration columns show the new dates. - Store:
await dataManager.updateTasks(changes).- Resolves:
vn-gantt-task-movedwith{ task, tasks, previous, source },tasksas the manager stored them,previousthe dates before the move. - Rejects (or no manager): every previous date is restored the same way,
and
vn-gantt-task-move-failedfires withcode: 'manager-rejected'and theerror.
- Resolves:
A queued move whose model was replaced by a reload before it ran is dropped.
4. Keyboard and focus
Three tab stops. From the element before the Gantt, Tab reaches the task
grid's viewport, the splitter and the timeline, and a fourth press leaves
the Gantt, whatever the dataset size and the grid's scroll position;
Shift+Tab goes back the same way. The task grid's expand / collapse toggles
are out of the tab order (tree.toggleTabStop: false,
Tree Rows § 1); they stay
clickable, and ArrowRight / ArrowLeft expand and collapse instead (below).
The timeline is its pane's only focus target: always tabindex="0",
role="group" with an aria-label from the timelineLabel message
('Timeline'). Bars carry no tabindex and are never focused. A press on a bar
focuses the timeline (focus({ preventScroll: true })). The scroller inside
it is tabindex="-1", out of the tab order, which Firefox would otherwise
give a scrollable element; a click on its empty area focuses it, and the
focus handler moves focus on to the timeline. A bar is role="img" with its
aria-label (Timeline
§ 2), a named graphic for browse mode; lanes carry no row semantics.
The selection is what the keys act on. The task grid has single selection (Web Component § 4); the keys move it, and Shift+Arrow moves the selected task. There is no separate cursor.
The row keys (ArrowDown / ArrowUp, PageDown / PageUp, Home /
End) act over either pane. Whether a row is selected decides what they do:
| Key | A row selected | No row selected |
|---|---|---|
ArrowDown / ArrowUp |
Select the next / previous row, by render index | Scroll both panes a row, as the grid's own keys |
PageDown / PageUp |
Move the selection by the rows that fit the viewport, less one | Scroll a viewport |
Home / End |
Select the first / last row | Scroll to the top / the end |
Space and Shift+Space toggle the selection, as a click on a row does in
single selection: with nothing selected they select the first task whose row
is fully inside the grid's viewport (whichever pane the key came from); with
a task selected they clear the selection (clearSelection()), so the row keys
scroll again. A held key toggles once; its repeats only have their default
prevented. In the Gantt neither key pages the task grid any more (PageDown and
PageUp still do); a plain <vn-grid> keeps them as its page-down and page-up.
ArrowRight / ArrowLeft in the grid pane, with a task selected (the WAI-ARIA tree keys):
| Selected task | ArrowRight | ArrowLeft |
|---|---|---|
| Collapsed parent | expandRow(key) |
Select its parent (none for a root) |
| Expanded parent | Select its first child | collapseRow(key) |
| Leaf | Nothing | Select its parent |
Under RTL (the grid's viewport computes direction: rtl) the two keys swap,
as in a WAI-ARIA tree. A selected task hidden under a collapsed ancestor acts
from its nearest visible ancestor. Shift+ArrowRight / Left in the grid pane
are not taken.
The timeline's own keys, with focus in it:
| Key | Action |
|---|---|
ArrowRight / ArrowLeft |
Scroll the timeline to the next / previous lower-tier tick boundary (not mirrored: dates run left to right) |
Shift+ArrowRight / Shift+ArrowLeft |
Move the selected task one day later / earlier (§ 3); nothing with no task selected |
Escape |
Cancel a drag |
The gate. One keydown listener on document, in the capture phase,
takes these keys when focus is in the grid's viewport or in the timeline,
or a mouse or pen pointer is over the grid's viewport or the timeline's body
(_pointerPane, kept by the hover sync's pointerover / pointerleave,
Timeline § 2). Never in
an input, textarea, select or editable element (the toolbar's search box
keeps its keys), on the splitter, or with Alt, Ctrl or Meta; Shift only on
Space (Shift+arrows stay the timeline's task move). A focused button keeps
Space, its activation key, and nothing else: the row keys, ArrowRight /
ArrowLeft included, go on to the pane checks, so a toolbar button left
focused by a click, or a tree toggle a click focused, doesn't stop them (the
grid's own gate has the same rule,
Keyboard Navigation § 4). ArrowRight / ArrowLeft
are the grid pane's only with focus in the grid's viewport, or the pointer
over it with focus outside the timeline: focus in the timeline keeps them for
scrolling. Several Gantts on a page: each checks its own panes. Touch has no
hover, so there the gate is focus.
- A row selected: a row key moves the selection (
_moveSelection()) and its default is prevented. The grid scrolls only to keep the new row in view, withscrollToRow(key, { align: 'nearest' }). Focus stays where it is. Moves go by render index, so they skip collapsed subtrees. - No row selected: a row key scrolls, and selects nothing and moves no
focus. Over or in the grid, the grid's own keyboard handling takes it; over
or in the timeline, the Gantt hands it to the grid's
forwardKeydown(), the grid's key scrolling with its key repeat and momentum guard, and the timeline follows the grid's scroll through scroll sync. - No key acts twice. The listener runs before the grid's keyboard registry
(bubble phase on
document), and every key it takes has its default prevented, which the grid'shandleKeydown()skips (Keyboard Navigation § 5).
The selected bar in view. After every selection change but a bar press (a
key, a row click, setSelectedKeys(), scrollToTask(id, { focus: true })),
the vn-grid-selection-changed listener scrolls the timeline sideways to the
selected task's bar when any of it is outside the view, by scrollToTask()'s
rule: the bar's start lands two header tiers from the left edge
(Timeline § 3). Only
when the selected task changed; sideways only (a key move already scrolled
its row into view; a programmatic selection of a row out of view leaves the
rows where they are). A bar press doesn't scroll: the pressed bar is under the
pointer, and a bar cut by the view's edge would otherwise slide under it as a
drag starts. A task with no bar, and a cleared selection, scroll nothing.
Keyboard focus arriving in the timeline from outside, with a task selected,
scrolls its bar into view the same way.
The ring: one selected state. The same listener keeps the selected key
and marks its lane (vn-gantt-lane-selected,
Timeline § 2), and that
class alone draws the ring around the lane's bar (2px in
--vn-gantt-bar-focus-ring at a 2px offset): a bar has the ring exactly when
its grid row is selected, whatever selected it, and never otherwise. Clearing
the selection removes the ring and the lane's mark, focus left where it is.
A task with no bar (no valid dates) has no ring; its lane tint and grid row
show the selection.
Screen readers. A visually hidden role="status" element in the timeline
(.vn-gantt-announcer, outside the scroller, so lane rotation never touches
it) takes the selected bar's label after each keyboard selection change, and
when keyboard focus arrives in the timeline with a task selected; a pointer
selection and a cleared selection leave it as it is.
Keyboard focus. Tab into the timeline selects nothing. Keyboard means the
timeline matches :focus-visible and focus came from outside it. While it
does, the timeline shows its inset outline (2px in
--vn-gantt-bar-focus-ring at outline-offset: -2px), so a keyboard user
sees that the keys act there; a click shows none. A bar press focuses the
timeline by script, which can match :focus-visible, so the press marks the
timeline with vn-gantt-timeline-pointer-focus until it blurs: no outline,
and the focus is not taken for keyboard focus.
scrollToTask(id, { focus: true }) selects the task and focuses the
timeline, wherever focus was
(Timeline § 3).
A selection move costs one setSelectedKeys(), a few milliseconds at
1,000,000 tasks: in tree mode it reads the tree's key index
(Selection § 4).
5. Theme tokens
--vn-gantt-bar-dragging-bg (the moved subtree while previewed),
--vn-gantt-bar-pushed-bg (every other changed bar while previewed) and
--vn-gantt-bar-focus-ring (the selected task's bar's ring, and the
timeline's inset outline while keyboard focus is in it), set by each theme
(Themes § 2). A summary's bracket ends take
the same colour.