@methane-ui/ui~7.9 KB brotli (cold + Lit)~2.0 KB marginalHierarchical collapsible navigation tree with WAI-ARIA tree/treeitem keyboard navigation, LTR/RTL branch expand/collapse, roving focus, and safe URL validation.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Documentation
Ready · interact with <mth-tree-nav>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/tree-nav"></script>
<mth-tree-nav></mth-tree-nav>
import '@methane-ui/ui/tree-nav';
import '@methane-ui/react';
export function Example() {
return <mth-tree-nav></mth-tree-nav>;
}
<script setup lang="ts">
import '@methane-ui/ui/tree-nav';
</script>
<template>
<mth-tree-nav></mth-tree-nav>
</template>
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/tree-nav';
import { MthTreeNavDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthTreeNavDirective],
template: `<mth-tree-nav></mth-tree-nav>`,
})
export class ExampleComponent {}
<script lang="ts">
import '@methane-ui/ui/tree-nav';
import MthTreeNav from '@methane-ui/svelte/MthTreeNav.svelte';
</script>
<MthTreeNav></MthTreeNav>
Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|
label | label | string | "" | Accessible label for the <nav> landmark and tree. |
activeValue | active-value | string | "" | Value of the currently active node marked aria-current="page". |
activeHref | active-href | string | "" | Href of the currently active node marked aria-current="page". |
expandedValues | — | ReadonlyArray<string> | [] | Values of currently expanded branch nodes. |
items | — | ReadonlyArray<unknown> | [] | Nested tree structure of navigation nodes. |
Events
| Event | Detail Type | Description |
|---|
mth-select | { value: string; label: string; href?: string } | Fired when a tree navigation node is activated. |
mth-toggle | { value: string; expanded: boolean } | Fired when a branch node expands or collapses. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|
| ArrowDown | both | treeitem focused | moves focus to next visible enabled treeitem |
| ArrowUp | both | treeitem focused | moves focus to previous visible enabled treeitem |
| ArrowRight | ltr | branch treeitem focused | expands collapsed branch or enters first child |
| ArrowLeft | ltr | branch or child treeitem focused | collapses expanded branch or focuses parent |
| Home | both | treeitem focused | moves focus to first visible enabled treeitem |
| End | both | treeitem focused | moves focus to last visible enabled treeitem |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 6 APG keyboard transitions across LTR/RTL. | mth-tree-nav.spec.test.ts |
| i18n | Routes 2 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |