# KptTree (kpt-tree) A hierarchical tree (expanding, selection, icons). Rendered recursively. Import: `import { KptTree, KptTreeNode } from '@konce-pt/angular';` ## The node model (KptTreeNode) `{ label: string; value?: T; icon?: string; children?: KptTreeNode[]; expanded?: boolean; disabled?: boolean }` ## Inputs / outputs - `nodes`: KptTreeNode[]; `selectable`: boolean - `collapseMotion`: `'spring' | 'fade' | 'none'` (default from `provideKptMotion`, else `spring`) - see below - `selected`: model; `nodeClick`: output ## Example ## Expansion is component state, not data `expanded` in a node is the initial state only. The component keeps what the user opened or closed itself and never writes to the node objects - so two trees fed the same nodes open and close independently, and replacing `nodes` with new objects brings their own initial state. ## Keyboard The tree is one Tab stop (roving tabindex on the `treeitem` elements), following the WAI-ARIA tree view pattern: - `ArrowDown` / `ArrowUp` - the next / previous visible row, `Home` / `End` - the first / last; - `ArrowRight` - expands a closed branch, on an open one moves to its first child; - `ArrowLeft` - collapses an open branch, otherwise moves to the parent; - `Enter` / `Space` - the same as a click: selects (with `selectable`) or toggles the branch. The logic is the pure function `treeKeyAction` in `tree-keys.ts`; the other port has a twin file. ## Accessibility `role="tree"`, `treeitem` and `group`; branches carry `aria-expanded`, every row `aria-level`, selectable trees `aria-selected`, disabled rows `aria-disabled`. The chevron is mouse-only (`aria-hidden`): a button inside a `treeitem` would be a nested control and a second Tab stop per row, and the keyboard expands with the arrows anyway. The focus ring is drawn on the row, not on the `
  • `, which would outline the whole subtree. `ariaLabel` names the `role="tree"` element (e.g. "Project files") - without it a screen reader announces a bare "tree". ## Branch motion `collapseMotion` animates expanding and collapsing a branch: - `spring` - the height opens on a soft spring, children slide in as a cascade and sharpen out of a blur; when collapsing, the children fade first; - `fade` - children cross-fade; - `none` - no motion. A collapsing branch stays in the DOM (`inert`) until its animation ends, so it does not cut off mid-way; keyboard navigation already skips it. Entry rules apply only after the first render, so branches expanded in the data do not animate on page load. With no value it takes `collapse` from `provideKptMotion` (default `spring`); `enabled: false` and the system "reduce motion" setting always win. ## Tokens Row hover `--kpt-color-surface-variant`; the selected row `--kpt-color-primary`.