@nanahoshi/mona-ui 0.25.1 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/chart/README.md +2 -2
- package/command/package.json +4 -0
- package/docs/auto-complete.md +733 -0
- package/docs/avatar.md +220 -0
- package/docs/breadcrumb.md +320 -0
- package/docs/button-group.md +392 -0
- package/docs/button.md +256 -0
- package/docs/calendar.md +515 -0
- package/docs/card.md +292 -0
- package/docs/chart-bar.md +714 -0
- package/docs/chart-financial.md +567 -0
- package/docs/chart-funnel.md +546 -0
- package/docs/chart-heatmap.md +535 -0
- package/docs/chart-line-area.md +462 -0
- package/docs/chart-pie.md +645 -0
- package/docs/chart-radar.md +518 -0
- package/docs/chart-radial.md +658 -0
- package/docs/chart-scatter.md +479 -0
- package/docs/chart-treemap.md +651 -0
- package/docs/chart.md +2465 -0
- package/docs/checkbox.md +374 -0
- package/docs/chip.md +339 -0
- package/docs/circular-progress-bar.md +287 -0
- package/docs/collapsible.md +308 -0
- package/docs/color-gradient.md +336 -0
- package/docs/color-palette.md +317 -0
- package/docs/color-picker.md +387 -0
- package/docs/combo-box.md +764 -0
- package/docs/command.md +582 -0
- package/docs/contextmenu.md +530 -0
- package/docs/date-picker.md +251 -0
- package/docs/datetime-picker.md +284 -0
- package/docs/decimal-textbox.md +260 -0
- package/docs/dialog.md +822 -0
- package/docs/dropdown-button.md +507 -0
- package/docs/dropdown-list.md +779 -0
- package/docs/editor.md +374 -0
- package/docs/expansion-panel.md +348 -0
- package/docs/fieldset.md +217 -0
- package/docs/forms.md +162 -0
- package/docs/grid.md +2053 -0
- package/docs/input.md +197 -0
- package/docs/installation.md +54 -0
- package/docs/introduction.md +46 -0
- package/docs/label.md +340 -0
- package/docs/list-box.md +637 -0
- package/docs/list-view.md +584 -0
- package/docs/menubar.md +559 -0
- package/docs/multi-select.md +765 -0
- package/docs/notification.md +460 -0
- package/docs/numeric-textbox.md +301 -0
- package/docs/otp-input.md +539 -0
- package/docs/pager.md +513 -0
- package/docs/placeholder.md +176 -0
- package/docs/popover.md +423 -0
- package/docs/popup-menu.md +658 -0
- package/docs/popup.md +617 -0
- package/docs/progress-bar.md +368 -0
- package/docs/radio-button.md +451 -0
- package/docs/range-slider.md +367 -0
- package/docs/rating.md +518 -0
- package/docs/scroll-view.md +375 -0
- package/docs/segmented.md +434 -0
- package/docs/sheet.md +348 -0
- package/docs/sidebar.md +1126 -0
- package/docs/skeleton.md +181 -0
- package/docs/slider.md +423 -0
- package/docs/spinner.md +370 -0
- package/docs/split-button.md +522 -0
- package/docs/splitter.md +342 -0
- package/docs/stepper.md +539 -0
- package/docs/switch.md +340 -0
- package/docs/tabs.md +542 -0
- package/docs/textarea.md +196 -0
- package/docs/textbox.md +332 -0
- package/docs/theming.md +403 -0
- package/docs/time-picker.md +254 -0
- package/docs/tooltip-directive.md +340 -0
- package/docs/tooltip.md +321 -0
- package/docs/tree-view.md +1018 -0
- package/docs/window.md +663 -0
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-breadcrumb.mjs +8 -0
- package/fesm2022/nanahoshi-mona-ui-button.mjs +12 -0
- package/fesm2022/nanahoshi-mona-ui-calendar.mjs +5 -2
- package/fesm2022/nanahoshi-mona-ui-chart.mjs +212 -66
- package/fesm2022/nanahoshi-mona-ui-check-box.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-circular-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-collapsible.mjs +16 -2
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-command.mjs +924 -0
- package/fesm2022/nanahoshi-mona-ui-common.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-contextmenu.mjs +10 -6
- package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-dialog.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdown-button.mjs +9 -5
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +55 -1
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +3 -2
- package/fesm2022/nanahoshi-mona-ui-expansion-panel.mjs +13 -0
- package/fesm2022/nanahoshi-mona-ui-fieldset.mjs +5 -0
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-2tVhD2hK.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-DjNnVxHE.mjs} +2 -2
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-list.component-BAN70Wcn.mjs → nanahoshi-mona-ui-grid-grid-list.component-ihQIKeP-.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-row.component-C_kCaA5b.mjs → nanahoshi-mona-ui-grid-grid-row.component-BpnybNcs.mjs} +18 -35
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-BsNfrAHz.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-CYlgfc7c.mjs} +5 -5
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-CEfVa7eo.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-LCzfCYd3.mjs} +4653 -4529
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-internal-list.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-internal-popup-menu.mjs +168 -0
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +19 -1
- package/fesm2022/nanahoshi-mona-ui-list-box.mjs +14 -0
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +32 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +10 -0
- package/fesm2022/nanahoshi-mona-ui-menubar.mjs +15 -8
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +8 -5
- package/fesm2022/nanahoshi-mona-ui-notification.mjs +9 -0
- package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-otp-input.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-popover.mjs +14 -6
- package/fesm2022/nanahoshi-mona-ui-popup-menu.mjs +48 -183
- package/fesm2022/nanahoshi-mona-ui-popup.mjs +16 -0
- package/fesm2022/nanahoshi-mona-ui-progress-bar.mjs +4 -0
- package/fesm2022/nanahoshi-mona-ui-rating.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-segmented.mjs +1 -0
- package/fesm2022/nanahoshi-mona-ui-sheet.mjs +5 -5
- package/fesm2022/nanahoshi-mona-ui-sidebar.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-slider.mjs +7 -2
- package/fesm2022/nanahoshi-mona-ui-split-button.mjs +9 -6
- package/fesm2022/nanahoshi-mona-ui-stepper.mjs +18 -21
- package/fesm2022/nanahoshi-mona-ui-tabs.mjs +11 -8
- package/fesm2022/nanahoshi-mona-ui-text-box.mjs +9 -1
- package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +2 -1
- package/fesm2022/nanahoshi-mona-ui-tooltip.mjs +16 -5
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +13 -11
- package/fesm2022/nanahoshi-mona-ui-window.mjs +12 -5
- package/i18n/catalogs/en-US.messages.json +10 -0
- package/internal/popup-menu/package.json +4 -0
- package/llms.txt +133 -0
- package/locales/ar-sa/ar-sa.messages.json +10 -0
- package/locales/de-de/de-de.messages.json +10 -0
- package/locales/es-es/es-es.messages.json +10 -0
- package/locales/fr-fr/fr-fr.messages.json +10 -0
- package/locales/id-id/id-id.messages.json +10 -0
- package/locales/it-it/it-it.messages.json +10 -0
- package/locales/ja-jp/ja-jp.messages.json +10 -0
- package/locales/ko-kr/ko-kr.messages.json +10 -0
- package/locales/pt-br/pt-br.messages.json +10 -0
- package/locales/ru-ru/ru-ru.messages.json +10 -0
- package/locales/tr-tr/tr-tr.messages.json +10 -0
- package/locales/zh-cn/zh-cn.messages.json +10 -0
- package/locales/zh-tw/zh-tw.messages.json +10 -0
- package/package.json +9 -1
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +1 -1
- package/types/nanahoshi-mona-ui-breadcrumb.d.ts +8 -0
- package/types/nanahoshi-mona-ui-button.d.ts +12 -0
- package/types/nanahoshi-mona-ui-calendar.d.ts +3 -0
- package/types/nanahoshi-mona-ui-chart.d.ts +250 -20
- package/types/nanahoshi-mona-ui-check-box.d.ts +4 -0
- package/types/nanahoshi-mona-ui-circular-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-collapsible.d.ts +10 -0
- package/types/nanahoshi-mona-ui-combo-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-command.d.ts +253 -0
- package/types/nanahoshi-mona-ui-common.d.ts +17 -1
- package/types/nanahoshi-mona-ui-contextmenu.d.ts +5 -2
- package/types/nanahoshi-mona-ui-date-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-datetime-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-dialog.d.ts +58 -1
- package/types/nanahoshi-mona-ui-dropdown-button.d.ts +7 -3
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +55 -1
- package/types/nanahoshi-mona-ui-editor.d.ts +31 -0
- package/types/nanahoshi-mona-ui-expansion-panel.d.ts +13 -0
- package/types/nanahoshi-mona-ui-fieldset.d.ts +5 -0
- package/types/nanahoshi-mona-ui-grid.d.ts +162 -35
- package/types/nanahoshi-mona-ui-i18n.d.ts +144 -1
- package/types/nanahoshi-mona-ui-internal-list.d.ts +16 -1
- package/types/nanahoshi-mona-ui-internal-popup-menu.d.ts +165 -0
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +21 -2
- package/types/nanahoshi-mona-ui-internal.d.ts +4 -5
- package/types/nanahoshi-mona-ui-label.d.ts +1 -0
- package/types/nanahoshi-mona-ui-list-box.d.ts +27 -4
- package/types/nanahoshi-mona-ui-list-view.d.ts +34 -1
- package/types/nanahoshi-mona-ui-list.d.ts +1 -1
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +10 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +10 -0
- package/types/nanahoshi-mona-ui-menubar.d.ts +10 -3
- package/types/nanahoshi-mona-ui-multi-select.d.ts +3 -3
- package/types/nanahoshi-mona-ui-notification.d.ts +9 -0
- package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +1 -1
- package/types/nanahoshi-mona-ui-otp-input.d.ts +1 -0
- package/types/nanahoshi-mona-ui-pager.d.ts +5 -1
- package/types/nanahoshi-mona-ui-popover.d.ts +9 -1
- package/types/nanahoshi-mona-ui-popup-menu.d.ts +48 -161
- package/types/nanahoshi-mona-ui-popup.d.ts +16 -0
- package/types/nanahoshi-mona-ui-progress-bar.d.ts +4 -0
- package/types/nanahoshi-mona-ui-rating.d.ts +2 -0
- package/types/nanahoshi-mona-ui-segmented.d.ts +1 -0
- package/types/nanahoshi-mona-ui-sheet.d.ts +1 -1
- package/types/nanahoshi-mona-ui-slider.d.ts +2 -0
- package/types/nanahoshi-mona-ui-spinner.d.ts +7 -0
- package/types/nanahoshi-mona-ui-split-button.d.ts +7 -4
- package/types/nanahoshi-mona-ui-stepper.d.ts +11 -2
- package/types/nanahoshi-mona-ui-tabs.d.ts +4 -1
- package/types/nanahoshi-mona-ui-text-box.d.ts +9 -1
- package/types/nanahoshi-mona-ui-time-picker.d.ts +2 -1
- package/types/nanahoshi-mona-ui-tooltip.d.ts +10 -2
- package/types/nanahoshi-mona-ui-tree-view.d.ts +6 -5
- package/types/nanahoshi-mona-ui-window.d.ts +66 -1
|
@@ -0,0 +1,1018 @@
|
|
|
1
|
+
# Tree View
|
|
2
|
+
|
|
3
|
+
> Hierarchical data as an expandable, keyboard-navigable tree.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/tree-view`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-tree-view`
|
|
8
|
+
|
|
9
|
+
`TreeViewComponent` renders hierarchical or flat parent-child data as an expandable, keyboard-navigable tree of nodes, with selection, checking, disabling, expand/collapse, filtering and drag-and-drop each opt-in through a companion directive. Nodes moved by drag and drop can also be moved with Ctrl+Shift+arrow keys; either way the tree asks through `nodeDrop`, and your handler applies the move.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Use Tree View to let a consumer browse or act on data that has parent-child relationships, such as a file system, a category tree, or an org chart. The data can be shaped as nested items (hierarchical mode) or as a flat list linked by an id and a parent id (flat mode).
|
|
14
|
+
|
|
15
|
+
Selection, checking, disabling, expand/collapse control, filtering, and drag-and-drop reordering are all opt-in. None of these behaviors are active until the corresponding attribute directive is applied to the `<mona-tree-view>` host element:
|
|
16
|
+
|
|
17
|
+
- `monaTreeViewSelectable` — single or multiple selection.
|
|
18
|
+
- `monaTreeViewCheckable` — a checkbox per node, with check propagation to children and parents.
|
|
19
|
+
- `monaTreeViewDisable` — disables nodes (and, by default, their descendants).
|
|
20
|
+
- `monaTreeViewExpandable` — expanders on parent nodes and controlled expand/collapse. Without it, every node is shown expanded and can't be collapsed — see [Without `monaTreeViewExpandable` every node is open](#without-monatreeviewexpandable-every-node-is-open).
|
|
21
|
+
- `monaTreeViewFilterable` — a filter input above the tree.
|
|
22
|
+
- `monaTreeViewDragAndDrop` — reordering and reparenting nodes by dragging.
|
|
23
|
+
|
|
24
|
+
**Use `Grid` instead when:**
|
|
25
|
+
|
|
26
|
+
- The data is naturally tabular rather than hierarchical.
|
|
27
|
+
|
|
28
|
+
**Use `DropDownList`, `ComboBox` or `MultiSelect` instead when:**
|
|
29
|
+
|
|
30
|
+
- The consumer is choosing from a flat collection of options rather than navigating a hierarchy.
|
|
31
|
+
|
|
32
|
+
## Import & Quick Start
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { TreeViewComponent } from "@nanahoshi/mona-ui/tree-view";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Each behavior directive (`TreeViewSelectableDirective`, `TreeViewCheckableDirective`, `TreeViewDisableDirective`, `TreeViewExpandableDirective`, `TreeViewFilterableDirective`, `TreeViewDragAndDropDirective`) and `TreeViewNodeTemplateDirective` is imported from the same entry point and added to the component's `imports` next to `TreeViewComponent`.
|
|
39
|
+
|
|
40
|
+
`textField` and either `children` (hierarchical mode) or `idField` / `parentIdField` (flat mode) are required for the tree to render nodes from `data`. When `textField` is empty, the data item itself is shown as the node's text.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
interface FileItem {
|
|
44
|
+
id: string;
|
|
45
|
+
text: string;
|
|
46
|
+
items: FileItem[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected readonly data: FileItem[] = [
|
|
50
|
+
{
|
|
51
|
+
id: "1",
|
|
52
|
+
text: "src",
|
|
53
|
+
items: [
|
|
54
|
+
{ id: "1-1", text: "index.ts", items: [] },
|
|
55
|
+
{ id: "1-2", text: "app.ts", items: [] }
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
{ id: "2", text: "package.json", items: [] }
|
|
59
|
+
];
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<mona-tree-view aria-label="Documents" [data]="data" children="items" textField="text"></mona-tree-view>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Give every tree a name with `aria-label` or `aria-labelledby` — see [ARIA](#aria).
|
|
67
|
+
|
|
68
|
+
## Anatomy
|
|
69
|
+
|
|
70
|
+
Consumers interact with the following selectors directly:
|
|
71
|
+
|
|
72
|
+
- `mona-tree-view` — the root component.
|
|
73
|
+
- `ng-template[monaTreeViewNodeTemplate]` — replaces the default node text with projected content. The template context exposes `$implicit` (the node's data item) and `element` (the node's content element, a `mona-tree-node`).
|
|
74
|
+
- `mona-tree-view[monaTreeViewSelectable]`, `mona-tree-view[monaTreeViewCheckable]`, `mona-tree-view[monaTreeViewDisable]`, `mona-tree-view[monaTreeViewExpandable]`, `mona-tree-view[monaTreeViewFilterable]`, `mona-tree-view[monaTreeViewDragAndDrop]` — attribute directives applied to the `mona-tree-view` host element to enable each behavior.
|
|
75
|
+
|
|
76
|
+
| Directive | Selector | Template context | Replaces |
|
|
77
|
+
| ------------------------------- | --------------------------------------- | -------------------------------------------------------------------------- | -------------------------------------- |
|
|
78
|
+
| `TreeViewNodeTemplateDirective` | `ng-template[monaTreeViewNodeTemplate]` | `TreeViewNodeTemplateContext<T>`: `{ $implicit: T, element: HTMLElement }` | The default node text from `textField` |
|
|
79
|
+
|
|
80
|
+
```html
|
|
81
|
+
<mona-tree-view aria-label="Documents" [data]="data" children="items" textField="text">
|
|
82
|
+
<ng-template monaTreeViewNodeTemplate [monaTreeViewNodeTemplateOf]="data" let-dataItem let-element="element">
|
|
83
|
+
<span>{{ dataItem.text }}</span>
|
|
84
|
+
</ng-template>
|
|
85
|
+
</mona-tree-view>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Bind the tree's data to `[monaTreeViewNodeTemplateOf]` to type `$implicit` in the template; without it, the data item is `any`. The context type, `TreeViewNodeTemplateContext<T>`, is exported for annotating a `TemplateRef`. The node's name is its template content, so keep it short: it is what screen readers read for the node. See [Keys inside node templates](#keys-inside-node-templates) before placing controls in a node template.
|
|
89
|
+
|
|
90
|
+
## Examples
|
|
91
|
+
|
|
92
|
+
### Flat data
|
|
93
|
+
|
|
94
|
+
Set `mode="flat"` and provide `idField` and `parentIdField` instead of `children` when the source data is a flat list linked by id references. Items whose parent id is `null` or missing are the root nodes; an item whose parent id matches no item is not shown.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
protected readonly data = [
|
|
98
|
+
{ id: "1", text: "Electronics", parentId: null },
|
|
99
|
+
{ id: "1-1", text: "Laptops", parentId: "1" },
|
|
100
|
+
{ id: "1-2", text: "Phones", parentId: "1" }
|
|
101
|
+
];
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The [checking example](#checking) uses flat data.
|
|
105
|
+
|
|
106
|
+
### Selection
|
|
107
|
+
|
|
108
|
+
Apply `monaTreeViewSelectable` to track which nodes are selected. Single mode is the default; pass `{ mode: 'multiple' }` to allow multiple selected nodes. In single mode, `toggleable: true` lets the user deselect the selected node by clicking it (or pressing Enter) again; `childrenOnly: true` makes only nodes without children selectable.
|
|
109
|
+
|
|
110
|
+
`selection-example.component.ts`
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { Component, signal } from "@angular/core";
|
|
114
|
+
import { LucideFile, LucideFolder } from "@lucide/angular";
|
|
115
|
+
import {
|
|
116
|
+
TreeViewComponent,
|
|
117
|
+
TreeViewExpandableDirective,
|
|
118
|
+
TreeViewNodeTemplateDirective,
|
|
119
|
+
TreeViewSelectableDirective
|
|
120
|
+
} from "@nanahoshi/mona-ui/tree-view";
|
|
121
|
+
|
|
122
|
+
interface FileItem {
|
|
123
|
+
id: string;
|
|
124
|
+
items: FileItem[];
|
|
125
|
+
text: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@Component({
|
|
129
|
+
selector: "app-tree-view-selection-example",
|
|
130
|
+
imports: [
|
|
131
|
+
LucideFile,
|
|
132
|
+
LucideFolder,
|
|
133
|
+
TreeViewComponent,
|
|
134
|
+
TreeViewExpandableDirective,
|
|
135
|
+
TreeViewNodeTemplateDirective,
|
|
136
|
+
TreeViewSelectableDirective
|
|
137
|
+
],
|
|
138
|
+
templateUrl: "./selection-example.component.html"
|
|
139
|
+
})
|
|
140
|
+
export class TreeViewSelectionExampleComponent {
|
|
141
|
+
protected readonly files: FileItem[] = [
|
|
142
|
+
{
|
|
143
|
+
id: "src",
|
|
144
|
+
text: "src",
|
|
145
|
+
items: [
|
|
146
|
+
{ id: "main.ts", text: "main.ts", items: [] },
|
|
147
|
+
{
|
|
148
|
+
id: "app",
|
|
149
|
+
text: "app",
|
|
150
|
+
items: [
|
|
151
|
+
{ id: "app.ts", text: "app.ts", items: [] },
|
|
152
|
+
{ id: "app.html", text: "app.html", items: [] }
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
{ id: "package.json", text: "package.json", items: [] },
|
|
158
|
+
{ id: "README.md", text: "README.md", items: [] }
|
|
159
|
+
];
|
|
160
|
+
protected readonly selectedKeys = signal<string[]>([]);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`selection-example.component.html`
|
|
165
|
+
|
|
166
|
+
```html
|
|
167
|
+
<div class="flex max-w-xs flex-col gap-2">
|
|
168
|
+
<mona-tree-view
|
|
169
|
+
aria-label="Project files"
|
|
170
|
+
children="items"
|
|
171
|
+
expandBy="id"
|
|
172
|
+
monaTreeViewExpandable
|
|
173
|
+
selectBy="id"
|
|
174
|
+
textField="text"
|
|
175
|
+
[data]="files"
|
|
176
|
+
[expandedKeys]="['src']"
|
|
177
|
+
[monaTreeViewSelectable]="{ mode: 'single', toggleable: true }"
|
|
178
|
+
[(selectedKeys)]="selectedKeys">
|
|
179
|
+
<ng-template let-file monaTreeViewNodeTemplate [monaTreeViewNodeTemplateOf]="files">
|
|
180
|
+
<span class="flex items-center gap-1.5">
|
|
181
|
+
@if (file.items.length > 0) {
|
|
182
|
+
<svg lucideFolder aria-hidden="true" [size]="14"></svg>
|
|
183
|
+
} @else {
|
|
184
|
+
<svg lucideFile aria-hidden="true" [size]="14"></svg>
|
|
185
|
+
}
|
|
186
|
+
{{ file.text }}
|
|
187
|
+
</span>
|
|
188
|
+
</ng-template>
|
|
189
|
+
</mona-tree-view>
|
|
190
|
+
<span aria-live="polite" class="text-sm">Selected: {{ selectedKeys().join(", ") || "none" }}</span>
|
|
191
|
+
</div>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
`selectBy` derives the key used for `selectedKeys`/`selectedKeysChange`; when omitted, the data item itself is the key. The same holds for `checkBy`, `disableBy` and `expandBy` below.
|
|
195
|
+
|
|
196
|
+
### Checking
|
|
197
|
+
|
|
198
|
+
Apply `monaTreeViewCheckable` to render checkboxes on nodes. Checking a parent also checks its children, checking all of a parent's children checks the parent, and a parent shows an indeterminate state when only some of its children are checked, unless configured otherwise through the directive's options (`checkChildren`, `checkParents`, `mode: "single"`). Use `hasCheckbox` to show checkboxes on some nodes only.
|
|
199
|
+
|
|
200
|
+
`checking-example.component.ts`
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { Component, computed, signal } from "@angular/core";
|
|
204
|
+
import {
|
|
205
|
+
TreeViewCheckableDirective,
|
|
206
|
+
TreeViewComponent,
|
|
207
|
+
TreeViewExpandableDirective
|
|
208
|
+
} from "@nanahoshi/mona-ui/tree-view";
|
|
209
|
+
|
|
210
|
+
@Component({
|
|
211
|
+
selector: "app-tree-view-checking-example",
|
|
212
|
+
imports: [TreeViewCheckableDirective, TreeViewComponent, TreeViewExpandableDirective],
|
|
213
|
+
templateUrl: "./checking-example.component.html"
|
|
214
|
+
})
|
|
215
|
+
export class TreeViewCheckingExampleComponent {
|
|
216
|
+
protected readonly categories = [
|
|
217
|
+
{ id: 1, text: "Electronics", parentId: null },
|
|
218
|
+
{ id: 2, text: "Laptops", parentId: 1 },
|
|
219
|
+
{ id: 3, text: "Phones", parentId: 1 },
|
|
220
|
+
{ id: 4, text: "Home", parentId: null },
|
|
221
|
+
{ id: 5, text: "Kitchen", parentId: 4 },
|
|
222
|
+
{ id: 6, text: "Garden", parentId: 4 },
|
|
223
|
+
{ id: 7, text: "Lighting", parentId: 4 }
|
|
224
|
+
];
|
|
225
|
+
protected readonly checkedKeys = signal<number[]>([3]);
|
|
226
|
+
protected readonly checkedNames = computed(() =>
|
|
227
|
+
this.categories.filter(category => this.checkedKeys().includes(category.id)).map(category => category.text)
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`checking-example.component.html`
|
|
233
|
+
|
|
234
|
+
```html
|
|
235
|
+
<div class="flex max-w-xs flex-col gap-2">
|
|
236
|
+
<mona-tree-view
|
|
237
|
+
aria-label="Product categories"
|
|
238
|
+
checkBy="id"
|
|
239
|
+
expandBy="id"
|
|
240
|
+
idField="id"
|
|
241
|
+
mode="flat"
|
|
242
|
+
monaTreeViewCheckable
|
|
243
|
+
monaTreeViewExpandable
|
|
244
|
+
parentIdField="parentId"
|
|
245
|
+
textField="text"
|
|
246
|
+
[data]="categories"
|
|
247
|
+
[expandedKeys]="[1, 4]"
|
|
248
|
+
[(checkedKeys)]="checkedKeys" />
|
|
249
|
+
<span aria-live="polite" class="text-sm">Checked: {{ checkedNames().join(", ") || "nothing" }}</span>
|
|
250
|
+
</div>
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Disabling nodes
|
|
254
|
+
|
|
255
|
+
Apply `monaTreeViewDisable` and pass the keys of the nodes to disable. Disabling a node also disables its descendants by default (`disableChildren`). A disabled node can still be moved to with the keyboard, but it can't be clicked, selected, checked, expanded, collapsed or dragged.
|
|
256
|
+
|
|
257
|
+
```html
|
|
258
|
+
<mona-tree-view
|
|
259
|
+
aria-label="Documents"
|
|
260
|
+
[data]="data"
|
|
261
|
+
children="items"
|
|
262
|
+
textField="text"
|
|
263
|
+
monaTreeViewDisable
|
|
264
|
+
disableBy="id"
|
|
265
|
+
[disabledKeys]="['1-2']"></mona-tree-view>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Controlled expand/collapse
|
|
269
|
+
|
|
270
|
+
Apply `monaTreeViewExpandable` to show an expander on every node with children, and bind `expandedKeys` and `expandedKeysChange` to control which nodes are expanded from outside the component. Without the directive, every node is shown expanded.
|
|
271
|
+
|
|
272
|
+
```html
|
|
273
|
+
<mona-tree-view
|
|
274
|
+
aria-label="Documents"
|
|
275
|
+
[data]="data"
|
|
276
|
+
children="items"
|
|
277
|
+
textField="text"
|
|
278
|
+
monaTreeViewExpandable
|
|
279
|
+
expandBy="id"
|
|
280
|
+
[expandedKeys]="expandedKeys()"
|
|
281
|
+
(expandedKeysChange)="expandedKeys.set($event)"></mona-tree-view>
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Filtering
|
|
285
|
+
|
|
286
|
+
Apply `monaTreeViewFilterable` to show a filter input above the tree that narrows the visible nodes to those whose text matches, plus their ancestors, and expands those ancestors. By default a node matches when its text contains the filter text, ignoring case; the options' `operator` (`"contains"`, `"startsWith"`, `"endsWith"` or a function), `caseSensitive` and `debounce` (how long after the user stops typing the filter applies; a filter set from code applies at once) change that. Bind `[(filter)]` to read the text or set it from code (setting it back to `""` clears the filter, even after the user typed). `filterInput` fires first with a cancelable `FilterChangeEvent`. The expansion a filter applies is view state: it isn't reported through `expandedKeysChange` and is undone when the filter is cleared. Lazily loaded children that haven't been loaded yet aren't searched.
|
|
287
|
+
|
|
288
|
+
```html
|
|
289
|
+
<mona-tree-view
|
|
290
|
+
aria-label="Documents"
|
|
291
|
+
[data]="data"
|
|
292
|
+
children="items"
|
|
293
|
+
textField="text"
|
|
294
|
+
monaTreeViewFilterable
|
|
295
|
+
filterPlaceholder="Filter documents"
|
|
296
|
+
[(filter)]="filter"></mona-tree-view>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Drag and drop reordering
|
|
300
|
+
|
|
301
|
+
Apply `monaTreeViewDragAndDrop` to let the consumer reorder or reparent nodes by dragging them with the mouse or by touch, or by moving them with the keyboard. Dropping near the top or bottom edge of a node places the dragged node before or after it; dropping on the rest of the node places it inside, as its last child. A node can't be dropped onto itself or into its own subtree, and disabled nodes can't be dragged.
|
|
302
|
+
|
|
303
|
+
A drop changes nothing by itself: the tree emits `nodeDrop`, and the consumer applies the move. Use the exported `moveTreeNode` (hierarchical data) or `moveFlatTreeNode` (flat data) helper inside the `nodeDrop` handler to compute an updated array and pass it back through `data`. `moveTreeNode` returns a new top-level array and updates nested children arrays in place, so untouched data items keep their identity and their tree state; `moveFlatTreeNode` returns a new array in which the moved item is replaced by a copy with its parent id updated, so key the flat tree's state with `selectBy`, `checkBy` and `expandBy` rather than by data item.
|
|
304
|
+
|
|
305
|
+
`drag-and-drop-example.component.ts`
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import { Component, signal } from "@angular/core";
|
|
309
|
+
import {
|
|
310
|
+
moveTreeNode,
|
|
311
|
+
type NodeDropEvent,
|
|
312
|
+
TreeViewComponent,
|
|
313
|
+
TreeViewDragAndDropDirective,
|
|
314
|
+
TreeViewExpandableDirective
|
|
315
|
+
} from "@nanahoshi/mona-ui/tree-view";
|
|
316
|
+
|
|
317
|
+
interface Track {
|
|
318
|
+
id: string;
|
|
319
|
+
items: Track[];
|
|
320
|
+
text: string;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
@Component({
|
|
324
|
+
selector: "app-tree-view-drag-and-drop-example",
|
|
325
|
+
imports: [TreeViewComponent, TreeViewDragAndDropDirective, TreeViewExpandableDirective],
|
|
326
|
+
templateUrl: "./drag-and-drop-example.component.html"
|
|
327
|
+
})
|
|
328
|
+
export class TreeViewDragAndDropExampleComponent {
|
|
329
|
+
protected readonly playlists = signal<Track[]>([
|
|
330
|
+
{
|
|
331
|
+
id: "focus",
|
|
332
|
+
text: "Focus",
|
|
333
|
+
items: [
|
|
334
|
+
{ id: "rain", text: "Rain on glass", items: [] },
|
|
335
|
+
{ id: "piano", text: "Quiet piano", items: [] }
|
|
336
|
+
]
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
id: "workout",
|
|
340
|
+
text: "Workout",
|
|
341
|
+
items: [
|
|
342
|
+
{ id: "drums", text: "Big drums", items: [] },
|
|
343
|
+
{ id: "synth", text: "Fast synth", items: [] }
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
]);
|
|
347
|
+
|
|
348
|
+
/** The tree doesn't move the node itself: apply the move and pass the new array back. */
|
|
349
|
+
protected onNodeDrop(event: NodeDropEvent<Track>): void {
|
|
350
|
+
this.playlists.set(moveTreeNode(this.playlists(), event, "id", "items"));
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
`drag-and-drop-example.component.html`
|
|
356
|
+
|
|
357
|
+
```html
|
|
358
|
+
<mona-tree-view
|
|
359
|
+
aria-label="Playlists"
|
|
360
|
+
children="items"
|
|
361
|
+
expandBy="id"
|
|
362
|
+
monaTreeViewDragAndDrop
|
|
363
|
+
monaTreeViewExpandable
|
|
364
|
+
textField="text"
|
|
365
|
+
[data]="playlists()"
|
|
366
|
+
[expandedKeys]="['focus', 'workout']"
|
|
367
|
+
(nodeDrop)="onNodeDrop($event)" />
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
For flat data, call `moveFlatTreeNode(this.data(), event, "id", "parentId")` instead.
|
|
371
|
+
|
|
372
|
+
The keyboard moves the active node with Ctrl+Shift+Arrow (Cmd+Shift+Arrow on macOS): ArrowUp and ArrowDown move it before its previous or after its next visible sibling, ArrowRight (ArrowLeft in RTL) moves it into its previous sibling as the last child, and ArrowLeft (ArrowRight in RTL) moves it out, after its parent. A keyboard move emits the same `nodeDrop` as a drop, with the `KeyboardEvent` as `originalEvent`, so the handler above serves both. Once the handler has applied the move, the node stays active, a node it moved into opens, and the move is announced ("Apple moved after Bread"); a move the handler didn't apply isn't announced. Disabled nodes don't move, and nothing moves into a disabled node.
|
|
373
|
+
|
|
374
|
+
### Lazy-loaded children
|
|
375
|
+
|
|
376
|
+
Pass a function returning an `Observable` as `children` to load a node's children on first expand instead of upfront. Provide `hasChildren` so unexpanded nodes can render an expander before their children are fetched, and apply `monaTreeViewExpandable`: without it there is no expander and nothing triggers the load. Loaded children are cached, so collapsing and expanding the node again doesn't request them again. A node expanded through `expandedKeys`, from the start or later, loads its children once it is shown. Pass the function as a property (an arrow function), not a method, so it keeps `this`.
|
|
377
|
+
|
|
378
|
+
While children load, the node is expanded and `aria-busy`, its expander reads "Loading {node}", and a load that takes more than a moment (400 ms) is announced. If the observable errors, `childrenLoadError` emits with the node and the error, the failure is announced, and the node is collapsed again and described as failed ("Couldn't load the items in {node}"); its expander reads "Retry loading {node}", and expanding it loads again.
|
|
379
|
+
|
|
380
|
+
`lazy-loading-example.component.ts`
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
import { Component } from "@angular/core";
|
|
384
|
+
import { TreeViewComponent, TreeViewExpandableDirective } from "@nanahoshi/mona-ui/tree-view";
|
|
385
|
+
import { delay, type Observable, of } from "rxjs";
|
|
386
|
+
|
|
387
|
+
interface Folder {
|
|
388
|
+
hasChildren: boolean;
|
|
389
|
+
id: string;
|
|
390
|
+
text: string;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Stands in for a server: it returns a folder's contents after a short wait. */
|
|
394
|
+
const fetchChildren = (folder: Folder): Observable<Folder[]> =>
|
|
395
|
+
of(
|
|
396
|
+
folder.id.split("/").length < 3
|
|
397
|
+
? ["Drafts", "Final"].map(name => ({ id: `${folder.id}/${name}`, text: name, hasChildren: true }))
|
|
398
|
+
: [{ id: `${folder.id}/notes.txt`, text: "notes.txt", hasChildren: false }]
|
|
399
|
+
).pipe(delay(800));
|
|
400
|
+
|
|
401
|
+
@Component({
|
|
402
|
+
selector: "app-tree-view-lazy-loading-example",
|
|
403
|
+
imports: [TreeViewComponent, TreeViewExpandableDirective],
|
|
404
|
+
templateUrl: "./lazy-loading-example.component.html"
|
|
405
|
+
})
|
|
406
|
+
export class TreeViewLazyLoadingExampleComponent {
|
|
407
|
+
protected readonly folders: Folder[] = [
|
|
408
|
+
{ id: "Documents", text: "Documents", hasChildren: true },
|
|
409
|
+
{ id: "Pictures", text: "Pictures", hasChildren: true }
|
|
410
|
+
];
|
|
411
|
+
protected readonly loadChildren = fetchChildren;
|
|
412
|
+
protected readonly hasChildren = (folder: Folder): boolean => folder.hasChildren;
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
`lazy-loading-example.component.html`
|
|
417
|
+
|
|
418
|
+
```html
|
|
419
|
+
<mona-tree-view
|
|
420
|
+
aria-label="Folders"
|
|
421
|
+
expandBy="id"
|
|
422
|
+
monaTreeViewExpandable
|
|
423
|
+
textField="text"
|
|
424
|
+
[children]="loadChildren"
|
|
425
|
+
[data]="folders"
|
|
426
|
+
[hasChildren]="hasChildren" />
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
To handle a failed load, listen to `childrenLoadError`: the node is collapsed again and expanding it retries, so log or report `event.error` there.
|
|
430
|
+
|
|
431
|
+
## Behavior
|
|
432
|
+
|
|
433
|
+
### Cancelable events
|
|
434
|
+
|
|
435
|
+
`nodeSelect`, `nodeCheck`, `nodeClick`, `nodeDragStart`, `nodeDrop`, and `filterInput` emit an event object with `preventDefault()` and `isDefaultPrevented()`. Calling `preventDefault()` in a handler stops the corresponding state change (selection, check, the click's selection, drag, or filter) from being applied. A drop changes nothing by itself, so `preventDefault()` on `nodeDrop` tells the tree the move wasn't applied: it doesn't move focus to the dropped node. `nodeDrag` and `nodeDragEnd` aren't cancelable: a drag always ends, and `preventDefault()` on `nodeDragEnd` has no effect. `nodeSelect` and `selectionChange` fire only when the selection would change: clicking (or pressing Enter on) the selected node of a single selection that isn't `toggleable` fires neither.
|
|
436
|
+
|
|
437
|
+
### Data modes
|
|
438
|
+
|
|
439
|
+
Switching `mode` requires providing the matching fields: `children` for `"hierarchical"`, or `idField` and `parentIdField` for `"flat"`. The two field sets are independent inputs and are not cross-validated. In hierarchical mode, a new `data` value reuses the node of every data object the tree already had, so lazily loaded children and the active node survive a refresh such as the one after `moveTreeNode`. In flat mode the nodes are rebuilt on every refresh; the active node is kept by its `idField` value, so it survives `moveFlatTreeNode` too. Changing `textField` doesn't rebuild the nodes.
|
|
440
|
+
|
|
441
|
+
### Without `monaTreeViewExpandable` every node is open
|
|
442
|
+
|
|
443
|
+
Without `monaTreeViewExpandable` (or with `{ enabled: false }`), every node with children is rendered expanded, has no expander and no `aria-expanded`, and can't be collapsed: the collapse key moves to the parent, `*` does nothing, and no expanded keys are written. Apply the directive for collapsible trees and for lazily loaded children.
|
|
444
|
+
|
|
445
|
+
### Moving nodes from code
|
|
446
|
+
|
|
447
|
+
`TreeViewComponent` exposes `moveNode(source, target, position)` and `undoMoveNode(snapshot)` for moving nodes in the tree's internal structure directly, without going through `data`. `moveNode` returns `null`, and changes nothing, for a move it can't make: onto the node itself or into its own subtree, inside the node's own parent or inside a disabled node, or `"outside"`. The `nodeDrop` event's `treeView` property refers to the emitting `TreeViewComponent` instance, typed as the exported `ITreeView<T>`.
|
|
448
|
+
|
|
449
|
+
### Each tree view has its own state
|
|
450
|
+
|
|
451
|
+
Every `mona-tree-view` provides its own tree state, so several trees on a page, or a tree inside another component's template, never share selection, checks, expansion or filter text.
|
|
452
|
+
|
|
453
|
+
### Keys inside node templates
|
|
454
|
+
|
|
455
|
+
Keys pressed in a control placed in a node template (an input, a button, a nested tree) are left to that control: the tree only handles keys pressed while it has focus itself. The control still isn't a Tab stop of its own unless you make it one, and a click on it also activates its node.
|
|
456
|
+
|
|
457
|
+
## Forms Integration
|
|
458
|
+
|
|
459
|
+
Tree View does not implement `ControlValueAccessor` or the signal forms `FormValueControl` / `FormCheckboxControl` interfaces. It cannot be bound with `[(ngModel)]`, `[formControl]`, `formControlName`, or `[formField]`. Track selection or check state through the `selectedKeys` / `checkedKeys` inputs and their `selectedKeysChange` / `checkedKeysChange` outputs, or the `selectionChange` / `nodeSelect` / `nodeCheck` outputs, exposed by the selectable and checkable directives.
|
|
460
|
+
|
|
461
|
+
## Accessibility
|
|
462
|
+
|
|
463
|
+
### Keyboard
|
|
464
|
+
|
|
465
|
+
The arrow keys that open and close nodes follow the tree's text direction (the nearest `dir`, or the application's direction): in a right-to-left tree, ArrowLeft and ArrowRight swap.
|
|
466
|
+
|
|
467
|
+
| Key | Action |
|
|
468
|
+
| -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
469
|
+
| `ArrowDown` | Move to the next visible node. From the last node, wraps to the first. |
|
|
470
|
+
| `ArrowUp` | Move to the previous visible node. From the first node, wraps to the last. |
|
|
471
|
+
| `Home` | Move to the first visible node. |
|
|
472
|
+
| `End` | Move to the last visible node. |
|
|
473
|
+
| `ArrowRight` (LTR) / `ArrowLeft` (RTL) | On a closed node with children, expand it (loading lazy children). On an open node, move to its first child. On a node without children, nothing. |
|
|
474
|
+
| `ArrowLeft` (LTR) / `ArrowRight` (RTL) | On an open node, collapse it. On a closed node, a node without children, or a node that can't be collapsed (disabled, or expanding is off), move to its parent. On a root node, nothing else. |
|
|
475
|
+
| `*` | Expand the active node and all of its siblings that have children. |
|
|
476
|
+
| `Enter` | With `monaTreeViewSelectable`, select the active node. In multiple mode, or in single mode with `toggleable`, Enter on a selected node deselects it; otherwise Enter on the selected node does nothing. `nodeSelect` fires first and can cancel it. With `childrenOnly`, nodes with children aren't selected. |
|
|
477
|
+
| `Space` | With `monaTreeViewCheckable`, check or uncheck the active node when it has a checkbox (`hasCheckbox`, and only nodes without children with `childrenOnly`). `nodeCheck` fires first and can cancel it. |
|
|
478
|
+
| Any letter or digit, `-` or `_` | Typeahead: move to the next visible node, after the active one and wrapping around, whose text starts with the typed characters (ignoring case). Keys typed within 200 ms build one prefix, and the active node stays while it still matches the longer prefix ("ap" on Apple stays on Apple); after a pause the next key starts a new search. |
|
|
479
|
+
| `Ctrl`+`Shift`+arrow (`Cmd` on macOS) | With `monaTreeViewDragAndDrop`, move the active node: ArrowUp / ArrowDown before its previous or after its next sibling, ArrowRight (LTR) into its previous sibling, ArrowLeft (LTR) out after its parent. See [Drag and drop reordering](#drag-and-drop-reordering). |
|
|
480
|
+
|
|
481
|
+
Disabled nodes can be moved to, but Enter, Space, the expand and collapse keys, `*` and the move keys leave them as they are. Visible nodes are those not hidden by a collapsed ancestor or by the filter. Other keys held with Ctrl, Alt or Meta, and keys pressed while an input method is composing text, are left to the page.
|
|
482
|
+
|
|
483
|
+
### Focus
|
|
484
|
+
|
|
485
|
+
The tree is the only Tab stop; individual nodes are not part of the page's tab order. Arrow-key navigation moves an internal active node pointer, reflected through `aria-activedescendant` on the tree element, instead of moving DOM focus between nodes. Clicking a node makes it the active node. When the tree regains focus, it restores the previously active node, or activates the first node if none was active yet; when the active node is hidden by a collapse or the filter, its nearest visible ancestor (else the first visible node) takes over. The active node has a solid 2px ring while the tree has focus; an empty tree stays a Tab stop and draws the ring around its "No data" or "No matching items" text. The filter input is a separate Tab stop before the tree, and it doesn't take focus when the tree renders.
|
|
486
|
+
|
|
487
|
+
### ARIA
|
|
488
|
+
|
|
489
|
+
The tree element is the `mona-tree` element inside `mona-tree-view`; the `mona-tree-view` host itself has no role.
|
|
490
|
+
|
|
491
|
+
| Element | Attribute | When present | Value |
|
|
492
|
+
| --------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
493
|
+
| Tree | `role` | Always | `tree` |
|
|
494
|
+
| Tree | `aria-label` | When the `aria-label` input is set | The `aria-label` value |
|
|
495
|
+
| Tree | `aria-labelledby` | When the `aria-labelledby` input is set | The `aria-labelledby` value |
|
|
496
|
+
| Tree | `aria-describedby` | When no node is shown | The "No data" or "No matching items" text |
|
|
497
|
+
| Tree | `aria-multiselectable` | When selectable with `mode: "multiple"` and not checkable | `true` |
|
|
498
|
+
| Tree | `aria-activedescendant` | While a node is active | The active node's element id |
|
|
499
|
+
| Tree | `aria-keyshortcuts` | With `monaTreeViewDragAndDrop` | The four Ctrl+Shift+arrow move keys |
|
|
500
|
+
| Child node list | `role` | The nested list of an expanded node | `group` |
|
|
501
|
+
| Node | `role` | Always | `treeitem` |
|
|
502
|
+
| Node | `aria-level`, `aria-setsize`, `aria-posinset` | Always | The node's depth and position among its visible siblings |
|
|
503
|
+
| Node | `aria-labelledby` | Always | The node's content, so the expander and nested nodes aren't part of its name |
|
|
504
|
+
| Node | `aria-expanded` | When `monaTreeViewExpandable` is on and the node has children (with an asynchronous `children`, when `hasChildren` says so) | `true` / `false`; `true` while its children load |
|
|
505
|
+
| Node | `aria-busy` | While its children load | `true` |
|
|
506
|
+
| Node | `aria-describedby` | When its children failed to load | "Couldn't load the items in {node}" |
|
|
507
|
+
| Node | `aria-selected` | When selectable is enabled and not checkable (a node reports one state; with checkboxes, selection is shown but not reported) | `true` / `false` |
|
|
508
|
+
| Node | `aria-disabled` | When the node is disabled | `true` |
|
|
509
|
+
| Node | `aria-checked` | When the node is checkable | `true` / `false` / `mixed` |
|
|
510
|
+
| Expander | `aria-label` | On each expander button (not a Tab stop) | "Expand {node}", "Collapse {node}", "Loading {node}" or "Retry loading {node}" |
|
|
511
|
+
| Filter | `role="search"`, `aria-label` | When filterable | A search landmark around the filter input, named like the input |
|
|
512
|
+
| Filter input | `aria-label`, `aria-controls` | When filterable | "Filter {name}" from the tree's name (or "Filter tree"), and the tree's id |
|
|
513
|
+
|
|
514
|
+
Name every tree with `aria-label` or `aria-labelledby`; in development, an unnamed tree logs a warning. The filter input's name is built from `aria-label`, or else from the text of the `aria-labelledby` elements. After the user types in the filter, the number of matching nodes is announced ("3 results", or "No matching items"); a filter set from code isn't announced. A keyboard move is announced once it's applied ("Apple moved into Fruits"). Each node's checkbox is hidden from assistive technology, because the node itself reports `aria-checked`. Announcements and labels are translated messages (`treeView` namespace); `TREE_VIEW_DEFAULT_MESSAGES` holds the English defaults.
|
|
515
|
+
|
|
516
|
+
## API
|
|
517
|
+
|
|
518
|
+
Everything below is imported from `@nanahoshi/mona-ui/tree-view`.
|
|
519
|
+
|
|
520
|
+
### `TreeViewComponent`
|
|
521
|
+
|
|
522
|
+
**Selector:** `mona-tree-view`
|
|
523
|
+
**Type parameters:** `T`
|
|
524
|
+
|
|
525
|
+
#### Inputs
|
|
526
|
+
|
|
527
|
+
| Name | Type | Default | Description |
|
|
528
|
+
| --- | --- | --- | --- |
|
|
529
|
+
| `animate` | `boolean` | `true` | Enables CSS transitions when nodes expand or collapse. Accepts the attribute form (`animate="false"`). |
|
|
530
|
+
| `aria-label` | `string` | `""` | Accessible name of the tree. Describe what the tree represents; it also names the filter input ("Filter {name}"). Set this or `aria-labelledby`: an unnamed tree logs a warning in development. A plain `aria-label` attribute on `mona-tree-view` doesn't name the tree. |
|
|
531
|
+
| `aria-labelledby` | `string` | `""` | Id of the element that names the tree, as an alternative to `aria-label`. |
|
|
532
|
+
| `children` | `ChildrenSelector<T>` | `""` | Property name or accessor used to derive a node's children from a data item. Accepts a property name, a function returning the children, or a function returning an observable of the children. |
|
|
533
|
+
| `data` | `Iterable<T>` | `[]` | Collection of items to render. |
|
|
534
|
+
| `hasChildren` | `Predicate<T> \| null` | `null` | Predicate that determines whether a node has children. Required when the children selector returns an observable. |
|
|
535
|
+
| `idField` | `string` | `""` | Property name that holds a node's unique identifier. Required when `mode` is set to `"flat"`. |
|
|
536
|
+
| `mode` | `DataStructure` | `"hierarchical"` | Shape of the source data: `"hierarchical"` for nested items via `children`, or `"flat"` for a flat list linked by `idField` and `parentIdField`. |
|
|
537
|
+
| `parentIdField` | `string` | `""` | Property name that holds a node's parent identifier. Required when `mode` is set to `"flat"`. |
|
|
538
|
+
| `textField` | `string \| Selector<T, string>` | `""` | Property name or accessor used to derive the display text from a data item. |
|
|
539
|
+
|
|
540
|
+
#### Outputs
|
|
541
|
+
|
|
542
|
+
| Name | Type | Description |
|
|
543
|
+
| --- | --- | --- |
|
|
544
|
+
| `blur` | `FocusEvent` | Emitted when the tree-view loses focus. |
|
|
545
|
+
| `childrenLoadError` | `ChildrenLoadErrorEvent<T>` | Emitted when the children observable of a node errors. The node is collapsed again and marked as failed (its expander reads "Retry loading {node}"), the failure is announced, and expanding the node retries the load. |
|
|
546
|
+
| `focus` | `FocusEvent` | Emitted when the tree-view gains focus. |
|
|
547
|
+
| `nodeClick` | `NodeClickEvent<T>` | Emitted when a node is clicked. |
|
|
548
|
+
|
|
549
|
+
#### Methods
|
|
550
|
+
|
|
551
|
+
| Signature | Description |
|
|
552
|
+
| --- | --- |
|
|
553
|
+
| `moveNode(source: NodeItem<T>, target: NodeItem<T>, position: DropPosition): NodeMoveSnapshot \| null` | Moves a node in the tree's internal structure, without going through `data`. |
|
|
554
|
+
| `undoMoveNode(snapshot: NodeMoveSnapshot): void` | Reverts a move previously performed by `moveNode`. |
|
|
555
|
+
|
|
556
|
+
### `TreeViewCheckableDirective`
|
|
557
|
+
|
|
558
|
+
**Selector:** `mona-tree-view[monaTreeViewCheckable]`
|
|
559
|
+
**Exported as:** `monaTreeViewCheckable`
|
|
560
|
+
**Type parameters:** `T`, `K = T`
|
|
561
|
+
|
|
562
|
+
#### Inputs
|
|
563
|
+
|
|
564
|
+
| Name | Type | Default | Description |
|
|
565
|
+
| --- | --- | --- | --- |
|
|
566
|
+
| `checkBy` | `NodeKeySelector<T, K> \| undefined` | `""` | Property name or accessor used to derive a node's check key from its data. Falls back to the node's data when unset. |
|
|
567
|
+
| `checkedKeys` | `Iterable<K>` | `[]` | Keys of the currently checked nodes. |
|
|
568
|
+
| `hasCheckbox` | `((data: T, uid: string) => boolean) \| null` | `null` | Predicate that determines whether a node displays a checkbox. When unset, every node displays a checkbox. |
|
|
569
|
+
| `monaTreeViewCheckable` | `Partial<CheckableOptions> \| ""` | `""` | Configures check mode and whether checking a node also checks its children or parents. Merged over `{ checkChildren: true, checkDisabledChildren: false, checkParents: true, childrenOnly: false, enabled: true, mode: "multiple" }` when applied bare. |
|
|
570
|
+
|
|
571
|
+
#### Outputs
|
|
572
|
+
|
|
573
|
+
| Name | Type | Description |
|
|
574
|
+
| --- | --- | --- |
|
|
575
|
+
| `checkedKeysChange` | `K[]` | Emitted with the checked keys when the user checks or unchecks a node, including the children and parents that check follows (`checkChildren`, `checkParents`). Not emitted for keys set through `checkedKeys`, nor for keys the tree derives on its own: checked parents of checked children set from code, lazily loaded children of a checked node, and ancestors after a drop. Those are reported with the next user change. |
|
|
576
|
+
| `nodeCheck` | `NodeCheckEvent<T>` | Emitted when a node is checked or unchecked. |
|
|
577
|
+
|
|
578
|
+
### `TreeViewExpandableDirective`
|
|
579
|
+
|
|
580
|
+
**Selector:** `mona-tree-view[monaTreeViewExpandable]`
|
|
581
|
+
**Exported as:** `monaTreeViewExpandable`
|
|
582
|
+
**Type parameters:** `T`, `K = T`
|
|
583
|
+
|
|
584
|
+
#### Inputs
|
|
585
|
+
|
|
586
|
+
| Name | Type | Default | Description |
|
|
587
|
+
| --- | --- | --- | --- |
|
|
588
|
+
| `expandBy` | `NodeKeySelector<T, K> \| undefined` | `""` | Property name or accessor used to derive a node's expand key from its data. Falls back to the node's data when unset. |
|
|
589
|
+
| `expandedKeys` | `Iterable<K>` | `[]` | Keys of the currently expanded nodes. |
|
|
590
|
+
| `monaTreeViewExpandable` | `Partial<ExpandableOptions> \| ""` | `""` | Configures whether expanding and collapsing nodes is enabled. Merged over `{ enabled: true }` when applied bare. |
|
|
591
|
+
|
|
592
|
+
#### Outputs
|
|
593
|
+
|
|
594
|
+
| Name | Type | Description |
|
|
595
|
+
| --- | --- | --- |
|
|
596
|
+
| `collapse` | `NodeItem<T>` | Emitted when a node is collapsed. |
|
|
597
|
+
| `expand` | `NodeItem<T>` | Emitted when a node is expanded. |
|
|
598
|
+
| `expandedKeysChange` | `K[]` | Emitted with the expanded keys when the user expands or collapses a node. Not emitted for keys set through `expandedKeys`, nor for the expansion a filter applies (which is undone when the filter is cleared). |
|
|
599
|
+
|
|
600
|
+
### `TreeViewSelectableDirective`
|
|
601
|
+
|
|
602
|
+
**Selector:** `mona-tree-view[monaTreeViewSelectable]`
|
|
603
|
+
**Exported as:** `monaTreeViewSelectable`
|
|
604
|
+
**Type parameters:** `T`, `K = T`
|
|
605
|
+
|
|
606
|
+
#### Inputs
|
|
607
|
+
|
|
608
|
+
| Name | Type | Default | Description |
|
|
609
|
+
| --- | --- | --- | --- |
|
|
610
|
+
| `monaTreeViewSelectable` | `Partial<SelectableOptions> \| ""` | `""` | Configures selection mode, toggleability, and whether only child nodes are selectable. Merged over `{ childrenOnly: false, enabled: true, mode: "single", toggleable: false }` when applied bare. |
|
|
611
|
+
| `selectBy` | `NodeKeySelector<T, K> \| undefined` | `""` | Property name or accessor used to derive a node's selection key from its data. Falls back to the node's data when unset. |
|
|
612
|
+
| `selectedKeys` | `Iterable<K>` | `[]` | Keys of the currently selected nodes. |
|
|
613
|
+
|
|
614
|
+
#### Outputs
|
|
615
|
+
|
|
616
|
+
| Name | Type | Description |
|
|
617
|
+
| --- | --- | --- |
|
|
618
|
+
| `nodeSelect` | `NodeSelectEvent<T>` | Emitted before the user selects or deselects a node, by click or Enter. Call `preventDefault()` to keep the selection as it is; `selectionChange` follows when it isn't prevented. |
|
|
619
|
+
| `selectedKeysChange` | `K[]` | Emitted with the selected keys when the user selects or deselects a node. Not emitted for keys set through `selectedKeys`. |
|
|
620
|
+
| `selectionChange` | `NodeItem<T>` | Emitted with the node after the user selects or deselects it (after a `nodeSelect` that wasn't prevented). |
|
|
621
|
+
|
|
622
|
+
### `TreeViewDragAndDropDirective`
|
|
623
|
+
|
|
624
|
+
**Selector:** `mona-tree-view[monaTreeViewDragAndDrop]`
|
|
625
|
+
**Exported as:** `monaTreeViewDragAndDrop`
|
|
626
|
+
**Type parameters:** `T`
|
|
627
|
+
|
|
628
|
+
#### Inputs
|
|
629
|
+
|
|
630
|
+
| Name | Type | Default | Description |
|
|
631
|
+
| --- | --- | --- | --- |
|
|
632
|
+
| `monaTreeViewDragAndDrop` | `Partial<DraggableOptions> \| ""` | `""` | Configures whether dragging nodes to reorder or reparent them is enabled. Merged over `{ enabled: true }` when applied bare. |
|
|
633
|
+
|
|
634
|
+
#### Outputs
|
|
635
|
+
|
|
636
|
+
| Name | Type | Description |
|
|
637
|
+
| --- | --- | --- |
|
|
638
|
+
| `nodeDrag` | `NodeDragEvent<T>` | Emitted while a node is being dragged. |
|
|
639
|
+
| `nodeDragEnd` | `NodeDragEndEvent<T>` | Emitted when a node drag ends, dropped or not. Not cancelable: the drag is over either way. |
|
|
640
|
+
| `nodeDragStart` | `NodeDragStartEvent<T>` | Emitted when a node drag starts. |
|
|
641
|
+
| `nodeDrop` | `NodeDropEvent<T>` | Emitted when a node is dropped on another node, or moved with Ctrl+Shift+Arrow (Cmd+Shift+Arrow on macOS). The tree doesn't move the node: the handler applies the move (with `moveTreeNode`, `moveFlatTreeNode` or `event.treeView.moveNode`). Call `preventDefault()` when the move isn't applied. |
|
|
642
|
+
|
|
643
|
+
### `TreeViewFilterableDirective`
|
|
644
|
+
|
|
645
|
+
**Selector:** `mona-tree-view[monaTreeViewFilterable]`
|
|
646
|
+
**Exported as:** `monaTreeViewFilterable`
|
|
647
|
+
**Type parameters:** `T`
|
|
648
|
+
|
|
649
|
+
#### Inputs
|
|
650
|
+
|
|
651
|
+
| Name | Type | Default | Description |
|
|
652
|
+
| --- | --- | --- | --- |
|
|
653
|
+
| `filter` (two-way) | `string` | `""` | Current filter text used to narrow the visible nodes. Two-way bindable (`[(filter)]`); the user's typing updates it, so setting it from code (including back to `""`) always applies. |
|
|
654
|
+
| `filterPlaceholder` | `string` | `""` | Placeholder text shown in the filter input. |
|
|
655
|
+
| `monaTreeViewFilterable` | `Partial<FilterableOptions> \| ""` | `""` | Configures the filter operator, case sensitivity, and debounce delay. Merged over `{ enabled: true, operator: "contains", caseSensitive: false, debounce: 0 }` when applied bare. |
|
|
656
|
+
|
|
657
|
+
#### Outputs
|
|
658
|
+
|
|
659
|
+
| Name | Type | Description |
|
|
660
|
+
| --- | --- | --- |
|
|
661
|
+
| `filterChange` | `string` | Emitted when `filter` changes. |
|
|
662
|
+
| `filterInput` | `FilterChangeEvent` | Emitted when the user types in the filter input, before the filter applies. Call `preventDefault()` to keep the current filter; otherwise `filterChange` reports the new text. |
|
|
663
|
+
|
|
664
|
+
### `TreeViewDisableDirective`
|
|
665
|
+
|
|
666
|
+
**Selector:** `mona-tree-view[monaTreeViewDisable]`
|
|
667
|
+
**Exported as:** `monaTreeViewDisable`
|
|
668
|
+
**Type parameters:** `T`, `K = T`
|
|
669
|
+
|
|
670
|
+
#### Inputs
|
|
671
|
+
|
|
672
|
+
| Name | Type | Default | Description |
|
|
673
|
+
| --- | --- | --- | --- |
|
|
674
|
+
| `disableBy` | `NodeKeySelector<T, K> \| undefined` | `""` | Property name or accessor used to derive a node's disable key from its data. Falls back to the node's data when unset. |
|
|
675
|
+
| `disabledKeys` | `Iterable<K>` | `[]` | Keys of the currently disabled nodes. |
|
|
676
|
+
| `monaTreeViewDisable` | `Partial<DisableOptions> \| ""` | `""` | Configures whether disabling a node also disables its children. Merged over `{ disableChildren: true, enabled: true }` when applied bare. |
|
|
677
|
+
|
|
678
|
+
### `TreeViewNodeTemplateDirective`
|
|
679
|
+
|
|
680
|
+
Template for each node's content. The data item is the template's implicit value (`let-dataItem`) and the node's
|
|
681
|
+
element is `element`. Bind the tree view's data to `monaTreeViewNodeTemplateOf` to type the data item; without it,
|
|
682
|
+
the data item is `any` in templates.
|
|
683
|
+
|
|
684
|
+
**Selector:** `ng-template[monaTreeViewNodeTemplate]`
|
|
685
|
+
**Type parameters:** `T = any`
|
|
686
|
+
|
|
687
|
+
#### Inputs
|
|
688
|
+
|
|
689
|
+
| Name | Type | Default | Description |
|
|
690
|
+
| --- | --- | --- | --- |
|
|
691
|
+
| `monaTreeViewNodeTemplateOf` | `Iterable<T> \| null \| undefined` | `null` | The tree view's data, used only to type the template's data item. Optional. |
|
|
692
|
+
|
|
693
|
+
#### Template context
|
|
694
|
+
|
|
695
|
+
| Name | Type | Description |
|
|
696
|
+
| --- | --- | --- |
|
|
697
|
+
| `$implicit` | `T` | The node's data item (`let-dataItem`). |
|
|
698
|
+
| `element` | `HTMLElement` | The node's element (`let-element="element"`). |
|
|
699
|
+
|
|
700
|
+
### `NodeCheckEvent`
|
|
701
|
+
|
|
702
|
+
**Type parameters:** `T`
|
|
703
|
+
**Extends:** `PreventableEvent`
|
|
704
|
+
|
|
705
|
+
#### Properties
|
|
706
|
+
|
|
707
|
+
| Name | Type |
|
|
708
|
+
| --- | --- |
|
|
709
|
+
| `nodeItem` (read-only) | `NodeItem<T>` |
|
|
710
|
+
|
|
711
|
+
### `NodeClickEvent`
|
|
712
|
+
|
|
713
|
+
**Type parameters:** `T`
|
|
714
|
+
**Extends:** `PreventableEvent`
|
|
715
|
+
|
|
716
|
+
#### Properties
|
|
717
|
+
|
|
718
|
+
| Name | Type |
|
|
719
|
+
| --- | --- |
|
|
720
|
+
| `nodeItem` (read-only) | `NodeItem<T>` |
|
|
721
|
+
|
|
722
|
+
### `NodeDragEndEvent`
|
|
723
|
+
|
|
724
|
+
**Type parameters:** `T`
|
|
725
|
+
|
|
726
|
+
#### Properties
|
|
727
|
+
|
|
728
|
+
| Name | Type |
|
|
729
|
+
| --- | --- |
|
|
730
|
+
| `nodeItem` (read-only) | `NodeItem<T>` |
|
|
731
|
+
|
|
732
|
+
### `NodeDragEvent`
|
|
733
|
+
|
|
734
|
+
**Type parameters:** `T`
|
|
735
|
+
|
|
736
|
+
#### Properties
|
|
737
|
+
|
|
738
|
+
| Name | Type |
|
|
739
|
+
| --- | --- |
|
|
740
|
+
| `nodeItem` (read-only) | `NodeItem<T>` |
|
|
741
|
+
| `originalEvent` (read-only) | `MouseEvent \| TouchEvent` |
|
|
742
|
+
| `targetNodeItem` (read-only) | `NodeItem<T> \| null` |
|
|
743
|
+
| `type` (read-only) | `string` |
|
|
744
|
+
|
|
745
|
+
### `NodeDragStartEvent`
|
|
746
|
+
|
|
747
|
+
**Type parameters:** `T`
|
|
748
|
+
|
|
749
|
+
#### Properties
|
|
750
|
+
|
|
751
|
+
| Name | Type |
|
|
752
|
+
| --- | --- |
|
|
753
|
+
| `nodeItem` (read-only) | `NodeItem<T>` |
|
|
754
|
+
|
|
755
|
+
### `NodeDropEvent`
|
|
756
|
+
|
|
757
|
+
A request to move a node: a drop, or a keyboard move (Ctrl+Shift+Arrow), whose original event is then the
|
|
758
|
+
`KeyboardEvent`.
|
|
759
|
+
|
|
760
|
+
**Type parameters:** `T`
|
|
761
|
+
|
|
762
|
+
#### Properties
|
|
763
|
+
|
|
764
|
+
| Name | Type |
|
|
765
|
+
| --- | --- |
|
|
766
|
+
| `nodeItem` (read-only) | `NodeItem<T>` |
|
|
767
|
+
| `position` (read-only) | `DropPosition` |
|
|
768
|
+
| `sourceNode` (read-only) | `NodeItem<T>` |
|
|
769
|
+
| `targetNode` (read-only) | `NodeItem<T>` |
|
|
770
|
+
| `treeView` (read-only) | `ITreeView<T>` |
|
|
771
|
+
|
|
772
|
+
### `NodeSelectEvent`
|
|
773
|
+
|
|
774
|
+
**Type parameters:** `T`
|
|
775
|
+
**Extends:** `PreventableEvent`
|
|
776
|
+
|
|
777
|
+
#### Properties
|
|
778
|
+
|
|
779
|
+
| Name | Type |
|
|
780
|
+
| --- | --- |
|
|
781
|
+
| `nodeItem` (read-only) | `NodeItem<T>` |
|
|
782
|
+
|
|
783
|
+
### `TreeNode`
|
|
784
|
+
|
|
785
|
+
A node of a tree, wrapping its data item. Read `data`, `uid` and `nodeItem`; the tree keeps the rest, and writing to it
|
|
786
|
+
would put the node out of step with the tree.
|
|
787
|
+
|
|
788
|
+
**Type parameters:** `T`
|
|
789
|
+
|
|
790
|
+
#### Properties
|
|
791
|
+
|
|
792
|
+
| Name | Type | Description |
|
|
793
|
+
| --- | --- | --- |
|
|
794
|
+
| `data` (read-only) | `T` | The data item this node was created from. |
|
|
795
|
+
| `nodeItem` (read-only) | `NodeItem<T>` | A plain snapshot of the node (its data, uid and whether it has children), as the tree view's events carry it. |
|
|
796
|
+
| `uid` (read-only) | `string` | A unique id generated for the node when it is created. |
|
|
797
|
+
|
|
798
|
+
### `moveFlatTreeNode`
|
|
799
|
+
|
|
800
|
+
Moves a node within a generic flat tree structure that uses parentId references.
|
|
801
|
+
|
|
802
|
+
```typescript
|
|
803
|
+
function moveFlatTreeNode<T extends object>(treeData: Iterable<T>, event: NodeDropEvent<T>, idKey: keyof T, parentIdKey: keyof T): T[];
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
### `moveTreeNode`
|
|
807
|
+
|
|
808
|
+
Moves a node within a generic hierarchical tree structure.
|
|
809
|
+
|
|
810
|
+
```typescript
|
|
811
|
+
function moveTreeNode<T extends object>(treeData: Iterable<T>, event: NodeDropEvent<T>, idKey: keyof T, childrenKey: keyof T): T[];
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
### Types
|
|
815
|
+
|
|
816
|
+
#### `TREE_VIEW_DEFAULT_MESSAGES`
|
|
817
|
+
|
|
818
|
+
```typescript
|
|
819
|
+
const TREE_VIEW_DEFAULT_MESSAGES: MonaTreeViewMessages;
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
#### `ITreeView`
|
|
823
|
+
|
|
824
|
+
**Type parameters:** `T`
|
|
825
|
+
|
|
826
|
+
**Methods**
|
|
827
|
+
|
|
828
|
+
| Signature |
|
|
829
|
+
| --- |
|
|
830
|
+
| `moveNode(source: NodeItem<T>, target: NodeItem<T>, position: DropPosition): NodeMoveSnapshot \| null` |
|
|
831
|
+
| `undoMoveNode(snapshot: NodeMoveSnapshot): void` |
|
|
832
|
+
|
|
833
|
+
#### `CheckableOptions`
|
|
834
|
+
|
|
835
|
+
| Name | Type | Description |
|
|
836
|
+
| --- | --- | --- |
|
|
837
|
+
| `checkChildren?` | `boolean` | Determines whether checking a node should also check its children. Only applicable when `mode` is set to `multiple`. |
|
|
838
|
+
| `checkDisabledChildren?` | `boolean` | Determines whether checking a node should also check its disabled children. Only applicable when `mode` is set to `multiple`. |
|
|
839
|
+
| `checkParents?` | `boolean` | Determines whether checking a node should also check its parents. Only applicable when `mode` is set to `multiple`. |
|
|
840
|
+
| `childrenOnly?` | `boolean` | Determines whether only the children of the node should be checkable. |
|
|
841
|
+
| `enabled?` | `boolean` | Determines if the checkboxes are enabled. |
|
|
842
|
+
| `mode?` | `"multiple" \| "single"` | Specifies the check mode. |
|
|
843
|
+
|
|
844
|
+
#### `ChildrenLoadErrorEvent`
|
|
845
|
+
|
|
846
|
+
Reports that the children of a node couldn't be loaded from an asynchronous children selector. The node is
|
|
847
|
+
collapsed again, and expanding it retries the load.
|
|
848
|
+
|
|
849
|
+
**Type parameters:** `T`
|
|
850
|
+
|
|
851
|
+
| Name | Type | Description |
|
|
852
|
+
| --- | --- | --- |
|
|
853
|
+
| `error` (read-only) | `unknown` | What the children observable errored with. |
|
|
854
|
+
| `node` (read-only) | `NodeItem<T>` | The node whose children failed to load. |
|
|
855
|
+
|
|
856
|
+
#### `DisableOptions`
|
|
857
|
+
|
|
858
|
+
| Name | Type | Description |
|
|
859
|
+
| --- | --- | --- |
|
|
860
|
+
| `disableChildren` | `boolean` | Determines whether the children of the node should be disabled as well. |
|
|
861
|
+
| `enabled` | `boolean` | Determines if the disabling is enabled. |
|
|
862
|
+
|
|
863
|
+
#### `DraggableOptions`
|
|
864
|
+
|
|
865
|
+
| Name | Type | Description |
|
|
866
|
+
| --- | --- | --- |
|
|
867
|
+
| `enabled` | `boolean` | Determines if the dragging is enabled. |
|
|
868
|
+
|
|
869
|
+
#### `DropPositionChangeEvent`
|
|
870
|
+
|
|
871
|
+
**Type parameters:** `T`
|
|
872
|
+
|
|
873
|
+
| Name | Type |
|
|
874
|
+
| --- | --- |
|
|
875
|
+
| `position` | `DropPosition` |
|
|
876
|
+
| `targetNode` | `TreeNode<T> \| null` |
|
|
877
|
+
|
|
878
|
+
#### `ExpandableOptions`
|
|
879
|
+
|
|
880
|
+
| Name | Type | Description |
|
|
881
|
+
| --- | --- | --- |
|
|
882
|
+
| `enabled` | `boolean` | Determines if the expanding is enabled. |
|
|
883
|
+
|
|
884
|
+
#### `MultipleSelectionConfig`
|
|
885
|
+
|
|
886
|
+
| Name | Type | Description |
|
|
887
|
+
| --- | --- | --- |
|
|
888
|
+
| `mode` | `"multiple"` | Allows multiple items to be selected simultaneously. |
|
|
889
|
+
|
|
890
|
+
#### `NodeItem`
|
|
891
|
+
|
|
892
|
+
**Type parameters:** `T`
|
|
893
|
+
|
|
894
|
+
| Name | Type |
|
|
895
|
+
| --- | --- |
|
|
896
|
+
| `data` | `T` |
|
|
897
|
+
| `hasChildren` | `boolean` |
|
|
898
|
+
| `uid` | `string` |
|
|
899
|
+
|
|
900
|
+
#### `NodeMoveSnapshot`
|
|
901
|
+
|
|
902
|
+
| Name | Type |
|
|
903
|
+
| --- | --- |
|
|
904
|
+
| `originalIndex` (read-only) | `number` |
|
|
905
|
+
| `originalParentUid` (read-only) | `string \| null` |
|
|
906
|
+
| `sourceNodeUid` (read-only) | `string` |
|
|
907
|
+
|
|
908
|
+
#### `SingleSelectionConfig`
|
|
909
|
+
|
|
910
|
+
| Name | Type | Description |
|
|
911
|
+
| --- | --- | --- |
|
|
912
|
+
| `mode` | `"single"` | Allows only one item to be selected at a time. |
|
|
913
|
+
| `toggleable?` | `boolean` | Determines if clicking an already selected item will deselect it. |
|
|
914
|
+
|
|
915
|
+
#### `TreeViewNodeTemplateContext`
|
|
916
|
+
|
|
917
|
+
The context of a `monaTreeViewNodeTemplate`.
|
|
918
|
+
|
|
919
|
+
**Type parameters:** `T`
|
|
920
|
+
|
|
921
|
+
| Name | Type | Description |
|
|
922
|
+
| --- | --- | --- |
|
|
923
|
+
| `$implicit` (read-only) | `T` | The node's data item (`let-dataItem`). |
|
|
924
|
+
| `element` (read-only) | `HTMLElement` | The node's element (`let-element="element"`). |
|
|
925
|
+
|
|
926
|
+
#### `ChildrenSelector`
|
|
927
|
+
|
|
928
|
+
```typescript
|
|
929
|
+
type ChildrenSelector<T> = string | Selector<T, Iterable<T> | Observable<Iterable<T>>>;
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
#### `DataStructure`
|
|
933
|
+
|
|
934
|
+
```typescript
|
|
935
|
+
type DataStructure = "flat" | "hierarchical";
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
#### `DropPosition`
|
|
939
|
+
|
|
940
|
+
```typescript
|
|
941
|
+
type DropPosition = "before" | "after" | "inside" | "outside";
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
#### `NodeDropOriginalEvent`
|
|
945
|
+
|
|
946
|
+
The event behind a `nodeDrop`: the pointer event of a drop, or the key press of a keyboard move.
|
|
947
|
+
|
|
948
|
+
```typescript
|
|
949
|
+
type NodeDropOriginalEvent = MouseEvent | TouchEvent | KeyboardEvent;
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
#### `NodeKeySelector`
|
|
953
|
+
|
|
954
|
+
```typescript
|
|
955
|
+
type NodeKeySelector<T, K = unknown> = string | Selector<T, K> | null;
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
#### `SelectableOptions`
|
|
959
|
+
|
|
960
|
+
```typescript
|
|
961
|
+
type SelectableOptions = { enabled: boolean; childrenOnly: boolean; } & (SingleSelectionConfig | MultipleSelectionConfig);
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
#### `FilterChangeEvent`
|
|
965
|
+
|
|
966
|
+
From `@nanahoshi/mona-ui/common`.
|
|
967
|
+
|
|
968
|
+
**Extends:** `PreventableEvent`
|
|
969
|
+
|
|
970
|
+
| Name | Type |
|
|
971
|
+
| --- | --- |
|
|
972
|
+
| `filter` (read-only) | `string` |
|
|
973
|
+
|
|
974
|
+
#### `MonaTreeViewMessages`
|
|
975
|
+
|
|
976
|
+
From `@nanahoshi/mona-ui/i18n`.
|
|
977
|
+
|
|
978
|
+
| Name | Type | Description |
|
|
979
|
+
| --- | --- | --- |
|
|
980
|
+
| `collapse` (read-only) | `string` | Start of an expanded node's expander name, followed by the node's text ("Collapse Documents"). |
|
|
981
|
+
| `expand` (read-only) | `string` | Start of a collapsed node's expander name, followed by the node's text ("Expand Documents"). |
|
|
982
|
+
| `filter` (read-only) | `string` | **Deprecated.** No longer rendered; the filter input's name comes from `filterLabel`. |
|
|
983
|
+
| `filterTree` (read-only) | `string` | Accessible name of the filter input when the tree view has no `aria-label`. |
|
|
984
|
+
| `noData` (read-only) | `string` | Shown, and describes the tree, when the tree view has no data. |
|
|
985
|
+
| `noMatches` (read-only) | `string` | Shown, describes the tree and is announced, when no node matches the filter. |
|
|
986
|
+
|
|
987
|
+
**Methods**
|
|
988
|
+
|
|
989
|
+
| Signature | Description |
|
|
990
|
+
| --- | --- |
|
|
991
|
+
| `filterLabel(tree: string): string` | Accessible name of the filter input, from the tree view's name ("Filter Files"). |
|
|
992
|
+
| `loadError(node: string): string` | Announced, and read with the node, when a node's children couldn't be loaded. |
|
|
993
|
+
| `loadingNode(node: string): string` | Announced while a node's children take a while to load, and the expander's name meanwhile. |
|
|
994
|
+
| `movedAfter(node: string, target: string): string` | Announced when a keyboard move (Ctrl+Shift+Arrow) put a node after another node. |
|
|
995
|
+
| `movedBefore(node: string, target: string): string` | Announced when a keyboard move put a node before another node. |
|
|
996
|
+
| `movedInto(node: string, target: string): string` | Announced when a keyboard move put a node inside another node, as its last child. |
|
|
997
|
+
| `results(count: number): string` | Announced after the user filters, with the number of nodes that match. |
|
|
998
|
+
| `retryLoading(node: string): string` | Name of the expander of a node whose children couldn't be loaded. |
|
|
999
|
+
|
|
1000
|
+
#### `PreventableEvent`
|
|
1001
|
+
|
|
1002
|
+
From `@nanahoshi/mona-ui/common`.
|
|
1003
|
+
|
|
1004
|
+
**Type parameters:** `E extends Event = Event`
|
|
1005
|
+
|
|
1006
|
+
| Name | Type | Description |
|
|
1007
|
+
| --- | --- | --- |
|
|
1008
|
+
| `originalEvent` (read-only) | `E \| undefined` | The DOM event that caused this one, when there is one. |
|
|
1009
|
+
| `type` (read-only) | `string \| undefined` | A name for the kind of event, when the component that emits it sets one. |
|
|
1010
|
+
|
|
1011
|
+
**Methods**
|
|
1012
|
+
|
|
1013
|
+
| Signature | Description |
|
|
1014
|
+
| --- | --- |
|
|
1015
|
+
| `isDefaultPrevented(): boolean` | Whether `preventDefault()` was called. |
|
|
1016
|
+
| `preventDefault(): void` | Cancels what the event announces, such as opening or closing a popup, or closing a dialog. |
|
|
1017
|
+
|
|
1018
|
+
**Documented elsewhere:** [`FilterableOptions`](grid.md)
|