Skip to content
Okaapiأوكابي
Framework for the code
Theme
Okaapi on GitHub

Chapter 11 Data

Tree

Nested items that open and close, such as folders or menu categories. One Tab stop: the arrow keys move, Right opens a branch and Left closes it, typing a name jumps to it, and Enter or Space selects. For a site's page links, use navigation instead.

Use it in Angular
import { TreeComponent, type TreeNode } from '@okaapi-ui/angular';
// On the Angular CDK tree.

Menu categories

The selected item is bold as well as highlighted, so it never depends on colour.

Desserts

Selected: pasta

Angular
<ui-tree label="Menu" [nodes]="menu" [expanded]="['mains']" [(selected)]="selected" />

menu: TreeNode[] = [
  { id: 'mains', label: 'Mains', children: [
    { id: 'grill', label: 'Grill', children: [{ id: 'kofta', label: 'Kofta' }] },
    { id: 'pasta', label: 'Pasta' },
  ] },
  { id: 'desserts', label: 'Desserts' },
];

In Arabic

Angular
<ui-tree label="القائمة" [nodes]="menu" [expanded]="['mains']" />

When to use something else

If you needUse
A flat list with columnsData table
Sections that open and closeAccordion

Inputs

NameTypeDefaultWhat it does
labelstring — Required. Names the tree: "Menu", "Files".
nodesTreeNode[] — Required. { id, label, children? }, nested as deep as needed.
expandedstring[][]Ids of the branches open at the start.
[(selected)]string | nullnullId of the selected item.

Keyboard and screen readers

KeysWhat they do
Tab Reach the tree; it is one Tab stop.
Up or Down Move to the previous or next item.
Right Open a branch, or move into it.
Left Close a branch, or move to its parent.
Letters Jump to the item that starts with them.
Enter or Space Select the item.
  • Read as a tree: each item says its level, whether it is open, and whether it is selected.