← All Components
<mth-tree>
WAI-ARIA APG hierarchical treeview (role="tree") with LTR/RTL arrow expand/collapse, typeahead, SelectionController, DataController, SlotCollectionController, and VirtualizerController.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-tree>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/tree"></script>
<mth-tree selection-mode="none" item-height="32">Example</mth-tree>import '@methane-ui/ui/tree';
import '@methane-ui/react';
export function Example() {
return <mth-tree selection-mode="none" item-height="32">Example</mth-tree>;
}<script setup lang="ts">
import '@methane-ui/ui/tree';
</script>
<template>
<mth-tree selection-mode="none" item-height="32">Example</mth-tree>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/tree';
import { MthTreeDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthTreeDirective],
template: `<mth-tree selection-mode="none" item-height="32">Example</mth-tree>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/tree';
import MthTree from '@methane-ui/svelte/MthTree.svelte';
</script>
<MthTree selection-mode="none" item-height="32">Example</MthTree>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
selectionMode | selection-mode | 'none' | 'single' | 'multiple' | "single" | Selection behavior (none, single, or multiple). |
value | value | string | "" | Currently selected node value in single-selection mode. |
values | — | ReadonlyArray<string> | — | Array of selected node values. |
items | — | ReadonlyArray<unknown> | null | null | Hierarchical TreeNodeData[] array for data-driven or virtualized trees. |
dataSource | — | unknown | null | null | Async DataSource<TreeNodeData, string> backing the tree. |
expandedValues | — | ReadonlyArray<string> | — | Array of expanded node IDs in data-driven mode. |
virtualized | virtualized | boolean | false | Enables windowed rendering via VirtualizerController. |
itemHeight | item-height | number | 32 | Estimated row height in pixels for virtualization. |
label | label | string | "" | Accessible label for the role="tree" landmark. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-change | { value: string; values: ReadonlyArray<string> } | Emitted when tree selection changes. |
mth-expand | { value: string } | Emitted when a branch node expands. |
mth-collapse | { value: string } | Emitted when a branch node collapses. |
mth-data-state | { status: unknown; count: number } | Emitted when DataController transitions state. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| ArrowDown | both | A treeitem has focus | Moves focus to next visible enabled treeitem |
| ArrowUp | both | A treeitem has focus | Moves focus to previous visible enabled treeitem |
| ArrowRight | ltr | A treeitem has focus in LTR | Expands closed branch or moves focus to first child |
| ArrowLeft | ltr | A treeitem has focus in LTR | Collapses open branch or moves focus to parent |
| ArrowLeft | rtl | A treeitem has focus in RTL | Expands closed branch or moves focus to first child |
| ArrowRight | rtl | A treeitem has focus in RTL | Collapses open branch or moves focus to parent |
| Home | both | A treeitem has focus | Moves focus to first visible enabled treeitem |
| End | both | A treeitem has focus | Moves focus to last visible enabled treeitem |
| Enter | both | A treeitem has focus | Selects focused treeitem and emits mth-change |
both | A treeitem has focus | Selects focused treeitem and emits mth-change | |
| * | both | A treeitem has focus | Expands all sibling branch items at the current level |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | Focus ownership matches focusModel="none" with host role="tree". | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 11 APG keyboard transitions across LTR/RTL. | mth-tree.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(loading), :state(empty), :state(error), :state(virtualized). | Conformance suite |
| i18n | Routes 5 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |