Skip to content

GhostTree ​

GhostTree is a hierarchical list (role="tree") for file explorers, taxonomy filters, and nested outlines. It follows the WAI-ARIA APG Tree View pattern. You render your own nested data with keyed GhostTreeItem parts; the tree tracks only their value strings and never reads or mutates your objects. Import GhostTree, GhostTreeItem, GhostTreeTrigger, and GhostTreeGroup from @ghostvue/themes for styled rows. The headless customization examples use the same interface from @ghostvue/vue.

Explore a workspace ​

Workspace explorer

Themed file tree with independent selection and expansion, separate chevrons, and a switch for RTL arrow navigation.

Workspace explorer
  • Components
    • Button
    • Tree
  • Tokens
Selected: components/tree

In the workspace explorer, select Components by clicking its name, or focus the row and press Enter. The Selected line shows the value. Click the chevron to open or close the folder while keeping the selection. With the folder open, focus Components and press Right Arrow to enter the list. Use Left Arrow on a child to return to its parent.

Use Right-to-left to try the same sequence with the horizontal arrows reversed. The tree keeps the selection and expanded folders when direction changes. Open Forms to see how a long filename wraps at a narrow width.

The theme indents rows through --ghost-tree-level and draws the focus ring around the focused row. GhostTreeGroup animates its height when motion is allowed. Set disable-animation on a group to disable that motion.

Plan milestones by initiative ​

Roadmap milestones

Milestones grouped by initiative with an Undated group, an example-owned timeline of target days, target windows and actual dates, and app-supplied risk details with a linked work item.

Milestones by initiative
  • Reporting, 3 milestones
    • CSV export, At risk, Target: June 12
    • Scheduled reports, On track, Target window: July 1 – July 31
    • Undated, 1 milestone
      • Report sharing permissions, Needs a date, No target date
  • Billing, 3 milestones
    • Invoice PDF redesign, Completed, Target: June 12, Actual: June 15
    • Usage dashboard beta, Completed, Target window: July 1 – July 31, Actual: July 18
    • Tax ID validation, On track, Target: August 20
Milestone details Choose a milestone in the tree or on the timeline to see its target, status and linked work.
Timeline, June – August 2026
Reporting
Billing

A planner scans milestones by initiative, finds commitments that still need a date, and inspects the work behind a risk warning. The tree groups milestones under each initiative. The timeline below it belongs to the example: plain buttons over a June to August scale, not a GhostVue component. Try it from the keyboard:

  • Find undated work. Tab into the tree, which starts on Reporting, and press ArrowDown three times, past CSV export and Scheduled reports, to reach Undated. Then press ArrowRight to move to Report sharing permissions. Its row reads No target date and Needs a date. A milestone without a target stays inside its initiative, next to the dated commitments it competes with, instead of in a separate list.
  • Inspect a risk. Move to CSV export and press Enter. The details show Target June 12 and the status At risk · required review scheduled for June 14. Press Tab once to reach the linked work item, Export security review.
  • Open from the timeline. Each timeline row is a button that opens the same details as the tree and selects the same tree row, opening its branches if needed. Focus stays on the button you pressed.

Every date is labeled in text, so a reader never relies on the marker shape:

  • A single-day target is a diamond with Target: June 12.
  • A target window is a bar with Target window: July 1 – July 31.
  • A completed milestone keeps its original target and adds a filled circle with Actual: June 15, as in Invoice PDF redesign (target June 12) and Usage dashboard beta (window July 1 – July 31, actual July 18).

The app owns each milestone's dates, status label and reason. The example prints the assessment it receives and never derives risk from dates, because only the app knows about reviews, dependencies and staffing.

Basic use ​

  • GhostTreeItem is the role="treeitem" node (<li> by default) and the focus target. Give it a unique, stable value.
  • GhostTreeTrigger is the row label (<span>, no role, no tabindex). The item uses it as its accessible name, so child items are never read as part of the parent's name.
  • GhostTreeGroup holds child items (<ul role="group">). An item with a group is a branch and gets aria-expanded and aria-controls; an item without one is a leaf.

