Vanilla Gantt Toolbar Technical Docs

<vn-gantt-toolbar gantt="<id>"> is a <vn-grid-toolbar> linked to the task grid of a <vn-gantt>. The page names the Gantt it wrote, by the Gantt's own id, instead of the embedded <vn-grid> the Gantt creates (which has no id). Its own behavior is that link and two built-in commands, scrollToSelectedTask and autoFitTaskList; everything else is the grid toolbar's, by inheritance. Getting Started is a step-by-step guide with live examples.

<vn-gantt-toolbar gantt="g">        <vn-gantt id="g">
  (inherited templates, items,        +-- <vn-grid class="vn-gantt-task-grid">
   commands, state, events)  ---->         linked once getTaskGrid() returns it

The element

class VanillaGanttToolbarElement extends window.VanillaGridToolbarElement, defined as vn-gantt-toolbar and exported as window.VanillaGanttToolbarElement. It is one file, src/vanilla-gantt-toolbar/vanilla-gantt-toolbar.js, with no stylesheet of its own.

Built-in commands

scrollToSelectedTask

scrollToSelectedTask brings the task selected in the task grid into view. A selection change already scrolls the timeline sideways to the selected bar (Task Moving § 4), so the command is the way back to the selection after either pane was scrolled away or its parent collapsed:

<vn-grid-toolbar-command command="scrollToSelectedTask" icon="locate" variant="ghost"
    title-key="scrollToSelectedTaskTitle" disabled-when="!hasSingleSelection"></vn-grid-toolbar-command>
Kind Name Value
Command scrollToSelectedTask Ignores arg. Calls the linked Gantt's scrollToTask(key, { focus: true }) for the one selected key and returns its boolean: ancestors expanded, row centred, bar scrolled into view, and the timeline focused (Timeline § 3). false when unlinked or without exactly one selected task
Message key scrollToSelectedTaskTitle 'Scroll to task'
Icon locate A crosshair

autoFitTaskList

autoFitTaskList fits the task grid's columns, then moves the splitter to the last column's right edge. The inherited autoFitAllColumns fits the columns only and leaves the task list's width as it is (columns wider than the pane scroll sideways, narrower ones leave a strip of row filler); it stays unchanged, as every inherited command does.

<vn-grid-toolbar-command command="autoFitTaskList" icon="auto-fit" variant="ghost"
    title-key="autoFitTaskListTitle"></vn-grid-toolbar-command>
Kind Name Value
Command autoFitTaskList Passes arg to the task grid's autoFitAllColumns() (Column Resizing § 14.2), then calls the linked Gantt's fitTaskListWidth() (Web Component § 8), and returns the auto-fit's boolean. false when unlinked
Message key autoFitTaskListTitle 'Auto-fit columns and task list'
Icon auto-fit The grid toolbar's own; no new icon

So a Gantt toolbar never links an unrelated grid.

The subclass contract

The grid toolbar splits its link resolution into two overridable steps (see 02-implementation.md § Subclass contract). The Gantt toolbar overrides both:

Method Grid toolbar Gantt toolbar
_resolveNamedGrid(warn) The <vn-grid> the grid attribute names The task grid of the <vn-gantt> the gantt attribute names (else of the element the property stored); null while that Gantt is missing, not upgraded or not initialized
_resolveFallbackGrid() The nearest <vn-grid>, with a warning null

It also overrides attributeChangedCallback() (for gantt and grid) and setGrid(). The grid toolbar's CSS and tooltip helpers don't depend on its tag name, so they apply to <vn-gantt-toolbar> as they are.

Theme

The toolbar mirrors the linked grid's theme, as every toolbar does when it has no theme attribute of its own. The Gantt gives its task grid its own theme (Themes), so the Gantt toolbar follows the Gantt's theme, and switches with it. The grid toolbar's base and theme sheets name both tags, :is(vn-grid-toolbar, vn-gantt-toolbar), with the specificity of a type selector, so the cascade and host overrides are the same on both elements.

Loading and the dist bundle

Performance

Not on a hot path once linked. While it waits, the document watch's cost is the grid toolbar's (one MutationObserver, a record per DOM change); each batch adds one getElementById() and one getTaskGrid() call. On project-tasks-js it waits from page load to initializeGantt(), while the DOM barely changes.

TypeScript declarations

src/vanilla-gantt-toolbar/vanilla-gantt-toolbar.d.ts is hand-authored. It imports VanillaGridToolbarElement from the grid toolbar's declarations and VanillaGanttElement from the Gantt's, declares the gantt accessor pair (getter VanillaGanttElement | null, setter also taking a string), and maps vn-gantt-toolbar in HTMLElementTagNameMap. The command names, message keys and icon are strings, so they get no type; the class's doc comment lists them. tests/types/vanilla-gantt-toolbar.dts-typecheck.ts compiles against it, and tests/node/dts-conformance.test.js checks the declared accessors against the runtime and that the element's own public members are declared.