Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-tree>

@methane-ui/ui~12.3 KB brotli (cold + Lit)~4.4 KB marginal

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

Interactive StageLive Custom Element · <mth-tree> (@methane-ui/ui)
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>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
selectionModeselection-mode'none' | 'single' | 'multiple'"single"Selection behavior (none, single, or multiple).
valuevaluestring""Currently selected node value in single-selection mode.
values—ReadonlyArray<string>—Array of selected node values.
items—ReadonlyArray<unknown> | nullnullHierarchical TreeNodeData[] array for data-driven or virtualized trees.
dataSource—unknown | nullnullAsync DataSource<TreeNodeData, string> backing the tree.
expandedValues—ReadonlyArray<string>—Array of expanded node IDs in data-driven mode.
virtualizedvirtualizedbooleanfalseEnables windowed rendering via VirtualizerController.
itemHeightitem-heightnumber32Estimated row height in pixels for virtualization.
labellabelstring""Accessible label for the role="tree" landmark.

Events

EventDetail TypeDescription
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

KeyDirectionWhenExpected Behavior
ArrowDownbothA treeitem has focusMoves focus to next visible enabled treeitem
ArrowUpbothA treeitem has focusMoves focus to previous visible enabled treeitem
ArrowRightltrA treeitem has focus in LTRExpands closed branch or moves focus to first child
ArrowLeftltrA treeitem has focus in LTRCollapses open branch or moves focus to parent
ArrowLeftrtlA treeitem has focus in RTLExpands closed branch or moves focus to first child
ArrowRightrtlA treeitem has focus in RTLCollapses open branch or moves focus to parent
HomebothA treeitem has focusMoves focus to first visible enabled treeitem
EndbothA treeitem has focusMoves focus to last visible enabled treeitem
EnterbothA treeitem has focusSelects focused treeitem and emits mth-change
bothA treeitem has focusSelects focused treeitem and emits mth-change
*bothA treeitem has focusExpands all sibling branch items at the current level

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusFocus ownership matches focusModel="none" with host role="tree".lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
keyboardImplements all 11 APG keyboard transitions across LTR/RTL.mth-tree.spec.test.ts
statesExposes ElementInternals CustomStateSet flags: :state(loading), :state(empty), :state(error), :state(virtualized).Conformance suite
i18nRoutes 5 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test