The tree has one Tab stop. Arrow keys move focus over visible, enabled items in rendered order; focus never changes selection or expansion on its own.

Selection and expansion ​

  • v-model holds the selection: string | undefined with the default selection-mode="single", or string[] with selection-mode="multiple" (which also sets aria-multiselectable="true"). Omit it and use default-value for uncontrolled state.
  • v-model:expanded holds the open branch values (string[]); use default-expanded for uncontrolled state.
  • Enter and Space select the focused item in single mode and toggle it in multiple mode, with no modifier keys. In single mode, set allow-deselect to let reactivation clear the selection.
  • Updates always emit new arrays. If a controlled parent ignores an update, the DOM and ARIA state keep showing the parent's value, and ArrowRight never enters a branch that did not actually open.
  • Selection is independent per node: selecting a parent never selects its children and selecting every child never selects the parent. Range selection (Shift+Arrow) and Ctrl/Cmd+A are intentionally not provided.
  • select and toggle events report each requested change as { value, selected } and { value, expanded }, for example to load children when a branch opens.

Pointer behavior and split triggers ​

Clicking a row selects it and, while expand-on-click is true (the default), also toggles a branch. GhostTreeTrigger takes an action:

  • 'both' (default) selects and toggles like a row click.
  • 'toggle' only expands or collapses. Use it for a chevron; it never names the item.
  • 'select' only selects.

Clicks that bubble from a nested item never select or toggle its parent.

Right-to-left ​

Pass dir, or let the tree inherit it from the closest [dir] ancestor or <html dir>. In RTL, ArrowLeft opens a branch or enters its first child and ArrowRight closes a branch or moves to the parent. The root reports the result in data-dir.

Keyboard ​

KeyBehavior
Tab / Shift+TabMoves into and out of the tree (one Tab stop).
ArrowDown / ArrowUpNext / previous visible enabled item. Wraps only with loop.
ArrowRight (LTR)Opens a closed branch; on an open branch, moves to its first child. Leaves: nothing.
ArrowLeft (LTR)Closes an open branch; otherwise moves to the closest enabled ancestor.
Home / EndFirst / last visible enabled item.
EnterSelects (single) or toggles selection (multiple). Never toggles expansion.
SpaceSame as Enter, unless a typeahead query is active, in which case it is part of the query.
*Opens every closed, enabled sibling branch of the focused item.
Printable charactersTypeahead (500 ms) over visible items, using text-value, the trigger text, or the item's own text.
Alt / Ctrl / MetaChords are left to the browser and assistive technology.
IME compositionIgnored until the input method commits text.

In RTL the two horizontal arrows swap.

Focus recovery ​

  • When a branch closes while one of its descendants has focus, focus moves to the closest visible enabled ancestor.
  • When the focused item unmounts, focus moves to the next visible enabled item, then the previous one, then the closest ancestor. No update:* event is emitted: removing an item never changes the selection or expansion values.
  • Keyed reordering and insertion keep the current Tab stop; navigation always follows the rendered order.

Disabled items ​

disabled on GhostTree disables everything. disabled on a GhostTreeItem removes that item from selection, expansion, navigation, and typeahead, but not its children: if a disabled branch is open, its enabled children stay reachable, and ArrowLeft from them skips to the closest enabled ancestor.

Server rendering ​

IDs, aria-expanded, aria-controls, aria-labelledby, closed groups (hidden), and the initial tabindex="0" are rendered on the server and hydrate without mismatches. To get branch ARIA in server HTML, put GhostTreeGroup and GhostTreeTrigger directly in the item's slot (inside plain elements is fine); parts nested inside your own wrapper components are recognized after hydration.

Headless customization ​

Use these examples from @ghostvue/vue when your application supplies its own styling. Each remains available in the playground and as copyable source.

Single selection ​

Basic Headless

Single-selection file hierarchy with expand/collapse, one Tab stop, and arrow-key navigation.

  • src
    • main.ts
    • router.ts
  • package.json

Selected: src/main.ts

Independent multi-selection ​

Multiple selection Headless

selectionMode="multiple" with controlled v-model and v-model:expanded; Space toggles the focused node.

  • Frontend
    • Vue
    • CSS
    • Accessibility
  • Design

