- Components
- Button
- Tree
- Forms
- Input
- Select (beta)
- Design system accessibility review checklist.md
- Tokens
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
Themed file tree with independent selection and expansion, separate chevrons, and a switch for RTL arrow navigation.
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
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.
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
ArrowDownthree times, past CSV export and Scheduled reports, to reach Undated. Then pressArrowRightto 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
GhostTreeItemis therole="treeitem"node (<li>by default) and the focus target. Give it a unique, stablevalue.GhostTreeTriggeris the row label (<span>, no role, notabindex). The item uses it as its accessible name, so child items are never read as part of the parent's name.GhostTreeGroupholds child items (<ul role="group">). An item with a group is a branch and getsaria-expandedandaria-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-modelholds the selection:string | undefinedwith the defaultselection-mode="single", orstring[]withselection-mode="multiple"(which also setsaria-multiselectable="true"). Omit it and usedefault-valuefor uncontrolled state.v-model:expandedholds the open branch values (string[]); usedefault-expandedfor uncontrolled state.EnterandSpaceselect the focused item in single mode and toggle it in multiple mode, with no modifier keys. In single mode, setallow-deselectto 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
ArrowRightnever 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) andCtrl/Cmd+Aare intentionally not provided. selectandtoggleevents 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
| Key | Behavior |
|---|---|
Tab / Shift+Tab | Moves into and out of the tree (one Tab stop). |
ArrowDown / ArrowUp | Next / 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 / End | First / last visible enabled item. |
Enter | Selects (single) or toggles selection (multiple). Never toggles expansion. |
Space | Same 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 characters | Typeahead (500 ms) over visible items, using text-value, the trigger text, or the item's own text. |
Alt / Ctrl / Meta | Chords are left to the browser and assistive technology. |
| IME composition | Ignored 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
Single-selection file hierarchy with expand/collapse, one Tab stop, and arrow-key navigation.
Independent multi-selection
selectionMode="multiple" with controlled v-model and v-model:expanded; Space toggles the focused node.
Separate disclosure and selection
A toggle-only chevron and a select-only label with expandOnClick=false.
Right-to-left tree
dir="rtl" hierarchy where ArrowLeft expands and enters branches and ArrowRight collapses or moves to the parent.
API
See the generated component references for props, emits, slots, exposed members, and styling hooks.
| Prop | Type | Default | Description |
|---|---|---|---|
allowDeselect | boolean | false | In single mode, re-activating the selected node clears the selection. |
as | GhostTreeElement | "ul" | Tag name or component rendered for the role="tree" container. |
defaultExpanded | string[] | "[]" | Initial expanded branch values when expanded is omitted. |
defaultValue | GhostTreeValue | — | Initial uncontrolled selection. |
dir | GhostTreeDirection | — | Explicit writing direction; otherwise inherited from [dir]. |
disabled | boolean | false | Disables every interaction in the tree. |
expanded | string[] | — | Controlled expanded branch values (v-model:expanded). |
expandOnClick | boolean | true | Pointer clicks on a branch row also toggle expansion. |
loop | boolean | false | ArrowDown / ArrowUp wrap at the ends of the visible node list. |
modelValue | GhostTreeValue | — | Controlled selection (v-model). Omit for uncontrolled mode. |
selectionMode | GhostTreeSelectionMode | "single" | Single (string | undefined) or multiple (string[]) selection. |
| Event | Payload | Description |
|---|---|---|
select | GhostTreeSelectPayload | Emitted as select. |
toggle | GhostTreeTogglePayload | Emitted as toggle. |
| Slot | Slot props | Description |
|---|---|---|
default | expandAllSiblings: (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) => void | GhostTreeItem 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-labeloraria-labelledbyonGhostTree. - 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/HighlightTextand disabled rowsGrayText.
Specification
See GhostTree specification and GhostCollapsible.