Tree
Installation
Section titled “Installation”Copy editable source into an initialized application:
pnpm dlx @simurgh-ui/cli add treeFor package consumption, import from the component subpath and load its optional recipe CSS:
import { Tree, TreeItem,} from '@simurgh-ui/react/tree';import '@simurgh-ui/styles/tree.css';import { Tree, TreeItem,} from '@simurgh-ui/vue/tree';import '@simurgh-ui/styles/tree.css';Angular
Section titled “Angular”import { TreeDirective, TreeItemComponent,} from '@simurgh-ui/angular/tree';import '@simurgh-ui/styles/tree.css';Omit the component stylesheet for fully headless styling. CLI-copied components use the local path
written to simurgh.json and the copied application styles instead of these package imports.
Purpose
Section titled “Purpose”Tree presents nested data as one keyboard stop. Arrow Up and Arrow Down move through visible items, Home and End jump to boundaries, and Arrow Right and Arrow Left expand, collapse, and move between parent and child items.
Default presentation: styled
Section titled “Default presentation: styled”The optional component stylesheet provides a complete default recipe, including visual hierarchy and interaction states. Consumers can override semantic tokens or omit the recipe.
Basic usage
Section titled “Basic usage”Anatomy
Section titled “Anatomy”The public component parts are listed in API surface below. Use only the parts needed by the example; compound components depend on their documented parent/child nesting.
State model
Section titled “State model”Controlled state remains the application’s source of truth and must be updated from every change event. Uncontrolled state reads its default only when the component mounts. Do not pass both forms of the same state at once.
| Framework | Exact state contract and reset behavior |
|---|---|
| React | No public controlled/uncontrolled state pair is exposed. |
| Vue | Controlled: v-model:expanded (expanded + update:expanded). Uncontrolled: defaultExpanded. Reset the model ref to its initial value; reset uncontrolled state with a changed Vue :key. |
| Angular | Controlled two-way binding: [(expanded)] (expanded + expandedChange). Angular exposes no separate default input; initialize and reset the bound class field explicitly. |
Vue
<script setup lang="ts">import { ref } from 'vue';const initial = false;const state = ref(initial);const resetKey = ref(0);</script>
<Tree v-model:expanded="state">…</Tree><button @click="state = initial">Reset controlled</button><Tree :key="resetKey" :defaultExpanded="initial">…</Tree><button @click="resetKey++">Reset uncontrolled</button>Angular
initial = false;expanded = this.initial;reset() { this.expanded = this.initial; }<simurgh-tree [(expanded)]="expanded">…</simurgh-tree><button type="button" (click)="reset()">Reset</button>Use Tree for hierarchical data, not site navigation. Supply a concise label on the root, keep item labels unique within their branch, and mark unavailable nodes disabled. Controlled expanded state is available when expansion must be synchronized with application state.
Examples
Section titled “Examples”<Tree aria-label="Files"> <TreeItem label="Documents" defaultExpanded> <TreeItem label="Guide" /> <TreeItem label="Locked" disabled /> </TreeItem> <TreeItem label="Images" /></Tree><Tree aria-label="Files"> <TreeItem label="Documents" default-expanded> <TreeItem label="Guide" /> <TreeItem label="Locked" disabled /> </TreeItem> <TreeItem label="Images" /></Tree><ul simurghTree aria-label="Files"> <simurgh-tree-item label="Documents" [expandable]="true" [expanded]="true"> <simurgh-tree-item label="Guide" /> <simurgh-tree-item label="Locked" [disabled]="true" /> </simurgh-tree-item> <simurgh-tree-item label="Images" /></ul>Keyboard interactions
Section titled “Keyboard interactions”These keys describe behavior implemented by the adapters. Native Tab, Enter, and Space behavior still applies to descendant links, buttons, and form controls unless the component overrides it.
| Concern / keys | Behavior |
|---|---|
| Focus entry and exit (Tab / Shift+Tab) | Tab enters at the current tree item and leaves after the tree. |
| Navigation and activation | Arrow Up/Down moves visible items; Right expands/enters; Left collapses/returns; Home/End moves to edges. |
| Escape | Not handled by the component. |
| RTL differences | Tree expand/collapse arrows remain semantic Right/Left in both directions. |
| Typeahead | Not supported. |
Accessibility
Section titled “Accessibility”Preserve the documented composition and accessible names when wrapping or restyling this component. See accessibility and RTL guidance for keyboard, focus, labeling, and directionality requirements.
API surface
Section titled “API surface”- React exports:
Tree,TreeItem - Vue exports:
Tree,TreeItem - Angular exports:
TreeDirective,TreeItemComponent
Import these public symbols from the component subpath shown in Installation. Framework-specific props, events, slots, directives, methods, defaults, and native-attribute behavior belong in the API tables on this page; use the linked source only to verify the current implementation.
React API reference
An inherited-attributes entry means the component accepts the complete named React native interface, including its event handlers and ARIA and data attributes. Remaining attributes are forwarded to the rendered element unless the component behavior described on this page overrides them.
Inherited attributes: HTMLAttributes<HTMLUListElement>.
| Prop | Type | Default / requirement |
|---|---|---|
children | ReactNode | undefined |
TreeItem
Section titled “TreeItem”Complete props type: TreeItemProps.
| Prop | Type | Default / requirement |
|---|---|---|
children | React.ReactNode | undefined |
defaultExpanded | boolean | undefined |
disabled | boolean | undefined |
expandable | boolean | undefined |
expanded | boolean | undefined |
label | React.ReactNode | Required |
onExpandedChange | (expanded: boolean) => void | undefined |
Vue API reference
Boolean props without explicit defaults use Vue’s false default. Undeclared attributes follow
the fallthrough behavior stated for each component.
Automatic fallthrough is disabled; attrs are manually forwarded to the rendered root.
No declared props.
No emitted events.
Slots: default.
Exposed methods: none.
TreeItem
Section titled “TreeItem”Automatic fallthrough is disabled; attrs are manually forwarded to the rendered root.
| Prop | Type | Default / requirement |
|---|---|---|
label | string | Required |
expandable | boolean | undefined |
expanded | boolean | undefined |
defaultExpanded | boolean | false |
disabled | boolean | false |
| Event | Payload |
|---|---|
update:expanded | boolean |
Slots: default.
Exposed methods: none.
Angular API reference
Angular
Section titled “Angular”Inputs and outputs use their public template names. Public methods are callable through a template
reference or ViewChild. Native attributes apply to the documented template root or directive host;
they are not automatically forwarded through component hosts.
TreeDirective
Section titled “TreeDirective”Attribute directive selector: ul[simurghTree]; behavior applies to its host element.
No inputs.
No outputs.
Content projection: none.
| Public method |
|---|
onKeydown(event: KeyboardEvent): void |
TreeItemComponent
Section titled “TreeItemComponent”Component selector: simurgh-tree-item. The template’s first native element is button. Angular host bindings: { role: 'none', 'data-slot': 'tree-node' }.
| Input | Type | Default / requirement |
|---|---|---|
label | string | '' |
expandable | boolean | false |
expanded | boolean | false |
disabled | boolean | false |
| Output | Payload |
|---|---|
expandedChange | boolean |
Content projection: default.
| Public method |
|---|
toggle(): void |
Composition contract
Section titled “Composition contract”Follow the framework example as a structural contract. Root components own shared state; parts that consume that state must stay under the root (or be attached to projected descendants in Angular). Parts described as conditional are optional until their corresponding interaction or semantic region is used. Do not render a state-consuming part by itself.
| Framework | Required parent/child relationship | Conditional parts | Supporting types |
|---|---|---|---|
| React | Render Tree as the ancestor. Nest the listed parts inside that root so they can read its shared state/context. | TreeItem are conditional parts: include only those needed by the documented anatomy. A trigger/control and its matching content/item are required when that interaction is used. | None. |
| Vue | Render Tree as the ancestor. Nest the listed parts inside that root so they can read its shared state/context. | TreeItem are conditional parts: include only those needed by the documented anatomy. A trigger/control and its matching content/item are required when that interaction is used. | None. |
| Angular | Create TreeItemComponent first. Attach listed directives to elements inside its projected content; nested component parts must remain inside it. | TreeDirective are conditional parts: include only those needed by the documented anatomy. A trigger/control and its matching content/item are required when that interaction is used. | None. |
Accessible names, descriptions, and form labels remain required whenever the component’s purpose cannot otherwise be determined, even when the corresponding visual part is optional.
Framework parity and differences
Section titled “Framework parity and differences”The adapters target the same user-visible behavior and accessibility contract. Their public shapes follow each framework’s conventions and are not expected to be symbol-for-symbol identical.
| Concern | Contract |
|---|---|
| Public composition | All adapters export 2 public symbols, with framework-idiomatic names. |
| State and change events | React uses controlled/default props and callbacks for expanded; Vue uses v-model:expanded; Angular uses [(expanded)]. |
| Children and content | React uses children; Vue uses the slots listed above; Angular uses the documented content projection selectors. |
| Native attributes | React forwards the named native interface; Vue follows the stated fallthrough rule; Angular attributes apply to the component host unless an input, directive, or documented native root consumes them. |
| Imperative access | React has no forwarded ref; Vue exposes no methods; Angular exposes the listed class methods through a template reference or ViewChild. |
These differences are intentional adapter design. Behavioral or accessibility differences not stated on this page are parity defects rather than supported variations.
Form integration
Section titled “Form integration”This component is not a form control and does not contribute a named value to FormData. Use it
to structure or describe a form only when its purpose and accessibility guidance apply.
Supported states
Section titled “Supported states”The table distinguishes component behavior from application-owned presentation. “Not supported” means there is no public state contract for that adapter; do not invent one with an undocumented attribute. Keep status and error messages accessible when they are rendered outside the component.
| State | React | Vue | Angular |
|---|---|---|---|
| Loading | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. |
| Empty | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. |
| Invalid | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. |
| Read-only | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. |
| Disabled | Supported with disabled={true} on the documented control or interactive part; its interaction is blocked. Disabled form controls are omitted from submission. | Supported with :disabled="true" on the documented control or interactive part; its interaction is blocked. Disabled form controls are omitted from submission. | Supported with [disabled]="true" on the documented control or interactive part; its interaction is blocked. Disabled form controls are omitted from submission. |
| Error | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. | Not supported by this component API; handle this state in surrounding application UI. |
Styling contract
Styling contract
Section titled “Styling contract”The selectors below are used by the published component recipe or emitted consistently by an adapter. Treat these as the supported styling surface. Element order, anonymous wrappers, and undocumented descendants are implementation details and should not be targeted.
| Surface | Stable hooks |
|---|---|
| Recipe classes | No component-specific recipe class; this stylesheet currently imports shared tokens only. |
| Stable DOM parts | [data-slot="tree"], [data-slot="tree-group"], [data-slot="tree-item"], [data-slot="tree-node"] |
| Stable data attributes | [data-slot] |
| ARIA/state selectors used by the recipe | [aria-expanded] |
| CSS custom properties consumed | --simurgh-accent, --simurgh-ring |
Prefer a semantic token override for theme-wide changes. Use the listed class or part selectors for a component-scoped override. When omitting recipe CSS, preserve state attributes and ARIA semantics even if your replacement styles use different selectors.
Customization
Section titled “Customization”Load the optional component stylesheet for the default recipe, override semantic tokens for broad theme changes, or omit the recipe CSS for headless styling. See theming and styling hooks for import order, selectors, dark mode, RTL, and reduced-motion guidance.
Last verified on 2026-08-13 against Simurgh registry 0.1.1.
Related components
Section titled “Related components”- Review the shared accessibility and RTL guidance and theming and styling hooks.
- Use the component chooser and component overview to compare related primitives.
- Inspect the registry manifest and framework source for React, Vue, or Angular.