Selected: css

Expanded: frontend

Separate disclosure and selection ​

Split trigger Headless

A toggle-only chevron and a select-only label with expandOnClick=false.

  • Team
    • Roadmap
    • Retro notes

Right-to-left tree ​

Right-to-left Headless

dir="rtl" hierarchy where ArrowLeft expands and enters branches and ArrowRight collapses or moves to the parent.

  • Invoices

API ​

See the generated component references for props, emits, slots, exposed members, and styling hooks.

PropTypeDefaultDescription
allowDeselectbooleanfalseIn single mode, re-activating the selected node clears the selection.
asGhostTreeElement"ul"Tag name or component rendered for the role="tree" container.
defaultExpandedstring[]"[]"Initial expanded branch values when expanded is omitted.
defaultValueGhostTreeValue—Initial uncontrolled selection.
dirGhostTreeDirection—Explicit writing direction; otherwise inherited from [dir].
disabledbooleanfalseDisables every interaction in the tree.
expandedstring[]—Controlled expanded branch values (v-model:expanded).
expandOnClickbooleantruePointer clicks on a branch row also toggle expansion.
loopbooleanfalseArrowDown / ArrowUp wrap at the ends of the visible node list.
modelValueGhostTreeValue—Controlled selection (v-model). Omit for uncontrolled mode.
selectionModeGhostTreeSelectionMode"single"Single (string | undefined) or multiple (string[]) selection.
EventPayloadDescription
selectGhostTreeSelectPayloadEmitted as select.
toggleGhostTreeTogglePayloadEmitted as toggle.
SlotSlot propsDescription
defaultexpandAllSiblings: (value: string) => void, expanded: string[], focusedValue: string | undefined, isExpanded: (value: string) => boolean, isSelected: (value: string) => boolean, modelValue: GhostTreeValue, select: (value: string) => void, toggleExpanded: (value: string) => voidGhostTreeItem nodes; receives selection, expansion, and focus state plus select/toggle helpers.

@ghostvue/themes adds no props, events, or slots to the headless GhostTree API, which it forwards.

GhostTree ​

Props: as (default 'ul'), selectionMode, modelValue, defaultValue, expanded, defaultExpanded, allowDeselect, expandOnClick (default true), loop, dir, and disabled. Emits update:modelValue, update:expanded, select, and toggle. The default slot receives { modelValue, expanded, focusedValue, isSelected, isExpanded, select, toggleExpanded, expandAllSiblings }. Sets data-part="root", data-ghost-tree, data-dir, and data-disabled.

GhostTreeItem ​

Props: as (default 'li'), value (required), disabled, and textValue. The default slot receives { selected, expanded, focused, disabled, expandable, level, select, toggle }. Sets data-part="item", data-state="checked" | "disabled", data-selected, data-expanded (branches), data-disabled, data-level, and the inline --ghost-tree-level custom property.

GhostTreeTrigger ​

Props: as (default 'span'), action, and disabled. Sets data-part="trigger", data-state="open" | "closed" (branches) or "checked" (selected leaves), data-selected, and data-disabled. focus() focuses the owning item.

GhostTreeGroup ​

Props: as (default 'ul') and disableAnimation. Sets role="group", data-part="group", data-state="open" | "closed", hidden while closed, and data-animation="off".

Every part exposes { element, focus, blur }.

useGhostTree(options?) and resolveTreeDir(dir?, element?) ​

useGhostTree is the state engine behind GhostTree: selection, expansion, the item registry, the roving tab stop, keyboard handling, and typeahead. resolveTreeDir returns 'ltr' | 'rtl' from an explicit value, the closest [dir] ancestor, then <html dir>, and is safe to call during SSR.

Accessibility ​

  • Name the tree with aria-label or aria-labelledby on GhostTree.
  • Mark decorative icons and chevrons aria-hidden="true"; they are then left out of both the accessible name and typeahead.
  • Do not put buttons, links, or other focusable controls inside an item. The item is the only focus target.
  • In forced-colors mode, selected rows use Highlight / HighlightText and disabled rows GrayText.

Specification ​

See GhostTree specification and GhostCollapsible.