GhostTree specification
Status: Approved. Direction (Option A) approved by Zac (maintainer) in chat, November 17, 2026. The complete design plan and specification was recorded in the GHO-105 Linear document (GHO-105 — Tree / TreeView design plan and specification), and per Zac's instructions GHO-105 was marked ready in the "Approval and readiness update — November 17, 2026" note on GHO-105. Predecessor: GhostCollapsible specification (GHO-86).
Purpose and user problems
GhostTree is an accessible hierarchical list widget (role="tree") for navigating, expanding/collapsing, and selecting nested items such as file explorers, taxonomy filters, organizational hierarchies, and nested configuration outlines. It gives consumers compound keyed parts (GhostTree, GhostTreeItem, GhostTreeTrigger, GhostTreeGroup) with controlled and uncontrolled selection (single or multiple) and expansion (expanded), a single roving tabindex="0" tab stop, RTL-aware 2D arrow navigation, typeahead, and deterministic SSR markup without mutating consumer data.
Non-goals
- Built-in row virtualization or windowed DOM recycling (deferred per
GHO-105Option A). - Built-in async lazy-loading state machines or transport callbacks (consumers own async child fetching and render
GhostTreeGroupchildren when available). - Cascading/tri-state parent-child selection (
propagateSelect/bubbleSelect); nested selection is strictly independent in v1. - Implicit
Shift+Arrow/Shift+Clickcontiguous range selection orCtrl/Cmd+Ashortcut interception in v1. - Drag-and-drop node reordering or inline node renaming (
contenteditable/ input editing). - Multi-column tabular trees (
role="treegrid"belongs to DataTableGHO-35).
Public API
Parts and exports
Headless exports from @ghostvue/vue:
GhostTree— rootrole="tree"container and context provider (as="ul"default).GhostTreeItem— keyedrole="treeitem"node (as="li"default) owning focus, selection state, and branch expansion state.GhostTreeTrigger— non-focusable row header or disclosure toggle target insideGhostTreeItem(as="span"default) providing the item's accessible label (aria-labelledby) and pointer action ('both' | 'toggle' | 'select').GhostTreeGroup— nestedrole="group"child container insideGhostTreeItem(as="ul"default) reusingGhostCollapsible'shiddenand themed height-transition semantics.useGhostTree— headless composable managing selection, expansion, node registration, parent/child relationships, roving focus, arrow-key navigation, and typeahead.resolveTreeDir— pure SSR-safe helper resolving'ltr' | 'rtl'.- Types:
GhostTreeSelectionMode,GhostTreeValue,GhostTreeDirection,GhostTreeElement,GhostTreeProps,GhostTreeSlotProps,GhostTreeExposed,GhostTreeItemElement,GhostTreeItemProps,GhostTreeItemSlotProps,GhostTreeItemExposed,GhostTreeTriggerElement,GhostTreeTriggerAction,GhostTreeTriggerProps,GhostTreeTriggerSlotProps,GhostTreeTriggerExposed,GhostTreeGroupElement,GhostTreeGroupProps,GhostTreeGroupExposed,GhostTreeSelectPayload,GhostTreeTogglePayload,GhostTreeNodeRecord,UseGhostTreeOptions,UseGhostTreeReturn,GhostTreeContext,GhostTreeItemContext,ghostTreeContextKey,ghostTreeItemContextKey.
Themed exports from @ghostvue/themes:
GhostTree,GhostTreeItem,GhostTreeTrigger,GhostTreeGroup(plus re-exported types and styles viapackages/themes/src/ghost-tree.cssindefault.css).
Props and configuration
export type GhostTreeSelectionMode = 'single' | 'multiple'
export type GhostTreeValue = string | string[] | undefined
export type GhostTreeDirection = 'ltr' | 'rtl'
export type GhostTreeTriggerAction = 'both' | 'toggle' | 'select'
export interface GhostTreeSelectPayload {
value: string
selected: boolean
}
export interface GhostTreeTogglePayload {
value: string
expanded: boolean
}GhostTree (root)
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostTreeElement (string | Component) | 'ul' | Element tag or component rendered for the role="tree" container. |
selectionMode | GhostTreeSelectionMode ('single' | 'multiple') | 'single' | Single selection (string | undefined) vs multi-selection (string[]). Sets aria-multiselectable="true" when 'multiple'. |
modelValue | GhostTreeValue (string | string[] | undefined) | undefined | Controlled selection (v-model). Omit for uncontrolled mode. Supports explicit controlled undefined in 'single' mode when onUpdate:modelValue is bound (allowControlledUndefined: true). |
defaultValue | GhostTreeValue (string | string[] | undefined) | undefined | Initial uncontrolled selection (undefined in 'single' mode, [] in 'multiple' mode). |
expanded | string[] | undefined | undefined | Controlled expanded branch keys (v-model:expanded). Omit for uncontrolled mode. |
defaultExpanded | string[] | [] | Initial expanded branch keys when expanded is omitted. |
allowDeselect | boolean | false | In selectionMode="single", allows re-activating the selected node via click, Space, or Enter to clear modelValue to undefined. Ignored in 'multiple' mode (where nodes always toggle). |
expandOnClick | boolean | true | When true, pointer click on a branch GhostTreeItem (or GhostTreeTrigger with action="both") toggles branch expansion in addition to selection. When false, row clicks only select unless a trigger has action="toggle". |
loop | boolean | false | When true, ArrowDown wraps from the last visible enabled node to the first and ArrowUp wraps from the first to the last. Defaults to false per APG Tree View. |
dir | GhostTreeDirection | undefined ('ltr' | 'rtl' | undefined) | undefined | Explicit writing direction for ArrowRight/ArrowLeft. When omitted, resolves from closest [dir] ancestor or document.documentElement.dir ('ltr' fallback in SSR). |
disabled | boolean | false | Disables all tree interaction (aria-disabled="true" on root and items; all items set tabindex="-1"). |
GhostTreeItem
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostTreeItemElement (string | Component) | 'li' | Element tag or component rendered for the role="treeitem" node. |
value | string | required | Unique, stable key identifying this node in modelValue, expanded, and focus tracking. |
disabled | boolean | false | Disables selection, expansion toggling, and roving focus for this node (aria-disabled="true"). Combines with root disabled. |
textValue | string | undefined | undefined | Explicit label used by printable-character typeahead. When omitted, derived from GhostTreeTrigger text content, or the item's own text content excluding nested [role="group"] elements. |
GhostTreeTrigger
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostTreeTriggerElement (string | Component) | 'span' | Element tag or component for the item's row or disclosure control. Defaults to 'span' with no interactive role or tabindex so GhostTreeItem remains the sole role="treeitem" tab stop and avoids nested-interactive Axe violations. |
action | GhostTreeTriggerAction ('both' | 'toggle' | 'select') | 'both' | Pointer click behavior: 'both' selects the item and (if expandable and expandOnClick=true) toggles expansion; 'toggle' only toggles branch expansion without changing selection; 'select' only selects the item without toggling expansion. |
disabled | boolean | false | Local disable flag combining with GhostTreeItem and GhostTree disabled. |
GhostTreeGroup
| Prop | Type | Default | Contract |
|---|---|---|---|
as | GhostTreeGroupElement (string | Component) | 'ul' | Element tag or component rendered for the role="group" child container. |
disableAnimation | boolean | false | When true, sets data-animation="off" and skips themed CSS height transitions on expand/collapse. |
v-model contracts
v-model(modelValue/update:modelValue):- Managed via
useControllableStatewithallowControlledUndefined: true. - In
selectionMode="single", committed values arestring | undefined. Selecting an unselected node emitsupdate:modelValue(value). Selecting an already-selected node emitsupdate:modelValue(undefined)only whenallowDeselect === true; whenallowDeselect === false, it is a no-op (no duplicate emission). - In
selectionMode="multiple", committed values arestring[](default[]). Activating a node toggles itsvaluein a new shallow-cloned array (preserving existing order and appending newly selected keys) and emitsupdate:modelValue(nextArray). Never mutates the consumer's input array in place.
- Managed via
v-model:expanded(expanded/update:expanded):- Managed via
useControllableState<string[]>. - Expanding a branch appends
value(deduplicated) to a newstring[]and emitsupdate:expanded(nextExpanded). Collapsing removesvalueinto a newstring[]and emitsupdate:expanded(nextExpanded). Expanding sibling branches via*adds all newly expanded sibling keys in a single atomicupdate:expandedemission. Never mutates the consumer'sexpandedarray in place.
- Managed via
Events, callbacks, slots, and exposed methods
GhostTreeevents:'update:modelValue': [value: GhostTreeValue]'update:expanded': [expanded: string[]]'select': [payload: GhostTreeSelectPayload]— emitted after an enabled node's selection action is triggered.'toggle': [payload: GhostTreeTogglePayload]— emitted after an enabled branch node's expansion action is triggered.
GhostTreedefault slot (GhostTreeSlotProps):{ modelValue: GhostTreeValue, expanded: string[], focusedValue: string | undefined, isSelected: (value: string) => boolean, isExpanded: (value: string) => boolean, select: (value: string) => void, toggleExpanded: (value: string) => void, expandAllSiblings: (value: string) => void }
GhostTreeItemdefault slot (GhostTreeItemSlotProps):{ selected: boolean, expanded: boolean, focused: boolean, disabled: boolean, expandable: boolean, level: number, select: () => void, toggle: () => void }
GhostTreeTriggerdefault slot (GhostTreeTriggerSlotProps):{ selected: boolean, expanded: boolean, disabled: boolean, expandable: boolean, level: number, select: () => void, toggle: () => void }
- Exposed component refs:
GhostTree,GhostTreeItem,GhostTreeTrigger, andGhostTreeGroupeach expose{ readonly element: HTMLElement | null, focus(options?: FocusOptions): void, blur(): void }.GhostTree.focus()focuses the active roving tab-stopGhostTreeItemelement (if any).GhostTreeTrigger.focus()delegates to its owningGhostTreeItemelement so programmatic focus always lands on therole="treeitem"host.
State model
- Independent focus, selection, and expansion:
- Moving focus via arrow keys,
Home,End, or typeahead updatesfocusedValueand the rovingtabindex="0"stop only; it never mutatesmodelValueorexpanded. - Nested selection is strictly independent: toggling a parent branch node never modifies its descendants' selection state, and selecting/deselecting all children never modifies or sets an indeterminate state on the parent branch node.
- Range selection (
Shift+Arrow,Shift+Click) andCtrl/Cmd+Aselect-all shortcuts are intentionally omitted in v1 soAlt/Ctrl/Metachords remain browser/OS-native (GHO-168) andShift+Arrowmoves focus predictably without unexpected multi-node mutations.
- Moving focus via arrow keys,
- Branch vs leaf detection (
expandable):- A
GhostTreeItembecomes a branch (expandable === true) when a direct childGhostTreeGroupmounts and registers with itsghostTreeItemContextKey. - Leaf items (
expandable === false) omitaria-expanded,aria-controls, anddata-expanded. - Branch items (
expandable === true) bindaria-expanded="true" | "false",aria-controls="<groupId>",data-expanded="true" | "false", anddata-state="open" | "closed"on their trigger/group.
- A
- Controlled update rejection:
- If
modelValueorexpandedis controlled and the parent ignores@update:modelValueor@update:expanded,useControllableStateretains the parent's prop value. aria-selected,aria-expanded,data-state,data-selected,data-expanded, andGhostTreeGroup'shiddenattribute always derive from the authoritative state (modelValueandexpandedrefs), so rejected updates never leave DOM or ARIA state out of sync.- Pressing
ArrowRight(LTR) /ArrowLeft(RTL) on a closed branch only proposessetExpanded(value, true)and keeps focus on the branch node; moving focus to the first child happens only when pressing the expand key on a branch whose authoritativeisExpanded(value)is alreadytrue. Thus, a rejected controlled expansion never moves focus into hidden children.
- If
Loading, empty, disabled, read-only, and error states
- Root
disabled: true: setsaria-disabled="true"anddata-disabled=""onGhostTreeand allGhostTreeItems, sets every item'stabindex="-1", and ignores all pointer and keyboard selection, expansion, and navigation. - Item
disabled: true: setsaria-disabled="true"anddata-disabled=""on thatGhostTreeItemand itsGhostTreeTrigger, sets itstabindex="-1", and skips it during arrow navigation,Home/End,*sibling expansion, and typeahead. - Disabled parent with pre-expanded children:
disabledon aGhostTreeItemdisables that node itself, not its descendants. If a disabled branch is open viadefaultExpandedor controlledexpanded, its enabled children remain visible and navigable. PressingArrowLeft(LTR) /ArrowRight(RTL) on a child whose immediate parent is disabled moves focus to the closest visible enabled ancestorGhostTreeItem(or stays on the child if no ancestor is enabled). - Empty tree: when zero enabled
GhostTreeItems are registered or visible, no element hastabindex="0", and keyboard handlers exit cleanly without throwing or callingpreventDefault().
Async behavior
- Consumers own async data fetching (e.g., loading child items when
@togglefires withexpanded: trueor viav-model:expanded). - When async children mount inside
GhostTreeGroup, they register dynamically inuseGhostTree, preserving the currentfocusedValueand singletabindex="0"stop.
Consumer data
- Consumers render their own nested collections via
v-for(or static templates) with stable:keyandvaluestrings on eachGhostTreeItem. GhostTreenever reads, clones, sorts, or mutates consumer domain objects; it tracks only thevalue: stringkeys and DOM references registered by mountedGhostTreeIteminstances.
Accessibility contract
Follows WAI-ARIA APG Tree View Pattern.
Semantics and relationships
GhostTree:role="tree",aria-multiselectable="true"whenselectionMode === 'multiple'(omitted when'single'),aria-disabled="true"whendisabled === true. Consumers supply an accessible name viaaria-labeloraria-labelledby.GhostTreeItem:role="treeitem",id(fromuseGhostId('ghost-tree-item')unless consumeridis provided),tabindex="0"on the single active roving stop andtabindex="-1"on all other items,aria-selected="true" | "false",aria-disabled="true"when disabled.- When a
GhostTreeGroupis registered insideGhostTreeItem: setsaria-expanded="true" | "false"andaria-controls="<groupId>". - When no
GhostTreeGroupis registered (leaf node): omitsaria-expandedandaria-controls. - When a
GhostTreeTriggeris registered insideGhostTreeItemand the consumer did not passaria-labeloraria-labelledbyonGhostTreeItem: setsaria-labelledby="<triggerId>"so the branchtreeitem's accessible name is computed exclusively from its trigger label and never concatenates descendantGhostTreeGroupitems.
- When a
GhostTreeTrigger: defaultas="span",id(fromuseGhostId('ghost-tree-trigger')unless consumeridis provided; the owningGhostTreeItemgenerates the id used by its first labelling trigger so it can reference it before the trigger renders),data-part="trigger". Triggers withaction="toggle"are disclosure affordances and never label the item; the first trigger withaction="both"or"select"is thearia-labelledbytarget. Does not setrole="button"ortabindexsoGhostTreeItem(role="treeitem") has zero nested interactive controls (axe-corenested-interactiverule).GhostTreeGroup:role="group",id(fromuseGhostId('ghost-tree-group')unless consumeridis provided),hiddenwhen collapsed (managed viauseCollapsibleContentHidden), andaria-labelledby="<triggerId>"when its owningGhostTreeItemhas a registeredGhostTreeTrigger(unless consumeraria-labeloraria-labelledbyis provided).
Keyboard interaction
Let expandKey be ArrowRight in LTR (dir="ltr") and ArrowLeft in RTL (dir="rtl"). Let collapseKey be ArrowLeft in LTR and ArrowRight in RTL.
| Key | State / Context | Behavior |
|---|---|---|
Tab / Shift+Tab | Anywhere | Moves focus into and out of the tree as a single Tab stop (tabindex="0"). Never intercepted by GhostTree. |
ArrowDown | On any visible enabled node | Moves focus and roving tabindex="0" to the next visible enabled GhostTreeItem in rendered DOM order (sortByDocumentOrder). Does not change selection or expansion. Wraps to first only when loop=true; at boundary with loop=false, stays on the last item. |
ArrowUp | On any visible enabled node | Moves focus and roving tabindex="0" to the previous visible enabled GhostTreeItem in rendered DOM order. Does not change selection or expansion. Wraps to last only when loop=true; at boundary with loop=false, stays on the first item. |
ArrowRight (LTR) / ArrowLeft (RTL) (expandKey) | On a closed branch node (expandable && !expanded) | Requests expansion (setExpanded(value, true)). Focus remains on the current branch node. |
ArrowRight (LTR) / ArrowLeft (RTL) (expandKey) | On an open branch node (expandable && expanded) | Moves focus and roving tabindex="0" to the first visible enabled child GhostTreeItem inside this branch. If the open branch has no visible enabled children, focus stays on the branch node. |
ArrowRight (LTR) / ArrowLeft (RTL) (expandKey) | On a leaf node (!expandable) | Does nothing. |
ArrowLeft (LTR) / ArrowRight (RTL) (collapseKey) | On an open branch node (expandable && expanded) | Requests collapse (setExpanded(value, false)). Focus remains on the current branch node. |
ArrowLeft (LTR) / ArrowRight (RTL) (collapseKey) | On a closed branch node or leaf node with a visible enabled ancestor | Moves focus and roving tabindex="0" to the closest visible enabled ancestor GhostTreeItem. |
ArrowLeft (LTR) / ArrowRight (RTL) (collapseKey) | On a root-level closed branch node or root-level leaf node (or when no ancestor is enabled) | Does nothing. |
Home | On any visible enabled node | Moves focus and roving tabindex="0" to the first visible enabled GhostTreeItem in the tree. |
End | On any visible enabled node | Moves focus and roving tabindex="0" to the last visible enabled GhostTreeItem in the tree. |
Enter | On any visible enabled node | Selects the focused node in selectionMode="single" (or deselects when already selected and allowDeselect=true), or toggles selection of the focused node in selectionMode="multiple". Does not toggle branch expansion. |
Space (' ') | When typeahead buffer is empty | Selects the focused node in selectionMode="single" (or deselects when allowDeselect=true), or toggles selection of the focused node in selectionMode="multiple" without requiring modifier keys. Prevents page scroll (event.preventDefault()). |
Space (' ') | When typeahead buffer is non-empty | Appends ' ' to the active typeahead query, resets the 500ms typeahead timer, and focuses the matching visible enabled node without toggling selection (event.preventDefault()). |
* (Asterisk) | When typeahead buffer is empty | Expands all closed, enabled sibling branch GhostTreeItems that share the same parent GhostTreeItem (or root level) as the focused node in one update:expanded update. Focus and selection do not change. |
Printable characters (key.length === 1, unmodified) | On any visible enabled node | Appends character to the 500ms typeahead buffer and moves focus (without changing selection) to the matching visible enabled node in rendered DOM order: starting at activeIndex + 1 for 1-character queries, keeping the active node if it still matches when extending multi-character queries (GHO-175), and cycling through same-letter matches on repeated single-character presses ("aa"). |
Alt+*, Ctrl+*, Meta+* chords | Anywhere | Ignored by GhostTree; never calls preventDefault(), never moves focus or mutates state (GHO-168). |
IME composition (isComposing === true or keyCode === 229) | Anywhere | Ignored by GhostTree; never calls preventDefault(), never moves focus, selects, expands, or updates typeahead (GHO-167). |
Focus behavior and recovery
- Single Tab stop: Exactly one visible enabled
GhostTreeItemhastabindex="0"at any time; all otherGhostTreeItems havetabindex="-1". - Initial tab stop (SSR and mount):
- In
selectionMode="single", ifmodelValue(ordefaultValue) matches a visible enabled item, that item receivestabindex="0". - In
selectionMode="multiple", the first visible enabled item in document/registration order whosevalueis inmodelValue(ordefaultValue) receivestabindex="0". - Otherwise, the first visible enabled item receives
tabindex="0". - Before mount, while a selected value has not yet registered (items render one at a time during SSR), earlier items withhold the stop. If the selected value never renders, the server HTML has no
tabindex="0"and the first visible enabled item receives it after mount.
- In
- Visibility definition for navigation and tab stops: A
GhostTreeItemis visible and eligible for focus iff:- It is not disabled (
!rootDisabled && !itemDisabled), - Every ancestor
GhostTreeItemin its parent chain is currently expanded (isExpanded(ancestorValue) === true), AND - When mounted in the client DOM, its element is connected (
element.isConnected) and not hidden by an ancestor[hidden],[inert],[aria-hidden="true"], ordisplay: none(!isHidden(element)). Checking logical ancestor expansion (isExpanded) ensures that as soon as a branch transitions toexpanded = false, its descendants are immediately excluded from focus/navigation even while a themed CSS close transition is still running.
- It is not disabled (
- Collapse of a focused descendant:
- When an ancestor branch collapses while
focusedValueis on a descendant inside that branch (e.g. clicking the ancestor's<GhostTreeTrigger action="toggle">or a controlledexpandedprop update removing the ancestor): focusedValueandtabindex="0"immediately recover to the closest visible enabled ancestorGhostTreeItem(or if no ancestor is enabled, the next visible enabled node, then previous visible enabled node).- If
document.activeElementwas inside the tree on the collapsed descendant,.focus({ preventScroll: true })is called on the recovery target's DOM element so focus is never trapped on ahiddennode or lost todocument.body.
- When an ancestor branch collapses while
- Reordered, inserted, and removed nodes:
- Reordering or inserting
GhostTreeItems via keyedv-forpreserves the currentfocusedValueand re-sorts visible enabled candidates viasortByDocumentOrderon the next key press or focus sync. - Removing/unmounting a
GhostTreeItemremoves it from the live node registry without mutating or emittingupdate:modelValueorupdate:expanded. If the removed item wasfocusedValue,focusedValuerecovers to the next visible enabled item at its prior position, else the previous visible enabled item, else its closest visible enabled ancestor, else the first visible enabled item (and moves DOM.focus({ preventScroll: true })onnextTickif the removed item helddocument.activeElement).
- Reordering or inserting
Assistive technology expectations
- Screen readers announce the tree name,
treeitemrole, selected state (aria-selected), expanded/collapsed state (aria-expandedon branches only), disabled state (aria-disabled), and hierarchical level/position from the nested<ul role="tree"> -> <li role="treeitem"> -> <ul role="group">structure. - Branch
GhostTreeItems automatically linkaria-labelledbyto their registeredGhostTreeTriggerID (when no explicitaria-label/aria-labelledbyis passed) so screen readers read only the branch's own label rather than concatenating childGhostTreeGrouptext.
Rendering and customization
Styling hooks (data-part, data-state, and secondary data-* attributes)
| Component | Class | data-part | data-state | Secondary data-* & CSS variables |
|---|---|---|---|---|
GhostTree | ghost-tree | root | — | data-ghost-tree="", data-dir="ltr" | "rtl", data-disabled="" (when disabled) |
GhostTreeItem | ghost-tree-item | item | 'checked' (when selected), 'disabled' (when disabled and unselected), absent when idle | data-ghost-tree-value="<value>", data-selected="" (when selected), data-expanded="true" | "false" (on branch items only), data-disabled="" (when disabled), data-level="<number>" (1-based depth), --ghost-tree-level: <number> |
GhostTreeTrigger | ghost-tree-trigger | trigger | 'open' | 'closed' (on branch items), 'checked' (on selected leaf items), absent when idle leaf | data-selected="" (when selected), data-disabled="" (when disabled) |
GhostTreeGroup | ghost-tree-group | group | 'open' | 'closed' | data-animation="off" (when disableAnimation=true) |
Themed CSS (packages/themes/src/ghost-tree.css)
- Authored under
@layer ghostvue-themeusing only semantic--ghost-*tokens (--ghost-surface-fg,--ghost-surface-muted-bgfor selected rows,--ghost-elevation-2-bgfor hovered rows,--ghost-radius-sm,--ghost-space-inset-xs,--ghost-space-inset-sm,--ghost-space-inset-md,--ghost-space-gap-xs,--ghost-type-family-sans,--ghost-type-feature-default,--ghost-type-size-sm,--ghost-type-weight-medium,--ghost-type-line-snug,--ghost-focus-ring-width,--ghost-focus-ring-color,--ghost-focus-ring-offset,--ghost-action-disabled-opacity,--ghost-motion-duration-moderate,--ghost-motion-easing-standard) with zero hardcoded color literals or non-zeropx/ms/s/rem/emvalues. (The design plan named--ghost-action-ghost-bg-hoverand--ghost-action-secondary-bg; those tokens do not exist, so the row states use the same tokens as Select options and menu items.) - Resets
list-style: none; margin: 0; padding: 0;on.ghost-treeand.ghost-tree-group. - Indents nested items via
padding-inline-start: calc((var(--ghost-tree-level, 1) - 1) * var(--ghost-space-inset-md))on the item row so indentation adapts automatically in both LTR and RTL at any depth. - Draws the
:focus-visibleoutline on.ghost-tree-item:focus-visible > [data-part='trigger'](withoutline: noneon the outer.ghost-tree-item) when aGhostTreeTriggeris present, and directly on.ghost-tree-item:focus-visible:not(:has(> [data-part='trigger']))for triggerless leaf items—so the focus ring highlights only the focused node's row and never wraps around an expanded childGhostTreeGroup. - Animates
GhostTreeGroupexpand/collapse under@supports (interpolate-size: allow-keywords)and@media (prefers-reduced-motion: no-preference)usingblock-sizeand@starting-style, collapsing transitions under@media (prefers-reduced-motion: reduce)or[data-animation='off'](matchingghost-collapsible.css). - Supports
@media (forced-colors: active)withHighlight/HighlightTextfor selected/focused indicators andGrayTextfor disabled items.
Environment behavior
SSR and hydration
- Deterministic IDs from
useGhostId(ghost-tree-item,ghost-tree-trigger,ghost-tree-group) populatearia-controlsandaria-labelledbyidentically on server and client. - An item's attributes are serialized before its child parts run
setup(). So thataria-expanded,aria-controls, andaria-labelledbyare present in server HTML,GhostTreeItemscans the vnodes its own slot returns for aGhostTreeGroupand a labellingGhostTreeTrigger(matched by component name, so the themed wrappers count, reading a consumeridwhen given). The scan descends through elements and fragments but not into other components; parts hidden inside consumer wrapper components are picked up by client registration after hydration instead. - Closed
GhostTreeGroupelements render in SSR HTML withhiddenanddata-state="closed"; open groups render withouthiddenand withdata-state="open". - Zero
window,document,MutationObserver, ormatchMediaaccess duringsetup(). - Initial
tabindex="0"vstabindex="-1"is computed deterministically frommodelValue/defaultValueandexpanded/defaultExpandedduring SSR render so hydration produces zero attribute mismatches.
Mobile and touch
- Pointer clicks on
GhostTreeTriggerorGhostTreeItemactivate selection/expansion perexpandOnClickandactionwithout hover-only affordances. - Themed row height and padding provide comfortable touch targets using
--ghost-space-inset-xs/--ghost-space-inset-sm.
Performance
- Node registration uses a
Map<string, GhostTreeNodeRecord>with a monotonicregistryVersioncounter so mounting/unmounting $N$ nodes is $O(N)$ without cloning arrays on every item mount (GHO-176). sortByDocumentOrderruns lazily on keyboard navigation, typeahead, or roving tab-stop recovery rather than on every registration call.- Never deep-watches consumer data; only primitive key props (
value,disabled,textValue) and controlledmodelValue/expandedrefs are watched.
Composition
- Reuses
useControllableState,useGhostId,useCollapsibleContentHidden,collapsibleHostAllowsAnimationShell,sortByDocumentOrder, andisDisabledElementfrompackages/vue/src/. - Does not delegate keyboard navigation to
GhostCollapsibleor 1DuseRovingFocus:GhostCollapsibleis a single disclosure primitive anduseRovingFocusis a 1D flat rover, whereasGhostTreerequires hierarchical parent/childArrowRight/ArrowLeftexpansion and traversal,*sibling expansion, and focus recovery on ancestor collapse.
Test plan
- Unit / composable (
packages/vue/src/use-ghost-tree.test.ts&packages/vue/src/GhostTree.test.ts):- Uncontrolled and controlled
modelValue(singleandmultiple),allowDeselect, andexpanded(v-model:expanded). - Controlled update rejection for both
modelValueandexpanded(verifyingaria-selected,aria-expanded,data-state,hidden, and thatArrowRighton a rejected closed branch does not move focus into hidden children). - Independent focus vs selection across all navigation keys (
ArrowDown,ArrowUp,ArrowRight,ArrowLeft,Home,End,Shift+Arrow, typeahead). - Independent nested selection (selecting parent does not select children; selecting all children does not select parent).
- RTL arrow reversal (
dir="rtl"on prop, ancestor[dir="rtl"], ordocument.documentElement.dir = 'rtl'). *expands all closed enabled sibling branches at the same level without moving focus.- Disabled root, disabled branch (including pre-expanded disabled branch with enabled children and
ArrowLeftskipping disabled parent to closest enabled ancestor), and disabled leaf items. - Collapse of an ancestor while a descendant holds focus / roving tab stop -> immediate focus recovery to closest visible enabled ancestor.
- Dynamic keyed reorder, insertion before/after active stop, and removal/unmount of active/selected/expanded node (preserving
modelValueandexpandedwithout spurious events while recovering focus). - Typeahead matching, 500ms timer reset,
Spacein active query vs standaloneSpaceselection, multi-character prefix continuation (GHO-175), repeated single-character cycling ("aa"),textValueoverride, excluding collapsed descendants, and ignoring IME composition (isComposing: trueandkeyCode: 229,GHO-167) andAlt/Ctrl/Metachords (GHO-168). GhostTreeTriggeraction="both" | "toggle" | "select"andGhostTreeexpandOnClick=false.- SSR
renderToString+ client hydration (tests/integration/ssr-hydration.test.ts) with zero mismatches and no leaked timers/listeners on unmount.
- Uncontrolled and controlled
- Theme & integration (
tests/integration/ghost-tree-themed.test.ts&tests/integration/ghost-tree-theme-css.test.ts):- Themed wrapper forwarding (
data-themed, class/style merging, exposedelement/focus/blur) with >= 80% coverage. - CSS token audit verifying
--ghost-*usage and zero hardcoded color/unit/time literals.
- Themed wrapper forwarding (
- Browser / Playwright (
tests/e2e/ghost-tree.spec.ts):- Real browser focus (
toBeFocused()) and ARIA state assertions across every documented key (ArrowDown,ArrowUp,ArrowRight,ArrowLeft,Home,End,*,Enter,Space, typeahead, modified keys ignored). - Single-select and multi-select (
Spacetoggles without modifiers) in real Chromium. - RTL tree fixture verifying
ArrowLeftexpands/enters child andArrowRightcollapses/moves to parent. - Focus recovery when collapsing an ancestor of the focused item via pointer click on
<GhostTreeTrigger action="toggle">. - Axe-core zero violations across collapsed and expanded states (
nested-interactive,aria-required-children,aria-required-parent, accessible names).
- Real browser focus (
- Type tests (
packages/vue/type-tests/):- Positive and negative compile-time checks for
GhostTree,GhostTreeItem(requiringvalue: string),GhostTreeTrigger,GhostTreeGroup, anduseGhostTree.
- Positive and negative compile-time checks for
Documentation plan
- Canonical spec at
docs/components/tree-spec.mdand public component guide atdocs/components/tree.md. - Five executable examples under
examples/tree/:examples/tree/basic.vue— single-selection file/folder hierarchy with expand/collapse and keyboard navigation.examples/tree/multi-select.vue—selectionMode="multiple"with independent focus andSpacetoggling plus controlledv-modelandv-model:expanded.examples/tree/split-trigger.vue— split<GhostTreeTrigger action="toggle">chevron and<GhostTreeTrigger action="select">label withexpandOnClick=false.examples/tree/rtl.vue—dir="rtl"localized hierarchy demonstrating flippedArrowLeft/ArrowRightexpansion and traversal.examples/tree/themed.vue—@ghostvue/themesstyled tree with depth indentation and collapsible height motion.
- Playground reference section in
apps/playground/src/App.vueexercising single, multi-select, RTL, and dynamic node insertion/removal.
Compatibility and release impact
- Additive minor exports in
@ghostvue/vueand@ghostvue/themes. - Requires a minor Changeset (
.changeset/gho-105-ghost-tree.md) for both@ghostvue/vueand@ghostvue/themes. - Updates row 46 (
GhostTree) indocs/roadmap.mdviapackages/vue/registry/tree.registry.jsonandpnpm registries:write.
Open architectural questions
None. All design and behavioral contracts required by GHO-105 are resolved above.