Skip to content

Read-only and partial editing

What the user may do with the mouse is the editing option: false makes the chart read-only, and an object with move, resize, progress and links turns single kinds of edit off. Two fields of a task narrow it further: locked (no drag at all, but links may touch it) and linkable: false (no link at all, but the bar may be dragged). Whatever the chart refuses is reported by onEditRefused, which the line under the chart shows.

Terminal window
pnpm add @ganttlane/dom # vanilla
pnpm add @ganttlane/react react react-dom # React
View on GitHub
data.ts
import type { Link, Task } from '@ganttlane/core';
// 2026-03-02 is a Monday. Two kinds of task are out of the user's reach, on top of what the
// `editing` option says for the whole chart:
// - `locked: true` cannot be moved, resized or given progress, but links may start and end at it;
// - `linkable: false` cannot be linked at all, but it can be dragged like any other bar.
export const tasks: Task[] = [
// Finished work is locked: the user cannot drag it, and propagation never moves it either.
{
id: 'research',
name: 'Research',
start: '2026-03-02',
end: '2026-03-06',
progress: 100,
locked: true,
},
{
id: 'design',
name: 'Design',
start: '2026-03-09',
end: '2026-03-13',
progress: 100,
locked: true,
},
{ id: 'backend', name: 'Backend', start: '2026-03-16', end: '2026-03-27', progress: 40 },
{ id: 'frontend', name: 'Frontend', start: '2026-03-16', end: '2026-03-25', progress: 25 },
// Agreed with another team: no dependency may be drawn to or from it.
{
id: 'legal',
name: 'Legal review',
start: '2026-03-18',
end: '2026-03-20',
progress: 0,
linkable: false,
},
{ id: 'docs', name: 'Docs', start: '2026-03-26', end: '2026-03-27', progress: 0 },
{ id: 'qa', name: 'QA', start: '2026-03-30', end: '2026-03-31', progress: 0 },
{ id: 'launch', name: 'Launch', type: 'milestone', start: '2026-04-01' },
];
export const links: Link[] = [
{ source: 'research', target: 'design' },
{ source: 'design', target: 'backend' },
{ source: 'design', target: 'frontend' },
{ source: 'frontend', target: 'docs' },
{ source: 'backend', target: 'qa' },
{ source: 'docs', target: 'qa' },
{ source: 'qa', target: 'launch' },
];

Files

  • data.ts: eight tasks; Research and Design are locked, Legal review is linkable: false.
  • options.ts: the editing flags the chart starts with, the view mode, the first scroll and the layout.
  • helpers.ts: the lines of the status, made from the payloads of the events.
  • vanilla.ts and react.tsx: the checkboxes, which call setOptions({ editing }) or pass the editing prop.

Options

Option Value What it does
editing false, or { move, resize, progress, links } (all true at start) Read-only, or one flag per kind of edit; a flag left out is on, true is the default
task.locked true on Research and Design The task cannot be moved, resized or given progress; links may still touch it
task.linkable false on Legal review No link may start at or end at the task
onEditRefused a function (in the example) A drag the chart would not start or commit: { gesture, id, target, reason, at }
onTasksChange a function (in the example) A change that was made, for contrast with the refusals
onLinkCreate a function (in the example) A link that was drawn
viewMode 'week' The scale of the timeline (React: defaultViewMode)
scroll.initial 'first-task' Opens on the plan
layout.rowHeight, .barHeight 36, 24 Smaller rows, so that every task is in view

What to try

  • Untick editing and drag any bar: the chart is read-only, nothing moves, and each attempt says Refused (permission, at the start). Hover a bar: no handles are drawn.
  • Tick it again and untick resize. Drag the edge of Backend: it moves the bar, because a resize zone that is not allowed is just the body of the bar. Untick move as well and the same drag is refused.
  • Research and Design are locked: dragging them is refused with every flag on. Draw a link from the round handle of Design all the same.
  • Legal review has no link handles. Draw a link from Backend onto it: nothing is created, and on release the chart reports link-create refused (permission).
  • Untick links: no handles at all. Untick progress: the little handle at the foot of a bar goes away.

Notes

  • A refusal changes nothing. The payload has the gesture ('move', 'resize-start', 'resize-end', 'progress' or 'link-create'), the task id (the source, for a link) and the target of a link. at says when: 'start' as the drag was about to begin, 'commit' when it was let go. The reason is 'permission' here; 'busy' while a before-hook waits, and 'self', 'cycle' and 'duplicate' for links (Link editing).
  • Only the user is limited. updateTask, addLink, setTasks and the other methods ignore editing and linkable; only a locked task is left alone by updateTask too (it answers 'unchanged'). See Programmatic updates.
  • A task can override the chart. task.editable takes true, false or the same four flags, and wins over editing, in both directions: a task with editable: true can be edited in a read-only chart. locked and linkable: false still forbid what they forbid.
  • Locked work stays put in propagation, too. When a predecessor moves, a locked successor does not follow, and what comes after it is not pushed either. The link is still drawn.
  • React. editing is an ordinary prop, so the checkboxes are state. viewMode is the controlled one, and defaultViewMode is where the chart starts.