@nanahoshi/mona-ui 0.36.1 → 0.38.0
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/docs/api/common.md +1 -1
- package/docs/api/dropdown-list.md +2 -0
- package/docs/api/dropdown-tree.md +81 -0
- package/docs/api/dropdowns.md +34 -8
- package/docs/api/editor.md +67 -0
- package/docs/api/file-upload.md +1 -1
- package/docs/api/i18n.md +49 -4
- package/docs/api/list.md +1 -1
- package/docs/api/locales.md +14 -14
- package/docs/api/multi-select-tree.md +75 -0
- package/docs/api/multi-select.md +3 -1
- package/docs/api/popup.md +1 -1
- package/docs/api/tree-view.md +2 -2
- package/docs/auto-complete.md +2 -0
- package/docs/combo-box.md +2 -0
- package/docs/dropdown-list.md +52 -0
- package/docs/dropdown-tree.md +427 -0
- package/docs/editor.md +238 -9
- package/docs/multi-select-tree.md +353 -0
- package/docs/multi-select.md +6 -0
- package/dropdown-tree/package.json +4 -0
- package/fesm2022/nanahoshi-mona-ui-dropdown-list.mjs +40 -5
- package/fesm2022/nanahoshi-mona-ui-dropdown-tree.mjs +1061 -0
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +701 -60
- package/fesm2022/nanahoshi-mona-ui-editor.mjs +1356 -192
- package/fesm2022/nanahoshi-mona-ui-file-upload.mjs +28 -94
- package/fesm2022/nanahoshi-mona-ui-filter.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +2 -0
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +63 -1
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +80 -37
- package/fesm2022/nanahoshi-mona-ui-internal.mjs +83 -2
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +66 -1
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +30 -1
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +42 -1
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +42 -1
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +24 -1
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +42 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +24 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +24 -1
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +64 -1
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +42 -1
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +64 -1
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +24 -1
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +24 -1
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +24 -1
- package/fesm2022/nanahoshi-mona-ui-multi-select-tree.mjs +1179 -0
- package/fesm2022/nanahoshi-mona-ui-multi-select.mjs +42 -7
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +3 -1
- package/fesm2022/nanahoshi-mona-ui-tree-view.mjs +2 -1
- package/i18n/catalogs/en-US.messages.json +26 -1
- package/llms.txt +7 -3
- package/locales/ar-sa/ar-sa.messages.json +26 -1
- package/locales/de-de/de-de.messages.json +26 -1
- package/locales/es-es/es-es.messages.json +26 -1
- package/locales/fr-fr/fr-fr.messages.json +26 -1
- package/locales/id-id/id-id.messages.json +26 -1
- package/locales/it-it/it-it.messages.json +26 -1
- package/locales/ja-jp/ja-jp.messages.json +26 -1
- package/locales/ko-kr/ko-kr.messages.json +26 -1
- package/locales/pl-pl/pl-pl.messages.json +26 -1
- package/locales/pt-br/pt-br.messages.json +26 -1
- package/locales/ru-ru/ru-ru.messages.json +26 -1
- package/locales/tr-tr/tr-tr.messages.json +26 -1
- package/locales/zh-cn/zh-cn.messages.json +26 -1
- package/locales/zh-tw/zh-tw.messages.json +26 -1
- package/multi-select-tree/package.json +4 -0
- package/package.json +9 -1
- package/types/nanahoshi-mona-ui-dropdown-list.d.ts +33 -5
- package/types/nanahoshi-mona-ui-dropdown-tree.d.ts +414 -0
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +198 -8
- package/types/nanahoshi-mona-ui-editor.d.ts +124 -2
- package/types/nanahoshi-mona-ui-file-upload.d.ts +1 -0
- package/types/nanahoshi-mona-ui-i18n.d.ts +44 -0
- package/types/nanahoshi-mona-ui-internal-tree.d.ts +36 -0
- package/types/nanahoshi-mona-ui-internal.d.ts +37 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +25 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +25 -0
- package/types/nanahoshi-mona-ui-multi-select-tree.d.ts +456 -0
- package/types/nanahoshi-mona-ui-multi-select.d.ts +43 -7
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# `@nanahoshi/mona-ui/multi-select-tree`
|
|
2
|
+
|
|
3
|
+
Everything `@nanahoshi/mona-ui/multi-select-tree` exports.
|
|
4
|
+
|
|
5
|
+
**Guides:** [Multi Select Tree](../multi-select-tree.md)
|
|
6
|
+
|
|
7
|
+
## `MultiSelectTreeComponent`
|
|
8
|
+
|
|
9
|
+
Component.
|
|
10
|
+
|
|
11
|
+
**Selector:** `mona-multi-select-tree`
|
|
12
|
+
**Type parameters:** `TData = unknown`, `TValue = TData`
|
|
13
|
+
**Implements:** `FormValueControl<Iterable<TValue>>`
|
|
14
|
+
|
|
15
|
+
### Inputs
|
|
16
|
+
|
|
17
|
+
| Name | Type | Default | Description |
|
|
18
|
+
| --- | --- | --- | --- |
|
|
19
|
+
| `adaptiveMode` | `AdaptiveMode` | `"none"` | Opens the popup as a sheet along the bottom of the screen on a small screen (narrower than 640 pixels) with `"auto"`, so it's easy to reach with a thumb. With `"none"`, it always opens under the field. |
|
|
20
|
+
| `adaptiveTitle` | `string` | `""` | Title of the bottom sheet the popup opens as with `adaptiveMode="auto"`. When empty, the sheet shows the field's name. |
|
|
21
|
+
| `aria-describedby` | `string` | `""` | ID of an element that describes the multi-select tree, such as help text or an error message. |
|
|
22
|
+
| `aria-label` | `string` | `""` | Accessible name of the multi-select tree. Describe what it represents. Falls back to `placeholder` when neither this nor `aria-labelledby` is set. |
|
|
23
|
+
| `aria-labelledby` | `string` | `""` | ID of an external element that provides the accessible name of the multi-select tree. |
|
|
24
|
+
| `checkChildren` | `boolean` | `true` | Whether checking an item checks its children too, and unchecking it unchecks them. |
|
|
25
|
+
| `checkParents` | `boolean` | `true` | Whether an item is checked when all its children are, and unchecked when one of them isn't. An item with only some of its children checked shows a mixed checkbox. |
|
|
26
|
+
| `children` | `ChildrenSelector<TData>` | `""` | Property name or accessor that gives a node's children, for `mode="hierarchical"`. An accessor may return an observable, which loads the children when the node is first opened; set `hasChildren` with it. |
|
|
27
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`. |
|
|
28
|
+
| `data` | `Iterable<TData>` | `[]` | The items of the tree: its root items for `mode="hierarchical"`, or every item for `mode="flat"`. |
|
|
29
|
+
| `disabled` | `boolean` | `false` | Disables the component, preventing the popup from opening and blocking tag removal. |
|
|
30
|
+
| `hasChildren` | `Predicate<TData> \| null` | `null` | Whether an item has children, before they load. Needed when `children` returns an observable. |
|
|
31
|
+
| `idField` | `string` | `""` | Property name that holds an item's unique id, for `mode="flat"`. |
|
|
32
|
+
| `invalid` | `boolean` | `false` | Marks the multi-select tree as invalid. When bound to a signal form field via `[formField]`, this is written by the `FormField` directive. |
|
|
33
|
+
| `itemDisabled` | `DropdownFieldPredicateType<TData>` | `undefined` | Predicate or field name that tells whether an item is disabled. A disabled item can't be checked or opened, and neither can its children; checking its parent leaves it as it is. |
|
|
34
|
+
| `loading` | `boolean` | `false` | Shows a loading indicator, in place of the clear button, and marks the field busy. It doesn't block interaction: the field stays usable while data loads. |
|
|
35
|
+
| `mode` | `DataStructure` | `"hierarchical"` | Shape of `data`: `"hierarchical"` for items that hold their children (see `children`), or `"flat"` for one list linked by `idField` and `parentIdField`. |
|
|
36
|
+
| `parentIdField` | `string` | `""` | Property name that holds an item's parent id, for `mode="flat"`. Items without one are roots. |
|
|
37
|
+
| `placeholder` | `string` | `""` | Text shown when nothing is checked. It also names the multi-select tree when neither `aria-label` nor `aria-labelledby` is set. |
|
|
38
|
+
| `popupClass` | `string` | `""` | Additional CSS classes applied to the popup element. |
|
|
39
|
+
| `popupHeight` | `ListSizeInputType` | `null` | Maximum height of the popup, in pixels or as a CSS length. Shorter trees shrink to fit. When unset, the popup is at most 200 pixels tall. |
|
|
40
|
+
| `popupWidth` | `ListSizeInputType` | `null` | Width of the popup element. When unset, the popup is as wide as the field. |
|
|
41
|
+
| `readonly` | `boolean` | `false` | Prevents value changes while preserving the component's visual state. |
|
|
42
|
+
| `required` | `boolean` | `false` | Marks the field as required: at least one item has to be checked. |
|
|
43
|
+
| `rounded` | `"full" \| "large" \| "medium" \| "none" \| "small"` | `"medium"` | Border-radius preset applied to the component. |
|
|
44
|
+
| `showClearButton` | `boolean` | `false` | Shows a button that unchecks every item when at least one is checked. |
|
|
45
|
+
| `size` | `"large" \| "medium" \| "small"` | `"medium"` | Size preset controlling the component's dimensions. |
|
|
46
|
+
| `textField` | `DropdownFieldSelectorType<TData, string>` | `undefined` | Property name or accessor that gives an item's text. When unset, the item itself is the text. |
|
|
47
|
+
| `touched` | `boolean` | `false` | Marks the control as touched. Set automatically by the `FormField` directive when bound via `[formField]`. |
|
|
48
|
+
| `value` (two-way) | `Iterable<TValue>` | `[]` | The checked items, two-way bindable and compatible with Signal Forms via `[formField]`: the data items, or with `valuePrimitive`, the values `valueField` gives for them. A user's change lists them in the tree's order. Nothing checked is an empty array. |
|
|
49
|
+
| `valueField` | `DropdownFieldSelectorType<TData, unknown>` | `undefined` | Property name or accessor that gives an item's value: what identifies the item, matches the values set from code to their nodes, and is the value with `valuePrimitive`. When unset, the item itself is the value. It should be a stable, unique scalar. |
|
|
50
|
+
| `valuePrimitive` | `boolean` | `false` | Whether the value holds what `valueField` gives for the checked items (`true`), or the items themselves (`false`). |
|
|
51
|
+
|
|
52
|
+
### Outputs
|
|
53
|
+
|
|
54
|
+
| Name | Type | Description |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `close` | `PopupCloseEvent<unknown>` | Emitted when the popup is about to close. This event is preventable. |
|
|
57
|
+
| `closed` | `void` | Emitted after the popup closes. |
|
|
58
|
+
| `open` | `PreventableEvent<Event>` | Emitted when the popup is about to open. This event is preventable. |
|
|
59
|
+
| `opened` | `void` | Emitted after the popup opens. |
|
|
60
|
+
| `touch` | `void` | Emitted when focus leaves the multi-select tree. Moving between it, its tags, its clear button and its popup doesn't count. The `FormField` directive listens to this to mark the field as touched. |
|
|
61
|
+
| `valueChange` | `Iterable<TValue>` | Emitted when `value` changes. |
|
|
62
|
+
|
|
63
|
+
### Methods
|
|
64
|
+
|
|
65
|
+
| Signature | Description |
|
|
66
|
+
| --- | --- |
|
|
67
|
+
| `focus(options?: FocusOptions): void` | Moves focus to the multi-select tree. |
|
|
68
|
+
|
|
69
|
+
## `MULTI_SELECT_TREE_DEFAULT_MESSAGES`
|
|
70
|
+
|
|
71
|
+
Constant.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const MULTI_SELECT_TREE_DEFAULT_MESSAGES: MonaMultiSelectTreeMessages;
|
|
75
|
+
```
|
package/docs/api/multi-select.md
CHANGED
|
@@ -16,6 +16,8 @@ Component.
|
|
|
16
16
|
|
|
17
17
|
| Name | Type | Default | Description |
|
|
18
18
|
| --- | --- | --- | --- |
|
|
19
|
+
| `adaptiveMode` | `AdaptiveMode` | `"none"` | Opens the popup as a sheet along the bottom of the screen on a small screen (narrower than 640 pixels) with `"auto"`, so it's easy to reach with a thumb. With `"none"`, it always opens under the field. |
|
|
20
|
+
| `adaptiveTitle` | `string` | `""` | Title of the bottom sheet the popup opens as with `adaptiveMode="auto"`. When empty, the sheet shows the field's name. |
|
|
19
21
|
| `allowCustomValue` | `boolean` | `false` | Lets people add values that aren't in `data`: Enter in the popup's filter box, on text that matches no item, emits `valueAdd` with the text, and an item whose text it matches is selected instead. Needs `monaDropDownFilterable`, whose filter box is where the text is typed. |
|
|
20
22
|
| `aria-describedby` | `string` | `""` | ID of an element that describes the multi select, such as help text or an error message. |
|
|
21
23
|
| `aria-label` | `string` | `""` | Accessible name for the multi select. Describe what it represents. Falls back to `placeholder` when neither this nor `aria-labelledby` is set. |
|
|
@@ -66,7 +68,7 @@ Component.
|
|
|
66
68
|
|
|
67
69
|
Directive.
|
|
68
70
|
|
|
69
|
-
**Selector:** `mona-multi-select[monaMultiSelectSummaryTag]`
|
|
71
|
+
**Selector:** `mona-multi-select[monaMultiSelectSummaryTag], mona-multi-select-tree[monaMultiSelectSummaryTag]`
|
|
70
72
|
|
|
71
73
|
### Inputs
|
|
72
74
|
|
package/docs/api/popup.md
CHANGED
|
@@ -123,7 +123,7 @@ Class.
|
|
|
123
123
|
| `isDefaultPrevented(): boolean` | Whether `preventDefault()` was called. |
|
|
124
124
|
| `preventDefault(): void` | Cancels what the event announces, such as opening or closing a popup, or closing a dialog. |
|
|
125
125
|
|
|
126
|
-
**Used by:** [`AutoCompleteComponent`](auto-complete.md#autocompletecomponent), [`ComboBoxComponent`](combo-box.md#comboboxcomponent), [`DatePickerComponent`](date-picker.md#datepickercomponent), [`DateRangePickerComponent`](date-range-picker.md#daterangepickercomponent), [`DateTimePickerComponent`](datetime-picker.md#datetimepickercomponent), [`DialogComponent`](dialog.md#dialogcomponent), [`DialogRef`](dialog.md#dialogref), [`DropdownListComponent`](dropdown-list.md#dropdownlistcomponent), [`MultiSelectComponent`](multi-select.md#multiselectcomponent), [`PopupComponent`](popup.md#popupcomponent), [`PopupRef`](popup.md#popupref), [`PopupSettings`](popup.md#popupsettings), [`SheetComponent`](sheet.md#sheetcomponent), [`TimePickerComponent`](time-picker.md#timepickercomponent), [`WindowComponent`](window.md#windowcomponent), [`WindowRef`](window.md#windowref), [`WindowSettings`](window.md#windowsettings)
|
|
126
|
+
**Used by:** [`AutoCompleteComponent`](auto-complete.md#autocompletecomponent), [`ComboBoxComponent`](combo-box.md#comboboxcomponent), [`DatePickerComponent`](date-picker.md#datepickercomponent), [`DateRangePickerComponent`](date-range-picker.md#daterangepickercomponent), [`DateTimePickerComponent`](datetime-picker.md#datetimepickercomponent), [`DialogComponent`](dialog.md#dialogcomponent), [`DialogRef`](dialog.md#dialogref), [`DropdownListComponent`](dropdown-list.md#dropdownlistcomponent), [`DropdownTreeComponent`](dropdown-tree.md#dropdowntreecomponent), [`MultiSelectComponent`](multi-select.md#multiselectcomponent), [`MultiSelectTreeComponent`](multi-select-tree.md#multiselecttreecomponent), [`PopupComponent`](popup.md#popupcomponent), [`PopupRef`](popup.md#popupref), [`PopupSettings`](popup.md#popupsettings), [`SheetComponent`](sheet.md#sheetcomponent), [`TimePickerComponent`](time-picker.md#timepickercomponent), [`WindowComponent`](window.md#windowcomponent), [`WindowRef`](window.md#windowref), [`WindowSettings`](window.md#windowsettings)
|
|
127
127
|
|
|
128
128
|
## `defaultPopupAnimation`
|
|
129
129
|
|
package/docs/api/tree-view.md
CHANGED
|
@@ -578,7 +578,7 @@ Type alias.
|
|
|
578
578
|
type ChildrenSelector<T> = string | Selector<T, Iterable<T> | Observable<Iterable<T>>>;
|
|
579
579
|
```
|
|
580
580
|
|
|
581
|
-
**Used by:** [`TreeViewComponent`](tree-view.md#treeviewcomponent)
|
|
581
|
+
**Used by:** [`DropdownTreeComponent`](dropdown-tree.md#dropdowntreecomponent), [`MultiSelectTreeComponent`](multi-select-tree.md#multiselecttreecomponent), [`TreeViewComponent`](tree-view.md#treeviewcomponent)
|
|
582
582
|
|
|
583
583
|
## `DataStructure`
|
|
584
584
|
|
|
@@ -588,7 +588,7 @@ Type alias.
|
|
|
588
588
|
type DataStructure = "flat" | "hierarchical";
|
|
589
589
|
```
|
|
590
590
|
|
|
591
|
-
**Used by:** [`TreeViewComponent`](tree-view.md#treeviewcomponent)
|
|
591
|
+
**Used by:** [`DropdownTreeComponent`](dropdown-tree.md#dropdowntreecomponent), [`MultiSelectTreeComponent`](multi-select-tree.md#multiselecttreecomponent), [`TreeViewComponent`](tree-view.md#treeviewcomponent)
|
|
592
592
|
|
|
593
593
|
## `DropPosition`
|
|
594
594
|
|
package/docs/auto-complete.md
CHANGED
|
@@ -426,6 +426,8 @@ From `@nanahoshi/mona-ui/dropdowns`:
|
|
|
426
426
|
| [`DropdownDataInputToken`](api/dropdowns.md#dropdowndatainputtoken) | Constant | **Deprecated.** Use `DROPDOWN_DATA_INPUT_TOKEN`. |
|
|
427
427
|
| [`DROPDOWNS_DEFAULT_MESSAGES`](api/dropdowns.md#dropdowns-default-messages) | Constant | |
|
|
428
428
|
| [`DropdownDataInput`](api/dropdowns.md#dropdowndatainput) | Interface | |
|
|
429
|
+
| [`DropdownSheetData`](api/dropdowns.md#dropdownsheetdata) | Interface | What a dropdown passes to the bottom sheet its popup opens as. |
|
|
430
|
+
| [`AdaptiveMode`](api/dropdowns.md#adaptivemode) | Type alias | How a dropdown's popup adapts to a small screen: `"auto"` opens it as a sheet along the bottom of the screen when the screen is narrower than 640 pixels, and `"none"` always opens it under the field. |
|
|
429
431
|
| [`DropdownFieldPredicateType`](api/dropdowns.md#dropdownfieldpredicatetype) | Type alias | |
|
|
430
432
|
| [`DropdownFieldSelectorType`](api/dropdowns.md#dropdownfieldselectortype) | Type alias | |
|
|
431
433
|
|
package/docs/combo-box.md
CHANGED
|
@@ -455,6 +455,8 @@ From `@nanahoshi/mona-ui/dropdowns`:
|
|
|
455
455
|
| [`DropdownDataInputToken`](api/dropdowns.md#dropdowndatainputtoken) | Constant | **Deprecated.** Use `DROPDOWN_DATA_INPUT_TOKEN`. |
|
|
456
456
|
| [`DROPDOWNS_DEFAULT_MESSAGES`](api/dropdowns.md#dropdowns-default-messages) | Constant | |
|
|
457
457
|
| [`DropdownDataInput`](api/dropdowns.md#dropdowndatainput) | Interface | |
|
|
458
|
+
| [`DropdownSheetData`](api/dropdowns.md#dropdownsheetdata) | Interface | What a dropdown passes to the bottom sheet its popup opens as. |
|
|
459
|
+
| [`AdaptiveMode`](api/dropdowns.md#adaptivemode) | Type alias | How a dropdown's popup adapts to a small screen: `"auto"` opens it as a sheet along the bottom of the screen when the screen is narrower than 640 pixels, and `"none"` always opens it under the field. |
|
|
458
460
|
| [`DropdownFieldPredicateType`](api/dropdowns.md#dropdownfieldpredicatetype) | Type alias | |
|
|
459
461
|
| [`DropdownFieldSelectorType`](api/dropdowns.md#dropdownfieldselectortype) | Type alias | |
|
|
460
462
|
|
package/docs/dropdown-list.md
CHANGED
|
@@ -323,6 +323,52 @@ export class DropdownListFormsExampleComponent {
|
|
|
323
323
|
</div>
|
|
324
324
|
```
|
|
325
325
|
|
|
326
|
+
### A bottom sheet on a phone
|
|
327
|
+
|
|
328
|
+
With `adaptiveMode="auto"`, on a screen narrower than 640 pixels, the popup opens as a sheet along the bottom of the screen, where it's easy to reach with a thumb. Narrow the window to see it.
|
|
329
|
+
|
|
330
|
+
`adaptive-example.component.ts`
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
import { Component, signal } from "@angular/core";
|
|
334
|
+
import { DropdownListComponent } from "@nanahoshi/mona-ui/dropdown-list";
|
|
335
|
+
import { DropdownFilterableDirective } from "@nanahoshi/mona-ui/dropdowns";
|
|
336
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
337
|
+
|
|
338
|
+
@Component({
|
|
339
|
+
selector: "app-dropdown-list-adaptive-example",
|
|
340
|
+
imports: [DropdownFilterableDirective, DropdownListComponent, FormFieldComponent],
|
|
341
|
+
templateUrl: "./adaptive-example.component.html"
|
|
342
|
+
})
|
|
343
|
+
export class DropdownListAdaptiveExampleComponent {
|
|
344
|
+
protected readonly timeZone = signal<string | null>("Europe/Istanbul");
|
|
345
|
+
protected readonly timeZones = [
|
|
346
|
+
"America/New_York",
|
|
347
|
+
"America/Sao_Paulo",
|
|
348
|
+
"Asia/Seoul",
|
|
349
|
+
"Asia/Tokyo",
|
|
350
|
+
"Australia/Sydney",
|
|
351
|
+
"Europe/Berlin",
|
|
352
|
+
"Europe/Istanbul",
|
|
353
|
+
"Europe/London",
|
|
354
|
+
"Europe/Warsaw"
|
|
355
|
+
];
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
`adaptive-example.component.html`
|
|
360
|
+
|
|
361
|
+
```html
|
|
362
|
+
<mona-form-field class="max-w-sm" label="Time zone" hint="On a phone, the list opens along the bottom of the screen.">
|
|
363
|
+
<mona-dropdown-list
|
|
364
|
+
adaptiveMode="auto"
|
|
365
|
+
class="w-full"
|
|
366
|
+
monaDropDownFilterable
|
|
367
|
+
[data]="timeZones"
|
|
368
|
+
[(value)]="timeZone" />
|
|
369
|
+
</mona-form-field>
|
|
370
|
+
```
|
|
371
|
+
|
|
326
372
|
### Disabled, readonly, loading, and required states
|
|
327
373
|
|
|
328
374
|
`disabled` renders the control with reduced visual emphasis and removes pointer interaction. `readonly` prevents value changes while preserving the visual state. `loading` shows a loading indicator in place of the clear button and marks the field busy. It doesn't block interaction: the field stays usable while data loads. `required` marks the field for form validation and affects the invalid state once the control is touched.
|
|
@@ -366,6 +412,10 @@ While the popup is open, arrow-key and typeahead navigation only stage a highlig
|
|
|
366
412
|
|
|
367
413
|
`open` and `close` emit event objects with `preventDefault()` and `isDefaultPrevented()`. Calling `preventDefault()` in an `open` handler stops the popup from opening; calling it in a `close` handler stops the popup from closing. `close`'s event object also exposes `via`, describing what triggered the close attempt (for example `"escape"` or `"outsideClick"`).
|
|
368
414
|
|
|
415
|
+
### The bottom sheet
|
|
416
|
+
|
|
417
|
+
With `adaptiveMode="auto"`, the popup opens as a bottom sheet when the screen is narrower than 640 pixels as it opens; it doesn't switch while open. The sheet covers the page with a dimmed backdrop, which closes it when pressed, and has a header with the field's name (or `adaptiveTitle`) and a close button. Its options are 44 pixels tall, to be easy to tap. Focus stays where it is, as with the popup under the field: on the field, or in the filter box. While an on-screen keyboard is open, the sheet sits above it. Without `adaptiveMode`, or with `"none"`, the popup always opens under the field.
|
|
418
|
+
|
|
369
419
|
### Click-to-toggle
|
|
370
420
|
|
|
371
421
|
Clicking anywhere on the host element, outside the clear button, toggles the popup — in addition to the keyboard interactions documented under [Keyboard](#keyboard).
|
|
@@ -470,6 +520,8 @@ From `@nanahoshi/mona-ui/dropdowns`:
|
|
|
470
520
|
| [`DropdownDataInputToken`](api/dropdowns.md#dropdowndatainputtoken) | Constant | **Deprecated.** Use `DROPDOWN_DATA_INPUT_TOKEN`. |
|
|
471
521
|
| [`DROPDOWNS_DEFAULT_MESSAGES`](api/dropdowns.md#dropdowns-default-messages) | Constant | |
|
|
472
522
|
| [`DropdownDataInput`](api/dropdowns.md#dropdowndatainput) | Interface | |
|
|
523
|
+
| [`DropdownSheetData`](api/dropdowns.md#dropdownsheetdata) | Interface | What a dropdown passes to the bottom sheet its popup opens as. |
|
|
524
|
+
| [`AdaptiveMode`](api/dropdowns.md#adaptivemode) | Type alias | How a dropdown's popup adapts to a small screen: `"auto"` opens it as a sheet along the bottom of the screen when the screen is narrower than 640 pixels, and `"none"` always opens it under the field. |
|
|
473
525
|
| [`DropdownFieldPredicateType`](api/dropdowns.md#dropdownfieldpredicatetype) | Type alias | |
|
|
474
526
|
| [`DropdownFieldSelectorType`](api/dropdowns.md#dropdownfieldselectortype) | Type alias | |
|
|
475
527
|
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
# Dropdown Tree
|
|
2
|
+
|
|
3
|
+
> A closed control that opens a tree for choosing one item from a hierarchy.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/dropdown-tree`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-dropdown-tree`
|
|
8
|
+
|
|
9
|
+
`DropdownTreeComponent` is a combobox that shows one selected item and opens a tree, for choosing an item from a hierarchy such as categories, folders or an organization. The popup opens on the selected item, with its parents opened to show it.
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Dropdown Tree renders a single-value combobox whose popup is a tree. The field shows the selected item's text (or a placeholder), and the popup opens on click, `Enter`, `Space`, `ArrowDown` or `Alt+ArrowDown`. Choosing an item, by click or with `Enter`, selects it and closes the popup, whichever level it's on.
|
|
14
|
+
|
|
15
|
+
The data is a tree in one of two shapes, as in the [tree view](tree-view.md):
|
|
16
|
+
|
|
17
|
+
- **Hierarchical** (the default): each item holds its children, named by `children`. `children` can also be a function that returns an observable, which loads a node's children the first time it opens.
|
|
18
|
+
- **Flat**: one list, with `mode="flat"`, where `idField` and `parentIdField` link each item to its parent.
|
|
19
|
+
|
|
20
|
+
**Use Dropdown Tree when:**
|
|
21
|
+
|
|
22
|
+
- The options form a hierarchy, and a parent can be chosen as well as a leaf.
|
|
23
|
+
- The hierarchy is too deep or too long for grouped options in a [dropdown list](dropdown-list.md).
|
|
24
|
+
|
|
25
|
+
**Use `MultiSelectTree` instead when:**
|
|
26
|
+
|
|
27
|
+
- More than one item can be chosen at once.
|
|
28
|
+
|
|
29
|
+
**Use `TreeView` instead when:**
|
|
30
|
+
|
|
31
|
+
- The tree is part of the page, not a field in a form.
|
|
32
|
+
|
|
33
|
+
## Import & Quick Start
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { DropdownTreeComponent } from "@nanahoshi/mona-ui/dropdown-tree";
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
protected readonly categories = [
|
|
41
|
+
{
|
|
42
|
+
id: "clothing",
|
|
43
|
+
name: "Clothing",
|
|
44
|
+
items: [
|
|
45
|
+
{ id: "shirts", name: "Shirts" },
|
|
46
|
+
{ id: "trousers", name: "Trousers" }
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{ id: "footwear", name: "Footwear", items: [{ id: "boots", name: "Boots" }] }
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
protected readonly category = signal<string | null>(null);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<mona-form-field label="Category">
|
|
57
|
+
<mona-dropdown-tree
|
|
58
|
+
children="items"
|
|
59
|
+
textField="name"
|
|
60
|
+
valueField="id"
|
|
61
|
+
[data]="categories"
|
|
62
|
+
[valuePrimitive]="true"
|
|
63
|
+
[(value)]="category" />
|
|
64
|
+
</mona-form-field>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`textField`, `valueField` and `children` each take a property name or an accessor function. `valueField` identifies each item: it matches a value set from code to its node, and with `valuePrimitive` it's what the value holds instead of the whole item.
|
|
68
|
+
|
|
69
|
+
## Anatomy
|
|
70
|
+
|
|
71
|
+
Each template below is an `ng-template` placed inside `<mona-dropdown-tree>`.
|
|
72
|
+
|
|
73
|
+
| Directive | Selector | Template context | Replaces |
|
|
74
|
+
|--------------------------------------|-----------------------------------------------|----------------------------------------------------|-------------------------------------------------|
|
|
75
|
+
| `DropdownItemTemplateDirective` | `ng-template[monaDropDownTreeItemTemplate]` | `{ $implicit: TData }` (the node's item) | Each node's text in the popup |
|
|
76
|
+
| `DropdownTreeValueTemplateDirective` | `ng-template[monaDropDownTreeValueTemplate]` | `{ $implicit: TData \| null }` (the selected item) | The selected item's text in the field |
|
|
77
|
+
| `DropdownHeaderTemplateDirective` | `ng-template[monaDropDownTreeHeaderTemplate]` | None | No default; renders above the tree |
|
|
78
|
+
| `DropdownFooterTemplateDirective` | `ng-template[monaDropDownTreeFooterTemplate]` | None | No default; renders below the tree |
|
|
79
|
+
| `DropdownNoDataTemplateDirective` | `ng-template[monaDropDownTreeNoDataTemplate]` | None | "No data", or "No matching items" when filtered |
|
|
80
|
+
| `DropdownPrefixTemplateDirective` | `ng-template[monaDropdownPrefixTemplate]` | None | No default; renders before the value |
|
|
81
|
+
|
|
82
|
+
The generic selectors of the other dropdowns, such as `monaDropDownItemTemplate`, work too. The item, header, footer and "no data" directives come from `@nanahoshi/mona-ui/dropdowns`, and the value template from `@nanahoshi/mona-ui/dropdown-tree`.
|
|
83
|
+
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
### Choosing a category
|
|
87
|
+
|
|
88
|
+
The value is the category's id. `monaDropDownFilterable` puts a filter box in the popup: matching items show with their parents, which open to show them, and the first match becomes the active node, so `Enter` picks it. The form field names the dropdown tree, and its hint describes it. With `adaptiveMode="auto"`, the popup opens as a bottom sheet on a phone.
|
|
89
|
+
|
|
90
|
+
`categories-example.component.ts`
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { Component, signal } from "@angular/core";
|
|
94
|
+
import { DropdownTreeComponent } from "@nanahoshi/mona-ui/dropdown-tree";
|
|
95
|
+
import { DropdownFilterableDirective } from "@nanahoshi/mona-ui/dropdowns";
|
|
96
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
97
|
+
|
|
98
|
+
interface Category {
|
|
99
|
+
readonly id: string;
|
|
100
|
+
readonly items?: readonly Category[];
|
|
101
|
+
readonly name: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@Component({
|
|
105
|
+
selector: "app-dropdown-tree-categories-example",
|
|
106
|
+
imports: [DropdownFilterableDirective, DropdownTreeComponent, FormFieldComponent],
|
|
107
|
+
templateUrl: "./categories-example.component.html"
|
|
108
|
+
})
|
|
109
|
+
export class DropdownTreeCategoriesExampleComponent {
|
|
110
|
+
protected readonly categories: readonly Category[] = [
|
|
111
|
+
{
|
|
112
|
+
id: "clothing",
|
|
113
|
+
name: "Clothing",
|
|
114
|
+
items: [
|
|
115
|
+
{
|
|
116
|
+
id: "tops",
|
|
117
|
+
name: "Tops",
|
|
118
|
+
items: [
|
|
119
|
+
{ id: "shirts", name: "Shirts" },
|
|
120
|
+
{ id: "t-shirts", name: "T-shirts" },
|
|
121
|
+
{ id: "sweaters", name: "Sweaters" }
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
{ id: "trousers", name: "Trousers" },
|
|
125
|
+
{ id: "jackets", name: "Jackets" }
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: "footwear",
|
|
130
|
+
name: "Footwear",
|
|
131
|
+
items: [
|
|
132
|
+
{ id: "boots", name: "Boots" },
|
|
133
|
+
{ id: "sandals", name: "Sandals" },
|
|
134
|
+
{ id: "sneakers", name: "Sneakers" }
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: "accessories",
|
|
139
|
+
name: "Accessories",
|
|
140
|
+
items: [
|
|
141
|
+
{ id: "bags", name: "Bags" },
|
|
142
|
+
{ id: "belts", name: "Belts" },
|
|
143
|
+
{ id: "hats", name: "Hats" }
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
];
|
|
147
|
+
protected readonly category = signal<string | null>("t-shirts");
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`categories-example.component.html`
|
|
152
|
+
|
|
153
|
+
```html
|
|
154
|
+
<div class="flex max-w-sm flex-col gap-2">
|
|
155
|
+
<mona-form-field label="Category" hint="Pick the most specific one.">
|
|
156
|
+
<mona-dropdown-tree
|
|
157
|
+
adaptiveMode="auto"
|
|
158
|
+
children="items"
|
|
159
|
+
class="w-full"
|
|
160
|
+
monaDropDownFilterable
|
|
161
|
+
placeholder="Choose a category"
|
|
162
|
+
textField="name"
|
|
163
|
+
valueField="id"
|
|
164
|
+
[data]="categories"
|
|
165
|
+
[showClearButton]="true"
|
|
166
|
+
[valuePrimitive]="true"
|
|
167
|
+
[(value)]="category" />
|
|
168
|
+
</mona-form-field>
|
|
169
|
+
<span class="text-sm">Category id: {{ category() ?? "none" }}</span>
|
|
170
|
+
</div>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Loading children as nodes open
|
|
174
|
+
|
|
175
|
+
`children` returns an observable of a folder's subfolders, which loads them the first time the folder opens, and `hasChildren` tells which folders have any before they load. A load that takes a moment is announced. The value is the whole folder item.
|
|
176
|
+
|
|
177
|
+
`lazy-loading-example.component.ts`
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { Component, signal } from "@angular/core";
|
|
181
|
+
import { DropdownTreeComponent } from "@nanahoshi/mona-ui/dropdown-tree";
|
|
182
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
183
|
+
import { delay, type Observable, of } from "rxjs";
|
|
184
|
+
|
|
185
|
+
interface Folder {
|
|
186
|
+
readonly hasFolders: boolean;
|
|
187
|
+
readonly name: string;
|
|
188
|
+
readonly path: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A stand-in for a file server: each folder's subfolders arrive after a short wait. */
|
|
192
|
+
const SUBFOLDERS: Readonly<Record<string, readonly string[]>> = {
|
|
193
|
+
"/": ["Documents", "Photos", "Projects"],
|
|
194
|
+
"/Documents": ["Invoices", "Letters"],
|
|
195
|
+
"/Photos": ["2025", "2026"],
|
|
196
|
+
"/Projects": ["Mona UI", "Website"],
|
|
197
|
+
"/Projects/Mona UI": ["Docs", "Source"]
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
function folder(parent: string, name: string): Folder {
|
|
201
|
+
const path = parent === "/" ? `/${name}` : `${parent}/${name}`;
|
|
202
|
+
return { hasFolders: path in SUBFOLDERS, name, path };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
@Component({
|
|
206
|
+
selector: "app-dropdown-tree-lazy-loading-example",
|
|
207
|
+
imports: [DropdownTreeComponent, FormFieldComponent],
|
|
208
|
+
templateUrl: "./lazy-loading-example.component.html"
|
|
209
|
+
})
|
|
210
|
+
export class DropdownTreeLazyLoadingExampleComponent {
|
|
211
|
+
protected readonly destination = signal<Folder | null>(null);
|
|
212
|
+
protected readonly roots: readonly Folder[] = SUBFOLDERS["/"].map(name => folder("/", name));
|
|
213
|
+
|
|
214
|
+
protected readonly hasFolders = (item: Folder): boolean => item.hasFolders;
|
|
215
|
+
protected readonly loadFolders = (item: Folder): Observable<Folder[]> =>
|
|
216
|
+
of((SUBFOLDERS[item.path] ?? []).map(name => folder(item.path, name))).pipe(delay(600));
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`lazy-loading-example.component.html`
|
|
221
|
+
|
|
222
|
+
```html
|
|
223
|
+
<div class="flex max-w-sm flex-col gap-2">
|
|
224
|
+
<mona-form-field label="Save to">
|
|
225
|
+
<mona-dropdown-tree
|
|
226
|
+
class="w-full"
|
|
227
|
+
placeholder="Choose a folder"
|
|
228
|
+
textField="name"
|
|
229
|
+
valueField="path"
|
|
230
|
+
[children]="loadFolders"
|
|
231
|
+
[data]="roots"
|
|
232
|
+
[hasChildren]="hasFolders"
|
|
233
|
+
[(value)]="destination" />
|
|
234
|
+
</mona-form-field>
|
|
235
|
+
<span class="text-sm">Path: {{ destination()?.path ?? "none" }}</span>
|
|
236
|
+
</div>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Flat data, disabled items and templates
|
|
240
|
+
|
|
241
|
+
With `mode="flat"`, the teams are one list linked by `parentId`. `itemDisabled` names a field that disables an item: an archived team can't be chosen, and neither can its children. The item template adds a note to archived teams, and the value template shows the selected team in the field.
|
|
242
|
+
|
|
243
|
+
`flat-data-example.component.ts`
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { Component, signal } from "@angular/core";
|
|
247
|
+
import { DropdownTreeComponent, DropdownTreeValueTemplateDirective } from "@nanahoshi/mona-ui/dropdown-tree";
|
|
248
|
+
import { DropdownItemTemplateDirective } from "@nanahoshi/mona-ui/dropdowns";
|
|
249
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
250
|
+
|
|
251
|
+
interface Team {
|
|
252
|
+
readonly archived: boolean;
|
|
253
|
+
readonly id: number;
|
|
254
|
+
readonly name: string;
|
|
255
|
+
readonly parentId: number | null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@Component({
|
|
259
|
+
selector: "app-dropdown-tree-flat-data-example",
|
|
260
|
+
imports: [
|
|
261
|
+
DropdownItemTemplateDirective,
|
|
262
|
+
DropdownTreeComponent,
|
|
263
|
+
DropdownTreeValueTemplateDirective,
|
|
264
|
+
FormFieldComponent
|
|
265
|
+
],
|
|
266
|
+
templateUrl: "./flat-data-example.component.html"
|
|
267
|
+
})
|
|
268
|
+
export class DropdownTreeFlatDataExampleComponent {
|
|
269
|
+
protected readonly team = signal<number | null>(null);
|
|
270
|
+
protected readonly teams: readonly Team[] = [
|
|
271
|
+
{ archived: false, id: 1, name: "Engineering", parentId: null },
|
|
272
|
+
{ archived: false, id: 2, name: "Platform", parentId: 1 },
|
|
273
|
+
{ archived: false, id: 3, name: "Mobile", parentId: 1 },
|
|
274
|
+
{ archived: true, id: 4, name: "Desktop", parentId: 1 },
|
|
275
|
+
{ archived: false, id: 5, name: "Design", parentId: null },
|
|
276
|
+
{ archived: false, id: 6, name: "Research", parentId: 5 },
|
|
277
|
+
{ archived: false, id: 7, name: "Brand", parentId: 5 },
|
|
278
|
+
{ archived: false, id: 8, name: "Support", parentId: null }
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
`flat-data-example.component.html`
|
|
284
|
+
|
|
285
|
+
```html
|
|
286
|
+
<mona-form-field class="max-w-sm" label="Team" hint="Archived teams can't take new members.">
|
|
287
|
+
<mona-dropdown-tree
|
|
288
|
+
class="w-full"
|
|
289
|
+
idField="id"
|
|
290
|
+
itemDisabled="archived"
|
|
291
|
+
mode="flat"
|
|
292
|
+
parentIdField="parentId"
|
|
293
|
+
placeholder="Choose a team"
|
|
294
|
+
textField="name"
|
|
295
|
+
valueField="id"
|
|
296
|
+
[data]="teams"
|
|
297
|
+
[valuePrimitive]="true"
|
|
298
|
+
[(value)]="team">
|
|
299
|
+
<ng-template monaDropDownTreeItemTemplate let-team>
|
|
300
|
+
<span class="flex flex-wrap items-baseline gap-x-2">
|
|
301
|
+
{{ team.name }}
|
|
302
|
+
@if (team.archived) {
|
|
303
|
+
<span class="text-xs text-muted-foreground">(archived)</span>
|
|
304
|
+
}
|
|
305
|
+
</span>
|
|
306
|
+
</ng-template>
|
|
307
|
+
<ng-template monaDropDownTreeValueTemplate let-team>
|
|
308
|
+
<span class="truncate">{{ team ? team.name + " team" : "Choose a team" }}</span>
|
|
309
|
+
</ng-template>
|
|
310
|
+
</mona-dropdown-tree>
|
|
311
|
+
</mona-form-field>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## Appearance & Styling
|
|
315
|
+
|
|
316
|
+
The dropdown tree has the sizes, corner roundings and states of the [dropdown list](dropdown-list.md): `size` is `small`, `medium` (default) or `large`, and `rounded` is `none`, `small`, `medium` (default), `large` or `full`.
|
|
317
|
+
|
|
318
|
+
| Input | What it does |
|
|
319
|
+
|-------------------|----------------------------------------------------------------------------------------------|
|
|
320
|
+
| `popupHeight` | The popup's maximum height; 200 pixels when unset. Shorter trees shrink to fit. |
|
|
321
|
+
| `popupWidth` | The popup's width; the field's width when unset. |
|
|
322
|
+
| `popupClass` | Classes added to the popup. |
|
|
323
|
+
| `showClearButton` | A button in the field that clears the value. |
|
|
324
|
+
| `adaptiveMode` | `"auto"` opens the popup as a bottom sheet on a small screen. See [On a phone](#on-a-phone). |
|
|
325
|
+
|
|
326
|
+
## Behavior
|
|
327
|
+
|
|
328
|
+
### Opening on the selected item
|
|
329
|
+
|
|
330
|
+
The popup opens with the selected item as its active node, and the item's parents open to show it. With nothing selected, the first node is active. As the filter changes, its first match becomes the active node. Closing the popup clears the filter.
|
|
331
|
+
|
|
332
|
+
### Clicking or pressing Enter selects and closes
|
|
333
|
+
|
|
334
|
+
A click on a node, or `Enter` or `Space` on the active node, selects it and closes the popup, even when it's already selected. The arrow on a node opens and closes it without selecting it. `Escape`, `Tab` and a click outside close the popup and leave the value as it was.
|
|
335
|
+
|
|
336
|
+
### Values set from code
|
|
337
|
+
|
|
338
|
+
A value set from code selects the node it matches through `valueField`. When the node isn't loaded yet (its parent hasn't opened), the field still shows the value's text for an object value; a primitive value shows only once its node loads, so give lazily loaded trees object values.
|
|
339
|
+
|
|
340
|
+
### On a phone
|
|
341
|
+
|
|
342
|
+
With `adaptiveMode="auto"`, on a screen narrower than 640 pixels, the popup opens as a sheet along the bottom of the screen, over a dimmed page. The sheet has the field's name, or `adaptiveTitle`, and a close button. Its nodes are 44 pixels tall, to be easy to tap. Focus stays where it is, as with the popup under the field: on the field, or in the filter box. While an on-screen keyboard is open, the sheet sits above it.
|
|
343
|
+
|
|
344
|
+
### `open` and `close` are cancelable
|
|
345
|
+
|
|
346
|
+
`open` and `close` emit a `PreventableEvent`; calling `preventDefault()` keeps the popup as it is. `opened` and `closed` follow once it has opened or closed.
|
|
347
|
+
|
|
348
|
+
## Forms Integration
|
|
349
|
+
|
|
350
|
+
The dropdown tree implements `FormValueControl<TValue | null>`, so `[formField]` binds it to a signal form field, which then sets `disabled`, `readonly`, `required`, `invalid` and `touched`. It's touched when focus leaves it and its popup. It also works with `[(ngModel)]` and reactive forms.
|
|
351
|
+
|
|
352
|
+
## Accessibility
|
|
353
|
+
|
|
354
|
+
### Keyboard
|
|
355
|
+
|
|
356
|
+
| Key | When | Action |
|
|
357
|
+
|-----------------------------------------------------------|--------|---------------------------------------------------------------------------------|
|
|
358
|
+
| `Enter`, `Space`, `ArrowDown`, `ArrowUp`, `Alt+ArrowDown` | Closed | Opens the popup |
|
|
359
|
+
| `ArrowDown` / `ArrowUp` | Open | Moves to the next or previous visible node |
|
|
360
|
+
| `ArrowRight` | Open | Opens a closed node, or moves to its first child (`ArrowLeft` in right-to-left) |
|
|
361
|
+
| `ArrowLeft` | Open | Closes an open node, or moves to its parent (`ArrowRight` in right-to-left) |
|
|
362
|
+
| `Home` / `End` | Open | Moves to the first or last visible node |
|
|
363
|
+
| `*` | Open | Opens the active node's siblings |
|
|
364
|
+
| Letters and digits | Open | Moves to the next node whose text starts with them |
|
|
365
|
+
| `Enter` / `Space` | Open | Selects the active node and closes the popup |
|
|
366
|
+
| `Escape`, `Alt+ArrowUp` | Open | Closes the popup without changing the value |
|
|
367
|
+
| `Tab` | Open | Closes the popup and moves focus on |
|
|
368
|
+
|
|
369
|
+
In the filter box, `ArrowDown`, `ArrowUp` and `Enter` work as above, and the other keys edit the text.
|
|
370
|
+
|
|
371
|
+
### Focus
|
|
372
|
+
|
|
373
|
+
Focus stays on the field while the popup is open, as for the other dropdowns; the active node is shown with a focus ring and announced through `aria-activedescendant`. With a filter box, focus moves into it when the popup opens, and returns to the field when the popup closes.
|
|
374
|
+
|
|
375
|
+
### ARIA
|
|
376
|
+
|
|
377
|
+
- The field has `role="combobox"`, `aria-haspopup="tree"`, `aria-expanded`, and `aria-controls` pointing at the tree. It's named by `aria-label`, `aria-labelledby`, a form field's label or, failing those, the placeholder.
|
|
378
|
+
- The popup's tree has `role="tree"` and the field's name. Its nodes are `treeitem`s with `aria-level`, `aria-setsize`, `aria-posinset`, `aria-expanded` on nodes with children, and `aria-selected` on the selected node. A disabled node has `aria-disabled`, and a node whose children are loading has `aria-busy`.
|
|
379
|
+
- The filter box is a combobox too, named "Filter" and the field's name. How many items match is announced as the filter changes.
|
|
380
|
+
- `loading` sets `aria-busy` on the field.
|
|
381
|
+
|
|
382
|
+
## API
|
|
383
|
+
|
|
384
|
+
Everything below is imported from `@nanahoshi/mona-ui/dropdown-tree`, unless a table names another entry point. Each name links to its reference page, with every input, output, property and method.
|
|
385
|
+
|
|
386
|
+
| Name | Kind | Description |
|
|
387
|
+
| --- | --- | --- |
|
|
388
|
+
| [`DropdownTreeComponent`](api/dropdown-tree.md#dropdowntreecomponent) | Component | |
|
|
389
|
+
| [`DropdownTreeValueTemplateDirective`](api/dropdown-tree.md#dropdowntreevaluetemplatedirective) | Directive | Renders the selected item in the field. |
|
|
390
|
+
|
|
391
|
+
From `@nanahoshi/mona-ui/dropdowns`:
|
|
392
|
+
|
|
393
|
+
| Name | Kind |
|
|
394
|
+
| --- | --- |
|
|
395
|
+
| [`DropdownFilterableDirective`](api/dropdowns.md#dropdownfilterabledirective) | Directive |
|
|
396
|
+
| [`DropdownGroupableDirective`](api/dropdowns.md#dropdowngroupabledirective) | Directive |
|
|
397
|
+
| [`DropdownVirtualScrollDirective`](api/dropdowns.md#dropdownvirtualscrolldirective) | Directive |
|
|
398
|
+
| [`DropdownDataHandlerDirective`](api/dropdowns.md#dropdowndatahandlerdirective) | Directive |
|
|
399
|
+
| [`DropdownFooterTemplateDirective`](api/dropdowns.md#dropdownfootertemplatedirective) | Directive |
|
|
400
|
+
| [`DropdownGroupHeaderTemplateDirective`](api/dropdowns.md#dropdowngroupheadertemplatedirective) | Directive |
|
|
401
|
+
| [`DropdownHeaderTemplateDirective`](api/dropdowns.md#dropdownheadertemplatedirective) | Directive |
|
|
402
|
+
| [`DropdownItemTemplateDirective`](api/dropdowns.md#dropdownitemtemplatedirective) | Directive |
|
|
403
|
+
| [`DropdownListPopupHandlerDirective`](api/dropdowns.md#dropdownlistpopuphandlerdirective) | Directive |
|
|
404
|
+
| [`DropdownNoDataTemplateDirective`](api/dropdowns.md#dropdownnodatatemplatedirective) | Directive |
|
|
405
|
+
| [`DropdownPrefixTemplateDirective`](api/dropdowns.md#dropdownprefixtemplatedirective) | Directive |
|
|
406
|
+
| [`DropdownSuffixTemplateDirective`](api/dropdowns.md#dropdownsuffixtemplatedirective) | Directive |
|
|
407
|
+
| [`DropdownListService`](api/dropdowns.md#dropdownlistservice) | Service |
|
|
408
|
+
|
|
409
|
+
### Types
|
|
410
|
+
|
|
411
|
+
| Type | Kind |
|
|
412
|
+
| --- | --- |
|
|
413
|
+
| [`DROPDOWN_TREE_DEFAULT_MESSAGES`](api/dropdown-tree.md#dropdown-tree-default-messages) | Constant |
|
|
414
|
+
|
|
415
|
+
From `@nanahoshi/mona-ui/dropdowns`:
|
|
416
|
+
|
|
417
|
+
| Type | Kind | Description |
|
|
418
|
+
| --- | --- | --- |
|
|
419
|
+
| [`DropdownDataInputToken`](api/dropdowns.md#dropdowndatainputtoken) | Constant | **Deprecated.** Use `DROPDOWN_DATA_INPUT_TOKEN`. |
|
|
420
|
+
| [`DROPDOWNS_DEFAULT_MESSAGES`](api/dropdowns.md#dropdowns-default-messages) | Constant | |
|
|
421
|
+
| [`DropdownDataInput`](api/dropdowns.md#dropdowndatainput) | Interface | |
|
|
422
|
+
| [`DropdownSheetData`](api/dropdowns.md#dropdownsheetdata) | Interface | What a dropdown passes to the bottom sheet its popup opens as. |
|
|
423
|
+
| [`AdaptiveMode`](api/dropdowns.md#adaptivemode) | Type alias | How a dropdown's popup adapts to a small screen: `"auto"` opens it as a sheet along the bottom of the screen when the screen is narrower than 640 pixels, and `"none"` always opens it under the field. |
|
|
424
|
+
| [`DropdownFieldPredicateType`](api/dropdowns.md#dropdownfieldpredicatetype) | Type alias | |
|
|
425
|
+
| [`DropdownFieldSelectorType`](api/dropdowns.md#dropdownfieldselectortype) | Type alias | |
|
|
426
|
+
|
|
427
|
+
**Related types:** [`ChildrenSelector`](api/tree-view.md#childrenselector), [`DataStructure`](api/tree-view.md#datastructure), [`FilterableOptions`](api/common.md#filterableoptions), [`FilterChangeEvent`](api/common.md#filterchangeevent), [`GroupableOptions`](api/grid.md#groupableoptions), [`ListItem`](api/list.md#listitem), [`ListSizeInputType`](api/list.md#listsizeinputtype), [`ListSizeType`](api/list.md#listsizetype), [`MonaDropdownsMessages`](api/i18n.md#monadropdownsmessages), [`MonaDropdownTreeMessages`](api/i18n.md#monadropdowntreemessages), [`PopupCloseEvent`](api/popup.md#popupcloseevent), [`PreventableEvent`](api/common.md#preventableevent), [`VirtualScrollOptions`](api/common.md#virtualscrolloptions)
|