You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/web/routes/uix/components/tree-view/+page.svelte

614 lines
26 KiB

<script lang="ts">
import {
TreeView,
type TreeViewSize,
type TreeViewVariant,
type TreeViewColor,
type TreeViewSelectionMode
} from '$uix/eidos/components/tree-view';
import { compileMorfo } from '$uix/morfo';
import { treeViewMorfo } from '@/uix/morfo/components/tree-view';
import { getActiveUix } from '$active-uix';
const uix = getActiveUix();
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
let tab = $state<Tab>('live');
// ── Sample data ──────────────────────────────────────────────────────
type Leaf = { kind: 'item'; value: string; label: string };
type Folder = { kind: 'branch'; value: string; label: string; children: TreeNode[] };
type TreeNode = Leaf | Folder;
const FILES: TreeNode[] = [
{ kind: 'item', value: 'readme', label: 'README.md' },
{ kind: 'item', value: 'license', label: 'LICENSE' },
{
kind: 'branch',
value: 'src',
label: 'src',
children: [
{ kind: 'item', value: 'index', label: 'index.ts' },
{ kind: 'item', value: 'app', label: 'App.svelte' },
{
kind: 'branch',
value: 'components',
label: 'components',
children: [
{ kind: 'item', value: 'button', label: 'Button.svelte' },
{ kind: 'item', value: 'input', label: 'Input.svelte' },
{
kind: 'branch',
value: 'forms',
label: 'forms',
children: [
{ kind: 'item', value: 'field', label: 'Field.svelte' },
{ kind: 'item', value: 'form', label: 'Form.svelte' }
]
}
]
},
{
kind: 'branch',
value: 'lib',
label: 'lib',
children: [
{ kind: 'item', value: 'utils', label: 'utils.ts' },
{ kind: 'item', value: 'types', label: 'types.ts' }
]
}
]
},
{
kind: 'branch',
value: 'tests',
label: 'tests',
children: [
{ kind: 'item', value: 'unit', label: 'unit.spec.ts' },
{ kind: 'item', value: 'e2e', label: 'e2e.spec.ts' }
]
},
{ kind: 'item', value: 'package', label: 'package.json' }
];
// ── Visual props ─────────────────────────────────────────────────────
let size = $state<TreeViewSize>('md');
let variant = $state<TreeViewVariant>('surface');
let color = $state<TreeViewColor>('primary');
let block = $state(true);
let showIndentGuides = $state(true);
let useScrollRegion = $state(false);
// ── i18n controls ────────────────────────────────────────────────────
let locale = $state('en-US');
let dir = $state<'ltr' | 'rtl'>('ltr');
// ── Soma feature controls ────────────────────────────────────────────
let selectionMode = $state<TreeViewSelectionMode>('single');
let expandOnClick = $state(true);
let typeahead = $state(true);
let expandedValue = $state<string[]>(['src', 'components']);
let selectedValue = $state<string[]>([]);
// ── Trace ────────────────────────────────────────────────────────────
type TraceEntry = { event: string; family: string; intent?: string; at: number };
let trace = $state<TraceEntry[]>([]);
let stageRef = $state<HTMLElement | null>(null);
$effect(() => {
const el = stageRef;
if (!el) return;
const obs = new MutationObserver((mutations) => {
for (const m of mutations) {
if (m.attributeName !== 'data-event') continue;
const target = m.target as Element;
const ev = target.getAttribute('data-event');
if (!ev) continue;
trace = [
{
event: ev,
family: target.getAttribute('data-event-family') ?? '—',
intent: target.getAttribute('data-event-intent') ?? undefined,
at: Date.now()
},
...trace
].slice(0, 6);
}
});
obs.observe(el, { attributes: true, subtree: true, attributeFilter: ['data-event'] });
return () => obs.disconnect();
});
const compiled = compileMorfo(treeViewMorfo);
const partsList = $derived([...compiled.parts.byKebab.values()]);
const events = $derived([...compiled.actions.byName.values()]);
function fmtTime(at: number): string {
const d = new Date(at);
return `${String(d.getSeconds()).padStart(2, '0')}.${String(d.getMilliseconds()).padStart(3, '0')}`;
}
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { TreeView } from '$uix/eidos/components/tree-view';",
' let expandedValue = $state<string[]>([]);',
' let selectedValue = $state<string[]>([]);',
'</' + 'script>',
'',
'<TreeView',
' bind:expandedValue',
' bind:selectedValue',
selectionMode !== 'single' && ` selectionMode="${selectionMode}"`,
dir !== 'ltr' && ` dir="${dir}"`,
!expandOnClick && ' expandOnClick={false}',
!typeahead && ' typeahead={false}',
size !== 'md' && ` size="${size}"`,
variant !== 'surface' && ` variant="${variant}"`,
color !== 'primary' && ` color="${color}"`,
!block && ' block={false}',
showIndentGuides && ' showIndentGuides',
useScrollRegion && ' maxHeight="16rem"',
'>',
' <TreeView.Branch value="src" depth={0}>',
' <TreeView.BranchControl>',
' <TreeView.BranchIndentGuide />',
' <TreeView.BranchIndicator />',
' <TreeView.Label>src</TreeView.Label>',
' </TreeView.BranchControl>',
' <TreeView.BranchContent>',
' <TreeView.Item value="index" depth={1}>',
' <TreeView.Label>index.ts</TreeView.Label>',
' </TreeView.Item>',
' </TreeView.BranchContent>',
' </TreeView.Branch>',
'</TreeView>'
]
.filter(Boolean)
.join('\n')
);
</script>
{#snippet renderNode(node: TreeNode, depth: number)}
{#if node.kind === 'item'}
<TreeView.Item value={node.value} {depth}>
<span style="flex: 0 0 auto; opacity: 0.6;">📄</span>
<TreeView.Label>{node.label}</TreeView.Label>
</TreeView.Item>
{:else}
<TreeView.Branch value={node.value} {depth}>
<TreeView.BranchControl>
<TreeView.BranchIndentGuide />
<TreeView.BranchIndicator />
<span style="flex: 0 0 auto;">📁</span>
<TreeView.Label>{node.label}</TreeView.Label>
</TreeView.BranchControl>
<TreeView.BranchContent>
{#each node.children as child (child.value)}
{@render renderNode(child, depth + 1)}
{/each}
</TreeView.BranchContent>
</TreeView.Branch>
{/if}
{/snippet}
<div data-uix-canvas-inner {dir}>
<header>
<div data-uix-eyebrow>Data · TreeView</div>
<h1 data-uix-page-title>TreeView</h1>
<p data-uix-page-lede>
Hierarchical tree with expandable branches and selectable items.
Implements the full WAI-ARIA TreeView pattern — arrow-key roving
tabindex, expand/collapse, typeahead, <code>*</code>-expand-siblings.
Use TreeView when nodes share the parent shape (file trees,
nav menus, org charts); use <code>Accordion</code> for flat
disclosure, <code>TreeGrid</code> for hierarchical tabular data,
<code>GridList</code> / <code>Listbox</code> for flat lists.
</p>
<div data-uix-page-meta>
<span data-uix-meta-pill>
<span data-uix-meta-key>parts</span>{compiled.parts.order.length}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>events</span>{events.length}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>sizes</span>5
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>apg</span>
<a href={treeViewMorfo.apg} target="_blank" rel="noreferrer">treeview ↗</a>
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>expanded</span> {expandedValue.length}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>selected</span> {selectedValue.length ? selectedValue.join(', ') : '—'}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>locale</span> {locale}
</span>
<span data-uix-meta-pill>
<span data-uix-meta-key>dir</span> {dir}
</span>
</div>
</header>
<div data-uix-stage>
<div data-uix-stage-area bind:this={stageRef} style="padding: var(--uix-space-3); display: flex; justify-content: center;">
<div style="inline-size: min(28rem, 100%);">
<TreeView
bind:expandedValue
bind:selectedValue
{selectionMode}
{expandOnClick}
{typeahead}
{dir}
{size}
{variant}
{color}
{block}
{showIndentGuides}
maxHeight={useScrollRegion ? '16rem' : undefined}
>
{#each FILES as node (node.value)}
{@render renderNode(node, 0)}
{/each}
</TreeView>
</div>
</div>
<div data-uix-stage-trace>
<span data-uix-stage-trace-key>trace</span>
{#if trace.length === 0}
<span>arrow keys to navigate, Enter/Space to select, * to expand siblings…</span>
{:else}
{#each trace.slice(0, 3) as entry (entry.at)}
<span><span data-uix-stage-trace-event>{entry.event}</span> · {entry.family}{entry.intent ? ' · ' + entry.intent : ''}</span>
<span style="color: var(--uix-text-faint)">{fmtTime(entry.at)}</span>
{/each}
{/if}
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>expanded</span> [{expandedValue.join(', ')}]
</span>
</div>
</div>
<div data-uix-tabs role="tablist">
<button data-uix-tab data-active={tab === 'live'} onclick={() => (tab = 'live')}>Live</button>
<button data-uix-tab data-active={tab === 'api'} onclick={() => (tab = 'api')}>
API <span data-uix-tab-count>8</span>
</button>
<button data-uix-tab data-active={tab === 'morfo'} onclick={() => (tab = 'morfo')}>
<span data-uix-layer-badge="morfo">morfo</span>
<span data-uix-tab-count>{partsList.length}p · {events.length}e</span>
</button>
<button data-uix-tab data-active={tab === 'sema'} onclick={() => (tab = 'sema')}>
<span data-uix-layer-badge="sema">sema</span>
<span data-uix-tab-count>{events.length}</span>
</button>
<button data-uix-tab data-active={tab === 'recipe'} onclick={() => (tab = 'recipe')}>Recipe</button>
<button data-uix-tab data-active={tab === 'a11y'} onclick={() => (tab = 'a11y')}>A11y</button>
</div>
{#if tab === 'live'}
<section data-uix-section>
<h2 data-uix-section-title>Controls</h2>
<p data-uix-section-desc>
Soma owns expand/select state, 1D roving tabindex (arrow keys), <code>*</code>-expand-siblings, typeahead, ARIA treeview pattern. Eidos adds visual chrome (variant / size / color), optional indent guides, optional scroll region.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> i18n
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>locale</span>
<select bind:value={locale}>
<option value="en-US">en-US</option>
<option value="es-ES">es-ES</option>
<option value="fr-FR">fr-FR</option>
</select>
</label>
<label data-uix-control>
<span data-uix-control-label>direction</span>
<span data-uix-chips role="radiogroup">
{#each ['ltr', 'rtl'] as value (value)}
<button data-uix-chip data-active={dir === value} onclick={() => (dir = value as 'ltr' | 'rtl')}>{value}</button>
{/each}
</span>
</label>
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> feature toggles
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>selectionMode</span>
<span data-uix-chips role="radiogroup">
{#each ['single', 'multiple'] as m (m)}
<button data-uix-chip data-active={selectionMode === m} onclick={() => (selectionMode = m as TreeViewSelectionMode)}>{m}</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>expandOnClick</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={expandOnClick} />
<span data-uix-switch-label>{expandOnClick ? 'click row toggles' : 'indicator only'}</span>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>typeahead</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={typeahead} />
<span data-uix-switch-label>{typeahead ? 'on' : 'off'}</span>
</span>
</label>
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> visual props
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>variant</span>
<span data-uix-chips role="radiogroup">
{#each ['surface', 'outline', 'ghost'] as v (v)}
<button data-uix-chip data-active={variant === v} onclick={() => (variant = v as TreeViewVariant)}>{v}</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>size</span>
<span data-uix-chips role="radiogroup">
{#each ['xs', 'sm', 'md', 'lg', 'xl'] as s (s)}
<button data-uix-chip data-active={size === s} onclick={() => (size = s as TreeViewSize)}>{s}</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>color</span>
<span data-uix-chips role="radiogroup">
{#each ['primary', 'secondary', 'neutral', 'affirm', 'fulfill', 'risk', 'threat', 'loss'] as c (c)}
<button data-uix-chip data-active={color === c} onclick={() => (color = c as TreeViewColor)}>{c}</button>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>block</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={block} />
<span data-uix-switch-label>{block ? 'on' : 'off'}</span>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>showIndentGuides</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={showIndentGuides} />
<span data-uix-switch-label>{showIndentGuides ? 'on' : 'off'}</span>
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>scrollable</span>
<span data-uix-switch>
<input type="checkbox" bind:checked={useScrollRegion} />
<span data-uix-switch-label>{useScrollRegion ? 'maxHeight=16rem' : 'off'}</span>
</span>
</label>
</div>
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="eidos">eidos</span>
<span>visual · TreeView + Branch + Item recursion</span>
<span data-uix-code-lang>svelte</span>
</div>
<pre><code>{eidosSnippet}</code></pre>
</div>
</section>
{/if}
{#if tab === 'api'}
<section data-uix-section>
<h2 data-uix-section-title>API reference</h2>
<p data-uix-section-desc>
8 parts: <code>Provider · Branch · BranchControl · BranchContent · BranchIndicator · BranchIndentGuide · Item · Label</code>. <code>BranchIndentGuide</code> is opt-in and must live inside a <code>BranchControl</code> (it reads the ancestor Branch's depth). Branches and Items take an explicit <code>depth</code> prop (0-based) — soma writes <code>aria-level</code> + <code>--tree-depth</code> CSS variable for indentation.
</p>
<div data-uix-subsection-head>Provider (TreeView)</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Default</th><th>Description</th></tr></thead>
<tbody>
<tr><td class="name">expandedValue <span data-uix-tag data-kind="bindable">bindable</span></td><td class="type">string[]</td><td class="default">[]</td><td>Open branch values.</td></tr>
<tr><td class="name">selectedValue <span data-uix-tag data-kind="bindable">bindable</span></td><td class="type">string[]</td><td class="default">[]</td><td>Selected node values.</td></tr>
<tr><td class="name">selectionMode</td><td class="type">'single' | 'multiple'</td><td class="default">'single'</td><td>—</td></tr>
<tr><td class="name">expandOnClick</td><td class="type">boolean</td><td class="default">true</td><td>Click row toggles expand; otherwise only the indicator does.</td></tr>
<tr><td class="name">typeahead</td><td class="type">boolean</td><td class="default">true</td><td>Letter keys jump to matching node.</td></tr>
<tr><td class="name">dir</td><td class="type">'ltr' | 'rtl'</td><td class="default">from Soma prefs</td><td>Flips Arrow Left/Right semantics + indent guides.</td></tr>
<tr><td class="name">variant <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">'surface' | 'outline' | 'ghost'</td><td class="default">'surface'</td><td>Container chrome.</td></tr>
<tr><td class="name">size <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">'xs' | 'sm' | 'md' | 'lg' | 'xl'</td><td class="default">'md'</td><td>Row height + indent step + font.</td></tr>
<tr><td class="name">color <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">ColorRole</td><td class="default">'primary'</td><td>Accent for selected items + focus.</td></tr>
<tr><td class="name">block <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">boolean</td><td class="default">true</td><td>Stretch root to container width.</td></tr>
<tr><td class="name">showIndentGuides <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">boolean</td><td class="default">false</td><td>Renders the BranchIndentGuide vertical lines.</td></tr>
<tr><td class="name">maxHeight <span data-uix-tag data-kind="eidos">eidos</span></td><td class="type">string</td><td class="default empty">—</td><td>Wraps the tree in a scrolling region.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>Branch · Item</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Type</th><th>Default</th><th>Description</th></tr></thead>
<tbody>
<tr><td class="name">value</td><td class="type">string</td><td class="default empty">required</td><td>Unique node identifier.</td></tr>
<tr><td class="name">depth</td><td class="type">number</td><td class="default empty">required</td><td>0-based nesting depth — drives <code>aria-level</code> + <code>--tree-depth</code>.</td></tr>
<tr><td class="name">disabled</td><td class="type">boolean</td><td class="default">false</td><td>Skip from selection + keyboard nav.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'morfo'}
<section data-uix-section>
<h2 data-uix-section-title>
<span data-uix-layer-badge="morfo">morfo</span>
· declarative contract
</h2>
<p data-uix-section-desc>Source: <code>src/uix/morfo/components/tree-view.ts</code>.</p>
<div data-uix-subsection-head>Parts</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Part</th><th>Marker</th><th>Element</th><th>Role</th><th>Archetype</th><th>States</th><th>Optional</th></tr></thead>
<tbody>
{#each partsList as part (part.kebab)}
<tr>
<td class="name">{part.kebab}</td>
<td><code data-uix-part-marker>[{part.marker}]</code></td>
<td class="type">&lt;{part.defaultElement}&gt;</td>
<td class="type">{part.role ?? '—'}</td>
<td class="default">{part.archetype ?? '—'}</td>
<td class="default">{part.states.length ? part.states.join(' | ') : '—'}</td>
<td class="default">{part.optional ? 'yes' : 'no'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
<div data-uix-subsection-head>Events declaration</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>name</th><th>family</th><th>verb</th><th>sequence</th><th>intent</th><th>target</th></tr></thead>
<tbody>
{#each events as action (action.name)}
{@const sem = action.semantic}
{@const intentDecl = 'intent' in sem ? sem.intent : undefined}
{@const intentStr = typeof intentDecl === 'string' ? intentDecl : intentDecl ? `fromProp:${(intentDecl as { fromProp?: string }).fromProp ?? '?'}` : '—'}
<tr>
<td class="name">{action.name}</td>
<td class="type">{sem.family}</td>
<td>{sem.verb ?? '—'}</td>
<td>{sem.sequence ?? 'pre'}</td>
<td class="default">{intentStr}</td>
<td>{action.target}</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'sema'}
<section data-uix-section id="sema">
<h2 data-uix-section-title>
<span data-uix-layer-badge="sema">sema</span>
· events
</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Name</th><th>Family</th><th>Verb</th><th>Sequence</th><th>Intent</th><th>Play</th></tr></thead>
<tbody>
{#each events as action (action.name)}
{@const intentDecl = 'intent' in action.semantic ? action.semantic.intent : undefined}
{@const effectiveIntent = typeof intentDecl === 'string' ? intentDecl : undefined}
<tr>
<td class="name">{action.name}</td>
<td class="type">{action.semantic.family}</td>
<td>{action.semantic.verb ?? '—'}</td>
<td>{action.semantic.sequence ?? 'pre'}</td>
<td class="default">{effectiveIntent ?? '—'}</td>
<td>
<button
data-uix-play
onclick={() => {
const target = (stageRef?.querySelector('[data-tree-view-item]') ?? stageRef) as HTMLElement | null;
if (!target) return;
void uix.events?.emit({
name: action.name,
family: action.semantic.family,
target,
...(effectiveIntent ? { intent: effectiveIntent } : {})
});
}}
>▶ play</button>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'recipe'}
<section data-uix-section>
<h2 data-uix-section-title>Eidos recipe</h2>
<p data-uix-section-desc>Selectors at <code>src/uix/eidos/components/tree-view/tree-view.css</code>. Visual data-attrs live on the <code>&lt;div data-tree-view-root&gt;</code> wrapper. Indentation uses the soma-emitted <code>--tree-depth</code> custom property.</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Selector</th><th>Source</th><th>What it paints</th></tr></thead>
<tbody>
<tr><td class="name">[data-tree-view-root]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Wrapper — radius, chrome, scroll cap.</td></tr>
<tr><td class="name">[data-tree-view-root][data-variant]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Border + background per variant.</td></tr>
<tr><td class="name">[data-tree-view-root][data-size]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Row height, indent step, font-size scale.</td></tr>
<tr><td class="name">[data-tree-view-root][data-color]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Accent token cascade.</td></tr>
<tr><td class="name">[data-tree-view-branch-control]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Indented row, hover + selected states, focus ring.</td></tr>
<tr><td class="name">[data-tree-view-branch-control][data-selected]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Selected-row accent-soft fill.</td></tr>
<tr><td class="name">[data-tree-view-branch-content][data-state]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Hide children when collapsed.</td></tr>
<tr><td class="name">[data-tree-view-branch-indicator][data-state]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Chevron rotation (right → down on open).</td></tr>
<tr><td class="name">[data-tree-view-root][data-indent-guides] [data-tree-view-branch-indent-guide]</td><td><span data-uix-tag data-kind="eidos">eidos</span></td><td>Vertical 1px line per depth column.</td></tr>
<tr><td class="name">[data-tree-view-item]</td><td><span data-uix-tag data-kind="soma">morfo</span></td><td>Leaf row, depth-indented.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'a11y'}
<section data-uix-section>
<h2 data-uix-section-title>Accessibility</h2>
<p data-uix-section-desc>
Follows the APG <a href={treeViewMorfo.apg} target="_blank" rel="noreferrer">treeview pattern</a>. Root is <code>role="tree"</code>, branches/items are <code>role="treeitem"</code>, child groups are <code>role="group"</code>. Roving tabindex; arrows traverse visible items; <code>aria-level</code> tracks depth.
</p>
<div data-uix-subsection-head>Keyboard</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Key</th><th>Action</th></tr></thead>
<tbody>
<tr><td><span data-uix-kbd>ArrowDown</span> / <span data-uix-kbd>ArrowUp</span></td><td>Move focus through visible items.</td></tr>
<tr><td><span data-uix-kbd>ArrowRight</span></td><td>Expand a collapsed branch, or step into the first child if already open. (Reversed in RTL.)</td></tr>
<tr><td><span data-uix-kbd>ArrowLeft</span></td><td>Collapse an expanded branch, or step out to the parent. (Reversed in RTL.)</td></tr>
<tr><td><span data-uix-kbd>Home</span> / <span data-uix-kbd>End</span></td><td>First / last visible item.</td></tr>
<tr><td><span data-uix-kbd>Enter</span> / <span data-uix-kbd>Space</span></td><td>Toggle selection of the focused node.</td></tr>
<tr><td><span data-uix-kbd>*</span></td><td>Expand all sibling branches at the same level.</td></tr>
<tr><td>Letter / digit</td><td>Typeahead — focus next visible node whose label starts with the typed string.</td></tr>
</tbody>
</table>
</div>
<div data-uix-subsection-head>ARIA contract</div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Part</th><th>Attribute</th><th>Value</th></tr></thead>
<tbody>
<tr><td class="name">Provider</td><td>role</td><td class="type">"tree"</td></tr>
<tr><td class="name">Provider</td><td>aria-multiselectable</td><td class="type">"true" (multiple mode)</td></tr>
<tr><td class="name">Branch / Item</td><td>role</td><td class="type">"treeitem"</td></tr>
<tr><td class="name">Branch</td><td>aria-expanded</td><td class="type">"true" | "false"</td></tr>
<tr><td class="name">Branch / Item</td><td>aria-selected</td><td class="type">"true" (selected)</td></tr>
<tr><td class="name">Branch / Item</td><td>aria-level</td><td class="type">depth + 1 (1-based)</td></tr>
<tr><td class="name">BranchContent</td><td>role</td><td class="type">"group"</td></tr>
<tr><td class="name">BranchIndicator</td><td>aria-hidden</td><td class="type">"true" (decorative)</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.