GanttChart
Plan hierarchical work across day, week, and month scales with progress, milestones, dependencies, controlled state, and accessible pointer and keyboard editing.
Project plan
Groups organize related work, progress fills show completion, dependency lines communicate sequencing, and milestones mark fixed delivery dates.
import { GanttChart, type GanttTask } from "madagent";
<GanttChart
defaultTasks={tasks}
defaultScale="week"
defaultViewStart={new Date(2026, 6, 13)}
defaultCollapsedTaskIds={["planning"]}
today={new Date(2026, 6, 14)}
aria-label="Product launch plan"
/>Installation
import { GanttChart, type GanttTask, type GanttScale } from "madagent";Day, week, and month scales
Control the scale, visible start date, and selected task independently. The chart also supports defaultScale, defaultViewStart, and defaultSelectedTaskId for uncontrolled use.
Design system selected
const [scale, setScale] = useState<GanttScale>("week");
const [viewStart, setViewStart] = useState(new Date(2026, 6, 13));
const [selectedTaskId, setSelectedTaskId] = useState<string | null>("design");
<GanttChart
defaultTasks={tasks}
scale={scale}
onScaleChange={setScale}
viewStart={viewStart}
onViewStartChange={setViewStart}
selectedTaskId={selectedTaskId}
onSelectedTaskIdChange={setSelectedTaskId}
aria-label="Controlled product launch timeline"
/>Pointer and keyboard editing
Task changes are immutable and work in controlled or uncontrolled mode. onTaskChange also identifies whether the task moved or which edge was resized.
Drag a task or milestone bar to move it. Task bars also expose edge handles for resizing; groups cannot be moved or resized. On the focused task name, Alt + ←/→ moves the task or milestone by one scale step. Focus a named task resize handle and press←/→ to adjust that edge. In RTL, the arrows follow logical time direction. Press Esc during a pointer edit to cancel it.
No task edits yet
const [tasks, setTasks] = useState<GanttTask[]>(initialTasks);
<GanttChart
tasks={tasks}
onTasksChange={setTasks}
onTaskChange={(task, previousTask, reason) => {
console.log({ task, previousTask, reason });
}}
editable
aria-label="Editable project timeline"
/>Read-only, disabled, and empty
Use readOnly to preserve exploration without edits, disabled to suspend the complete interaction surface, and an empty array when no scheduled work exists. Individual tasks can also be disabled.
Read-only
Navigation, group disclosure, and selection remain available; dates cannot be edited.
Disabled
Every chart control and task interaction is unavailable.
Empty
An empty task collection keeps the timeline usable and shows an accessible empty-state row.
<GanttChart tasks={tasks} readOnly aria-label="Read-only project timeline" />
<GanttChart tasks={tasks} disabled aria-label="Disabled project timeline" />
<GanttChart tasks={[]} aria-label="Empty project timeline" />GanttChart Props
| Prop | Type | Default | Description |
|---|---|---|---|
tasks | readonly GanttTask[] | - | Controlled task collection |
defaultTasks | readonly GanttTask[] | [] | Initial task collection for uncontrolled mode |
onTasksChange | (tasks: GanttTask[]) => void | - | Receives a new immutable task array after an edit |
onTaskChange | (task: GanttTask, previousTask: GanttTask, reason: GanttTaskChangeReason) => void | - | Reports the edited task, its previous value, and a "move", "resize-start", or "resize-end" reason |
scale | GanttScale | - | Controlled timeline scale: day, week, or month |
defaultScale | GanttScale | "week" | Initial scale for uncontrolled mode |
onScaleChange | (scale: GanttScale) => void | - | Called when the timeline scale changes |
viewStart | Date | - | Controlled first visible calendar date |
defaultViewStart | Date | - | Initial first visible date, aligned to the initial scale boundary; defaults near the earliest task or today |
onViewStartChange | (date: Date) => void | - | Called when navigation or a scale change updates the first visible date |
onNavigate | (direction: "previous" | "next" | "today", viewStart: Date) => void | - | Reports toolbar navigation and its resolved start date |
selectedTaskId | stringnull | - | Controlled selected task id |
defaultSelectedTaskId | stringnull | null | Initial selected task id for uncontrolled mode |
onSelectedTaskIdChange | (taskId: string | null) => void | - | Called when selection changes |
onTaskSelect | (task: GanttTask | null) => void | - | Reports the selected task object or a cleared selection |
collapsedTaskIds | readonly string[] | - | Controlled collapsed group ids |
defaultCollapsedTaskIds | readonly string[] | [] | Initial collapsed group ids for uncontrolled mode |
onCollapsedTaskIdsChange | (taskIds: string[]) => void | - | Called when a group is expanded or collapsed |
locale | string | "en-US" | Locale passed to Intl.DateTimeFormat |
today | Date | - | Deterministic "today" override used by the marker, implicit initial viewport, and Today navigation |
editable | boolean | true | Enables pointer and keyboard task editing |
readOnly | boolean | false | Prevents edits while retaining navigation and selection |
disabled | boolean | false | Disables all controls and task interactions |
taskRailWidth | number | 430 | Width of the sticky task rail in CSS pixels, clamped to at least 240 |
rowHeight | number | 58 | Fixed task row height in CSS pixels, clamped to at least 44 |
aria-label | string | "Project schedule" | Accessible name for the chart |
...divProps | Omit<HTMLAttributes<HTMLDivElement>, "onChange" | "onSelect"> | - | Native div attributes except onChange/onSelect, plus a forwarded ref |
GanttTask
Task dates are calendar dates. The end date is inclusive, groups can own nested tasks through parentId, and dependencies refer to predecessor ids.
Empty ids, invalid dates, and later duplicate ids are omitted. A reversed range is normalized to its start date, milestone end dates are normalized to their start date, progress is clamped to 0–100, and an omitted color is derived from status.
| Prop | Type | Default | Description |
|---|---|---|---|
id* | string | - | Stable identifier used by selection, hierarchy, and dependencies |
title* | string | - | Human-readable task name |
start* | Date | - | Start calendar date; time-of-day is ignored |
end* | Date | - | Inclusive end date; milestones render on one date |
progress | number | 0 | Completion percentage, clamped to the 0–100 range for rendering |
type | "task""group""milestone" | "task" | Visual and behavioral task kind |
status | "todo""in-progress""done""blocked" | - | Semantic workflow state and default color source |
color | "accent""info""positive""warning""negative""chart1""chart2""chart3""chart4""chart5" | - | Semantic or chart-token bar color |
assignee | ReactNode | - | Owner content, such as a name or Avatar |
parentId | string | - | Parent group or task id; orphan tasks safely render at the root |
dependencies | string[] | [] | Predecessor task ids used to draw dependency connectors |
disabled | boolean | false | Prevents editing and selection while leaving the task readable |
Accessibility
Always give the chart a concise aria-label. The task rail and timeline expose a named treegrid with native focusable controls, groups communicate their expanded state and hierarchy, and selection does not rely on color alone.
- Tab reaches chart navigation, scale, disclosure, task, and edit controls; visible rows expose their hierarchy through the treegrid.
- Enter or Space selects the focused task name; selecting the current item again clears selection.
- The task-name controls use roving focus: Up/Down moves through visible tasks, Home/End jumps to a boundary, logical inline-end expands a group or enters its first child, and logical inline-start collapses a group or returns to its parent.
- Alt + Left/Right moves the focused editable task name. A focused, named resize separator uses Left/Right without a modifier. Each step is 1 day, 7 days, or 30 days for day, week, or month scale. Groups are not movable, and groups and milestones have no resize handles.
- Completed move and resize operations are announced through a polite live region and emit the same callbacks as pointer edits. Escape or pointer cancellation aborts an active pointer preview without callbacks.
readOnlypreserves navigation and selection, whiledisableddisables controls and task interactions; the scrollable timeline region remains reachable for reading.
RTL Support
Components automatically adapt to right-to-left languages using CSS logical properties.
Preview
Usage
<GanttChart
defaultTasks={arabicTasks}
locale="ar-EG"
defaultScale="week"
aria-label="خطة إطلاق المنتج"
/>