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.

  1. The move. The moved task keeps its duration and shifts by delta days. A summary's whole subtree shifts by delta.
  2. 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.
  3. Never pulled. Moving a task earlier pulls nothing: a predecessor link it now breaks stays violated, and shows so.
  4. 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.
  5. 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):

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():

  1. Compute the whole change set (§ 1). A cycle fires vn-gantt-task-move-failed with code: 'dependency-cycle' and changes nothing. No change (a move onto the same dates) fires nothing.
  2. Dispatch vn-gantt-task-move, cancelable, with { task, changes, source }: changes as { id, start, end }, dates as 'YYYY-MM-DD'; source 'pointer' (mouse, pen and touch) or 'keyboard'. preventDefault() leaves every bar where it was.
  3. Apply optimistically: the model's day arrays and the task objects' start / end strings, 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 with refresh({ preserveScroll: true }) so its start, end and duration columns show the new dates.
  4. Store: await dataManager.updateTasks(changes).
    • Resolves: vn-gantt-task-moved with { task, tasks, previous, source }, tasks as the manager stored them, previous the dates before the move.
    • Rejects (or no manager): every previous date is restored the same way, and vn-gantt-task-move-failed fires with code: 'manager-rejected' and the error.

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.

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.