@xleddyl/443-components-vue 0.16.19 → 0.16.21

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/CATALOG.md CHANGED
@@ -46,6 +46,7 @@ Playground paths in this file are relative to `playground/nuxt/app/pages/compone
46
46
  | One choice from a short list (5 or fewer) | `RadioGroup` or `SegmentedControl` |
47
47
  | One choice from a longer list, no search | `Select` |
48
48
  | Searchable select, async search, multi select, create option | `Combobox` |
49
+ | Pick one node of a hierarchy (category, folder) | `TreeSelect` (`leavesOnly` to allow only leaves) |
49
50
  | Create new values with a format or rule (tags, codes) | `Combobox` with `creatable`, `createTransform`, `createValidate` |
50
51
  | Several choices as checkboxes | `CheckboxGroup` |
51
52
  | One yes or no | `Switch` (instant setting) or `Checkbox` (part of a form) |
@@ -167,6 +168,7 @@ All field components work inside `FormField` and take `invalid`, `disabled`, `re
167
168
  | `SegmentedControl` | Compact toggle between 2 to 5 options (view mode, period). | Model: value (with `required` it is never null). Props: `options` (`label`, `value`, `icon`, `title`, `muted`), `iconOnly`, `block`, `label`. Slot: `option`. | `forms/segmented-control.vue` |
168
169
  | `Select` | Native styled select. Use `Combobox` when search or async options are needed. | Model: `T or null`. Props: `options` (items or groups with `label`, `value`, `disabled`), `placeholder`, `icon`. Option values can be string, number or boolean. | `forms/select.vue` |
169
170
  | `Combobox` | Searchable select. Local filter, async `search`, `multiple` with tags, `creatable`. | Models: `v-model`, `v-model:query`. Props: `options` (`label`, `value`, `description`, `icon`, `color` (dot and tag color), `group` (divider with the group name, also the tooltip of a selected tag), `keywords`), `search(query, signal)`, `filter`, `multiple`, `hideTags`, `creatable`, `createTransform`, `createValidate` (a returned string is the inline error), `debounce`, `minQueryLength`, `maxSelected`, `clearable`, `loading`, `placeholder`, `emptyText`. Slots: `option`, `empty`, `header` (top of the panel, for example quick filter pills). Events: `create`, `open`, `close`. | `forms/combobox.vue` |
171
+ | `TreeSelect` | Pick one node of a hierarchy (category, folder) with a drill-down panel, one level at a time. | Model: `TreeNodeId or null`. Props: `nodes` (`TreeNode`: `id`, `label`, `description`, `icon`, `disabled`, `children`), `leavesOnly` (parents only navigate), `separator` (path in the control and in search results, default `' / '`), `clearable`, `placeholder`, `searchPlaceholder`, `emptyText`, `icon`. Search lists every match with its path. Slots: `node` (`node`, `selected`, `path`), `empty`. Events: `open`, `close`. | `forms/tree-select.vue` |
170
172
  | `Switch` | On or off setting that applies at once. | Model: boolean. Props: `label`, `description`, `labelPosition`, `checkedIcon`, `uncheckedIcon`, `name`. Slots: default, `description`. | `forms/switch.vue` |
171
173
  | `NumberInput` | Locale aware number with stepper, min, max, step. | Model: number or null. Props: `min`, `max`, `step`, `largeStep`, `locale`, `formatOptions` (currency, percent), `stepper`, `wheel`, `align`, `icon`, `placeholder`. | `forms/number-input.vue` |
172
174
  | `PasswordInput` | Password with show or hide, optional generator, copy and strength meter. | Model: string. Props: `generate` (true or a function), `copy`, `strength`, `minLength`, `autocomplete`. Event: `generate`. | `forms/password-input.vue` |
@@ -185,21 +187,21 @@ All field components work inside `FormField` and take `invalid`, `disabled`, `re
185
187
 
186
188
  Mount `OverlayHost` once for the imperative hooks (see [Composables](#composables)).
187
189
 
188
- | Component | Purpose and when to use it | Main props, models, slots, events | Playground |
189
- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------ |
190
- | `Modal` | Centered dialog for forms and content. Use `Drawer` for a side panel, `useConfirm` for a yes or no question. | Models: `v-model:open`, `v-model:tab`. Props: `title`, `description`, `size` (sm to xl, full, fit, fullscreen), `width`, `minHeight`, `dismissible`, `hideClose`, `sheet`, `flush`, `loading`, `beforeClose(reason)`, `tabs` (tabs in the header), `trail` (breadcrumb title and back button), `backLabel`. Slots: default (`{ tab }`), `header`, `actions` (header, before the close button), `footer`, `title-trailing`. Events: `open`, `close`, `afterLeave`, `navigate(index)`. | `overlays/modal.vue` |
191
- | `Drawer` | Panel from the side or bottom for details and edit forms. Use `Modal` for short focused dialogs. | Models: `v-model:open`, `v-model:tab`. Props: `title`, `description`, `side` (left, right, bottom), `size` (sm to xl, full), `dismissible`, `hideClose`, `flush`, `loading`, `beforeClose(reason)`, `tabs`, `trail`, `backLabel`. Slots like `Modal`. Events: `open`, `close`, `afterLeave`, `navigate(index)`. | `overlays/drawer.vue` |
192
- | `ConfirmDialog` | Declarative confirm dialog. Prefer `useConfirm()`. Use this one only when the dialog state lives in the template. | Model: `v-model:open`. Props: `title`, `description`, `confirmLabel`, `cancelLabel`, `tone`, `icon`, `hideCancel`, `onConfirm`. Events: `resolve(confirmed)`, `cancel`, `afterLeave`. | `overlays/confirm-dialog.vue` |
193
- | `ConfirmHost` | Renders the dialogs of `useConfirm`, `useAlert`, `usePrompt`. `OverlayHost` includes it. Do not mount it alone. | None. | - |
194
- | `OverlayHost` | One mount point for toasts, confirm dialogs, programmatic modals and loading indicators. | Props: `toaster` (true or options), `confirm`, `modals`, `loading` (true or `{ bar, delay, label }`). | `overlays/hooks.vue` |
195
- | `Toaster` | Renders toasts. `OverlayHost` includes it. Use it directly only for custom options. The stack moves out of the way of an open side Drawer (beside it, or above its footer). | Props: `position`, `max`, `duration`, `gap`, `expand`, `progress`, `hotkey`. | `overlays/toast.vue` |
196
- | `DropdownMenu` | Menu opened by its trigger. Items can have icons, shortcuts, checkboxes, radios, sub menus and links. | Model: `v-model:open`. Props: `items` (`label`, `icon`, `to`, `href`, `tone: danger`, `shortcut`, `disabled`, `children`, `onSelect`; also `type`: checkbox, radio, label, separator), `placement`, `offset`, `matchTriggerWidth`, `minWidth`. Slot: default (the trigger). Event: `select`. | `overlays/dropdown-menu.vue` |
197
- | `ContextMenu` | Menu on right click of the wrapped area. | Model: `v-model:open`. Props: `items` (same as `DropdownMenu`), `disabled`. Slot: default (the area). Event: `select`. | `overlays/context-menu.vue` |
198
- | `Popover` | Floating panel with any content (a form, filters) opened by its trigger. Use `DropdownMenu` for a list of actions. | Model: `v-model:open`. Props: `placement`, `offset`, `arrow`, `label`, `initialFocus`. Slots: default (the trigger), `content`. | `overlays/popover.vue` |
199
- | `HoverCard` | Rich preview on hover or focus (user card, link preview). Use `Tooltip` for plain text. | Model: `v-model:open`. Props: `placement`, `openDelay`, `closeDelay`, `arrow`, `disabled`. Slots: default (trigger), `content`. | `overlays/hover-card.vue` |
200
- | `Tooltip` | Short text on hover or focus. Optional shortcut. | Props: `text`, `placement`, `openDelay`, `closeDelay`, `arrow`, `shortcut`, `disabled`. Slots: default (trigger), `content`. | `overlays/tooltip.vue` |
201
- | `CommandPalette` | Search and command dialog (Cmd+K) with groups, recent items, async search and typed item data. Groups take `icon` (default item icon) and `more` (a last "show all" item). Matching (`matchesSearch`, exported) finds every word in any order, without case or accents. | Models: `v-model:open`, `v-model:query`. Props: `groups` (items with `id`, `label`, `description`, `icon`, `shortcut`, `keywords`, `to`, `data`, `onSelect`), `search(query, signal)`, `shortcut`, `trigger`, `recentKey`, `emptyText`, `notice`. Slots: `item`, `empty`, `group-label`, `after-results`. Events: `select`, `open`, `close`. | `overlays/command-palette.vue` |
202
- | `CommandButton` | A `Button` made from a `CommandItem`: label, icon, `to`, `href`, `disabled` and `onSelect` come from the command. | Props: `command`, `label`, `icon`, and every `Button` prop (size, variant, tone). | `overlays/command-palette.vue` |
190
+ | Component | Purpose and when to use it | Main props, models, slots, events | Playground |
191
+ | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
192
+ | `Modal` | Centered dialog for forms and content. Use `Drawer` for a side panel, `useConfirm` for a yes or no question. | Models: `v-model:open`, `v-model:tab`. Props: `title`, `description`, `size` (sm to xl, full, fit, fullscreen), `width`, `minHeight`, `dismissible`, `hideClose`, `sheet`, `flush`, `fill`, `loading`, `beforeClose(reason)`, `tabs` (tabs in the header), `trail` (breadcrumb title and back button), `backLabel`. Slots: default (`{ tab }`), `header`, `actions` (header, before the close button), `footer`, `title-trailing`. Events: `open`, `close`, `afterLeave`, `navigate(index)`. | `overlays/modal.vue` |
193
+ | `Drawer` | Panel from the side or bottom for details and edit forms. Use `Modal` for short focused dialogs. | Models: `v-model:open`, `v-model:tab`. Props: `title`, `description`, `side` (left, right, bottom), `size` (sm to xl, full), `dismissible`, `hideClose`, `flush`, `fill` (the body content takes the full height, for a table or a grid), `loading`, `beforeClose(reason)`, `tabs`, `trail`, `backLabel`. Slots like `Modal`. Events: `open`, `close`, `afterLeave`, `navigate(index)`. | `overlays/drawer.vue` |
194
+ | `ConfirmDialog` | Declarative confirm dialog. Prefer `useConfirm()`. Use this one only when the dialog state lives in the template. | Model: `v-model:open`. Props: `title`, `description`, `confirmLabel`, `cancelLabel`, `tone`, `icon`, `hideCancel`, `onConfirm`. Events: `resolve(confirmed)`, `cancel`, `afterLeave`. | `overlays/confirm-dialog.vue` |
195
+ | `ConfirmHost` | Renders the dialogs of `useConfirm`, `useAlert`, `usePrompt`. `OverlayHost` includes it. Do not mount it alone. | None. | - |
196
+ | `OverlayHost` | One mount point for toasts, confirm dialogs, programmatic modals and loading indicators. | Props: `toaster` (true or options), `confirm`, `modals`, `loading` (true or `{ bar, delay, label }`). | `overlays/hooks.vue` |
197
+ | `Toaster` | Renders toasts. `OverlayHost` includes it. Use it directly only for custom options. The stack moves out of the way of an open side Drawer (beside it, or above its footer). | Props: `position`, `max`, `duration`, `gap`, `expand`, `progress`, `hotkey`. | `overlays/toast.vue` |
198
+ | `DropdownMenu` | Menu opened by its trigger. Items can have icons, shortcuts, checkboxes, radios, sub menus and links. | Model: `v-model:open`. Props: `items` (`label`, `icon`, `to`, `href`, `tone: danger`, `shortcut`, `disabled`, `children`, `onSelect`; also `type`: checkbox, radio, label, separator), `placement`, `offset`, `matchTriggerWidth`, `minWidth`. Slot: default (the trigger). Event: `select`. | `overlays/dropdown-menu.vue` |
199
+ | `ContextMenu` | Menu on right click of the wrapped area. | Model: `v-model:open`. Props: `items` (same as `DropdownMenu`), `disabled`. Slot: default (the area). Event: `select`. | `overlays/context-menu.vue` |
200
+ | `Popover` | Floating panel with any content (a form, filters) opened by its trigger. Use `DropdownMenu` for a list of actions. | Model: `v-model:open`. Props: `placement`, `offset`, `arrow`, `label`, `initialFocus`. Slots: default (the trigger), `content`. | `overlays/popover.vue` |
201
+ | `HoverCard` | Rich preview on hover or focus (user card, link preview). Use `Tooltip` for plain text. | Model: `v-model:open`. Props: `placement`, `openDelay`, `closeDelay`, `arrow`, `disabled`. Slots: default (trigger), `content`. | `overlays/hover-card.vue` |
202
+ | `Tooltip` | Short text on hover or focus. Optional shortcut. | Props: `text`, `placement`, `openDelay`, `closeDelay`, `arrow`, `shortcut`, `disabled`. Slots: default (trigger), `content`. | `overlays/tooltip.vue` |
203
+ | `CommandPalette` | Search and command dialog (Cmd+K) with groups, recent items, async search and typed item data. Groups take `icon` (default item icon) and `more` (a last "show all" item). Matching (`matchesSearch`, exported) finds every word in any order, without case or accents. | Models: `v-model:open`, `v-model:query`. Props: `groups` (items with `id`, `label`, `description`, `icon`, `shortcut`, `keywords`, `to`, `data`, `onSelect`), `search(query, signal)`, `shortcut`, `trigger`, `recentKey`, `emptyText`, `notice`. Slots: `item`, `empty`, `group-label`, `after-results`. Events: `select`, `open`, `close`. | `overlays/command-palette.vue` |
204
+ | `CommandButton` | A `Button` made from a `CommandItem`: label, icon, `to`, `href`, `disabled` and `onSelect` come from the command. | Props: `command`, `label`, `icon`, and every `Button` prop (size, variant, tone). | `overlays/command-palette.vue` |
203
205
 
204
206
  ## Data
205
207
 
@@ -267,7 +269,7 @@ Templates combine core parts into whole pages and layouts. Start from them for n
267
269
  | `AuthLayout` | Login, sign up and reset password frame. Centered card or split with aside. | Props: `variant` (centered, split), `title`, `description`, `footer`, `brandName`, `brandIcon`, `brandLogo`, `asideTitle`, `asideDescription`, `themeSwitch`. Slots: default, `links`, `footer`, `brand`, `aside`, `corner`. | `templates/auth-layout.vue` |
268
270
  | `ListPage` | Whole list page: header, search, filters, table, pagination, bulk actions, loading, empty, no results and error states. Client or server mode (`total`). | Models: `page`, `pageSize`, `search`, `filter`, `sort`, `selected`. Props: `title`, `rows`, `columns`, `rowKey`, `rowTo`, `selectable`, `loading`, `error`, `total`, `paginate`, `searchable`, `searchKeys`, `filters`, `filterKey`, `filterMultiple`, `emptyTitle`. Slots: `actions`, `toolbar`, `toolbar-end`, `bulk`, `empty`, `empty-actions`, `no-results`, `error`, `cell-<key>`, `table`. Events: `retry`, `clear`, `rowClick`. | `templates/list-page.vue` |
269
271
  | `DetailPage` | Record page: back link, title, status, actions, tabs, main column and aside with description lists. | Model: `v-model:tab`. Props: `title`, `backTo`, `backLabel`, `status` (`label`, `tone`, `dot`), `tabs`, `sections` (`title`, `items`), `loading`, `error`. Slots: default, `actions`, `badge`, `meta`, `aside`, `aside-before`, `panel-<value>`. | `templates/detail-page.vue` |
270
- | `FormDrawer` | Drawer with a form: `Form` around the body, footer with delete (left), cancel and submit, a discard confirmation on close when the form is dirty, `SkeletonForm` while `loading`. | Models: `v-model:open`, `v-model:tab`. Props: `title`, `description`, `side`, `size`, `tabs` (`FormDrawerTab`: `fields` gives the error dot and opens the tab on a failed submit), `tabRoute` (keeps the tab in the hash under this key), `trail`, `backLabel`, `form`, `loading`, `readonly`, `creating` (submit says Create, no dirty needed), `requireDirty`, `deletable`, `deleteDisabled`, `deleteHint`, `submitLabel`, `cancelLabel`, `deleteLabel`, `guard`, `guardTitle`, `guardMessage`, `beforeClose`, `onCancel`. Slots: default (`{ tab }`), `actions`, `title-trailing`, `skeleton`, `footer`. Events: `delete`, `navigate`, `afterLeave`. Exposes `confirmDiscard()`, `close()`. | `templates/form-drawer.vue` |
272
+ | `FormDrawer` | Drawer with a form: `Form` around the body, footer with delete (left), cancel and submit, a discard confirmation on close when the form is dirty, `SkeletonForm` while `loading`. | Models: `v-model:open`, `v-model:tab`. Props: `title`, `description`, `side`, `size`, `fill` (per tab, for a full height table), `tabs` (`FormDrawerTab`: `fields` gives the error dot and opens the tab on a failed submit), `tabRoute` (keeps the tab in the hash under this key), `trail`, `backLabel`, `form`, `loading`, `readonly`, `creating` (submit says Create, no dirty needed), `requireDirty`, `deletable`, `deleteDisabled`, `deleteHint`, `submitLabel`, `cancelLabel`, `deleteLabel`, `guard`, `guardTitle`, `guardMessage`, `beforeClose`, `onCancel`. Slots: default (`{ tab }`), `actions`, `title-trailing`, `skeleton`, `footer`. Events: `delete`, `navigate`, `afterLeave`. Exposes `confirmDiscard()`, `close()`. | `templates/form-drawer.vue` |
271
273
  | `FormPage` | Form page: header, cards in a `Form`, sticky submit and cancel footer, dirty guard. | Props: `title`, `backTo`, `form` (from `useForm`), `dirty`, `saving`, `guard`, `requireDirty`, `submitLabel`, `cancelLabel`, `cancelTo`, `width`, `sticky`. Slots: default, `actions`, `footer`, `status`. Events: `submit`, `submitted`, `invalid`, `reset`, `cancel`. | `templates/form-page.vue` |
272
274
  | `DashboardPage` | Overview page: header, stat grid, content grid. | Props: `title`, `eyebrow`, `description`, `stats` (`PageStat[]`), `statsColumns`, `columns`, `loading`. Slots: default, `actions`, `stats`, `sparkline`, `before`, `after`, `eyebrow`. | `templates/dashboard-page.vue` |
273
275
  | `SettingsPage` | Settings as a page: section nav, panels, floating save bar when `dirty`. | Model: `v-model:section`. Props: `title`, `sections` (`value`, `label`, `icon`, `to`), `dirty`, `saving`, `saveBar`, `form`. Slots: `section-<value>`, `actions`, `nav-footer`. Events: `save`, `discard`. | `templates/settings-page.vue` |
@@ -0,0 +1,515 @@
1
+ <template>
2
+ <div
3
+ ref="rootRef"
4
+ class="k-tree-select"
5
+ :class="[
6
+ `k-tree-select-${size}`,
7
+ {
8
+ 'is-open': layer.isOpen.value,
9
+ 'is-empty': !selectedEntry,
10
+ 'is-disabled': control.disabled.value,
11
+ 'has-lead': Boolean(icon)
12
+ },
13
+ props.class
14
+ ]"
15
+ :style="props.style"
16
+ >
17
+ <button
18
+ ref="triggerRef"
19
+ :id="control.id.value"
20
+ :aria-labelledby="
21
+ control.labelledBy.value && !$attrs['aria-label'] ? `${control.labelledBy.value} ${valueId}` : void 0
22
+ "
23
+ v-bind="$attrs"
24
+ :disabled="control.disabled.value || void 0"
25
+ :aria-invalid="control.invalid.value ? 'true' : void 0"
26
+ :aria-describedby="
27
+ joinIds(
28
+ $attrs['aria-describedby'],
29
+ control.describedBy.value,
30
+ readonly ? readonlyId : void 0
31
+ )
32
+ "
33
+ type="button"
34
+ class="k-field k-tree-select-trigger"
35
+ :class="[
36
+ `k-field-${size}`,
37
+ {
38
+ 'is-invalid': control.invalid.value,
39
+ 'is-disabled': control.disabled.value,
40
+ 'is-readonly': readonly
41
+ }
42
+ ]"
43
+ aria-haspopup="listbox"
44
+ :aria-expanded="layer.isOpen.value ? 'true' : 'false'"
45
+ :aria-controls="panelId"
46
+ @mousedown="onTriggerMousedown"
47
+ @click="toggleList"
48
+ @keydown="onTriggerKeydown"
49
+ >
50
+ <span v-if="icon" class="k-tree-select-lead" aria-hidden="true"
51
+ ><Icon :name="icon"
52
+ /></span>
53
+ <span :id="valueId" class="k-tree-select-value">
54
+ <template v-if="selectedEntry">
55
+ <span v-if="selectedEntry.path.length" class="k-tree-select-value-path">{{
56
+ pathText(selectedEntry.path) + separator
57
+ }}</span>
58
+ <span class="k-tree-select-value-label">{{ selectedEntry.node.label }}</span>
59
+ </template>
60
+ <span v-else class="k-tree-select-placeholder">{{ placeholderText }}</span>
61
+ </span>
62
+ </button>
63
+ <span v-if="readonly" :id="readonlyId" hidden>{{ t("common.readonly") }}</span>
64
+ <span class="k-tree-select-trail">
65
+ <button
66
+ v-if="showClear"
67
+ type="button"
68
+ class="k-tree-select-icon-button"
69
+ :aria-label="clearText"
70
+ :title="clearText"
71
+ tabindex="-1"
72
+ @mousedown.prevent
73
+ @click.stop="clear"
74
+ >
75
+ <Icon name="x-mark" />
76
+ </button>
77
+ <button
78
+ type="button"
79
+ class="k-tree-select-icon-button k-tree-select-chevron"
80
+ :aria-label="toggleText"
81
+ tabindex="-1"
82
+ :disabled="!interactive || void 0"
83
+ @mousedown.prevent
84
+ @click.stop="toggleList"
85
+ >
86
+ <Icon name="chevron-down" />
87
+ </button>
88
+ </span>
89
+ <div
90
+ :id="panelId"
91
+ ref="panelRef"
92
+ popover="manual"
93
+ class="k-floating k-form-popover k-tree-select-panel"
94
+ :data-side="layer.side.value"
95
+ @mousedown.prevent
96
+ >
97
+ <div class="k-tree-select-header">
98
+ <div class="k-tree-select-search">
99
+ <Icon name="magnifying-glass" class="k-tree-select-search-icon" />
100
+ <input
101
+ ref="searchRef"
102
+ class="k-tree-select-search-input"
103
+ type="text"
104
+ role="combobox"
105
+ autocomplete="off"
106
+ autocapitalize="off"
107
+ spellcheck="false"
108
+ aria-autocomplete="list"
109
+ aria-expanded="true"
110
+ :aria-controls="listId"
111
+ :aria-activedescendant="activeId"
112
+ :aria-label="searchText"
113
+ :placeholder="searchText"
114
+ :value="query"
115
+ @input="onInput"
116
+ @keydown="onSearchKeydown"
117
+ @blur="onBlur"
118
+ />
119
+ </div>
120
+ <button
121
+ v-if="!searching && levelEntry"
122
+ type="button"
123
+ class="k-tree-select-back"
124
+ :aria-label="backText"
125
+ tabindex="-1"
126
+ @click="back"
127
+ >
128
+ <Icon name="chevron-left" class="k-tree-select-back-icon" />
129
+ <span class="k-tree-select-back-text">
130
+ <span v-if="levelEntry.path.length" class="k-tree-select-back-path">{{
131
+ pathText(levelEntry.path) + separator
132
+ }}</span>
133
+ <span class="k-tree-select-back-label">{{ levelEntry.node.label }}</span>
134
+ </span>
135
+ </button>
136
+ </div>
137
+ <ul
138
+ :id="listId"
139
+ role="listbox"
140
+ class="k-tree-select-list"
141
+ :aria-labelledby="listLabelledBy"
142
+ :aria-label="listLabelledBy ? void 0 : listText"
143
+ >
144
+ <li
145
+ v-for="(item, index) in items"
146
+ :id="optionId(index)"
147
+ :key="keyOf(item.node.id)"
148
+ role="option"
149
+ class="k-combobox-option k-tree-select-option"
150
+ :class="{
151
+ 'is-active': index === activeIndex,
152
+ 'is-selected': item.selected,
153
+ 'is-ancestor': item.ancestor,
154
+ 'is-parent': item.parent
155
+ }"
156
+ :aria-selected="item.selected ? 'true' : 'false'"
157
+ :aria-disabled="item.node.disabled ? 'true' : void 0"
158
+ @mousemove="activate(index)"
159
+ @click="choose(item)"
160
+ >
161
+ <Icon v-if="item.node.icon" :name="item.node.icon" class="k-combobox-option-icon" />
162
+ <span class="k-combobox-option-text">
163
+ <slot name="node" :node="item.node" :selected="item.selected" :path="item.path">
164
+ <span class="k-combobox-option-label">{{ item.node.label }}</span>
165
+ <span
166
+ v-if="searching ? item.path.length : item.node.description"
167
+ class="k-combobox-option-description"
168
+ >{{ searching ? pathText(item.path) : item.node.description }}</span
169
+ >
170
+ </slot>
171
+ </span>
172
+ <Icon v-if="item.selected" name="check" class="k-combobox-option-selected" />
173
+ <span
174
+ v-if="item.parent && !searching"
175
+ class="k-tree-select-drill"
176
+ :class="{ 'is-button': !leavesOnly }"
177
+ aria-hidden="true"
178
+ @click.stop="drill(item)"
179
+ >
180
+ <Icon name="chevron-right" />
181
+ </span>
182
+ </li>
183
+ </ul>
184
+ <div v-if="!items.length" class="k-combobox-state">
185
+ <slot name="empty" :query="query">{{ emptyLabel }}</slot>
186
+ </div>
187
+ </div>
188
+ <LiveRegion :message="live.message.value" />
189
+ <input
190
+ v-if="formName"
191
+ type="hidden"
192
+ :name="formName"
193
+ :value="selectedEntry ? keyOf(selectedEntry.node.id) : ''"
194
+ />
195
+ </div>
196
+ </template>
197
+
198
+ <script setup>
199
+ import { computed, nextTick, ref, useAttrs, useId, useTemplateRef, watch } from "vue";
200
+ import { useFieldControl } from "../../composables/useField";
201
+ import { useLocale } from "../../composables/useLocale";
202
+ import { useFloatingLayer } from "../../internal/floating/layer";
203
+ import { nextEnabledIndex } from "../../internal/core/roving";
204
+ import LiveRegion from "../../internal/core/LiveRegion.vue";
205
+ import { useLiveMessage } from "../../internal/core/live";
206
+ import { normalizeSearch } from "../../internal/core/text";
207
+ import { joinIds } from "../../internal/forms/control";
208
+ import Icon from "../core/Icon.vue";
209
+ defineOptions({ inheritAttrs: false });
210
+ const props = defineProps({
211
+ nodes: { type: Array, required: false, default: () => [] },
212
+ name: { type: String, required: false },
213
+ leavesOnly: { type: Boolean, required: false },
214
+ clearable: { type: Boolean, required: false },
215
+ placeholder: { type: String, required: false },
216
+ searchPlaceholder: { type: String, required: false },
217
+ emptyText: { type: String, required: false },
218
+ size: { type: String, required: false, default: "md" },
219
+ icon: { type: null, required: false },
220
+ separator: { type: String, required: false, default: " / " },
221
+ clearLabel: { type: String, required: false },
222
+ toggleLabel: { type: String, required: false },
223
+ backLabel: { type: String, required: false },
224
+ listLabel: { type: String, required: false },
225
+ resultsText: { type: Function, required: false },
226
+ invalid: { type: Boolean, required: false, default: void 0 },
227
+ disabled: { type: Boolean, required: false },
228
+ readonly: { type: Boolean, required: false },
229
+ required: { type: Boolean, required: false },
230
+ class: { type: null, required: false },
231
+ style: { type: null, required: false }
232
+ });
233
+ const model = defineModel({ type: [String, Number, null] });
234
+ const emit = defineEmits(["open", "close"]);
235
+ const { t } = useLocale();
236
+ const placeholderText = computed(() => props.placeholder ?? t("treeSelect.placeholder"));
237
+ const searchText = computed(() => props.searchPlaceholder ?? t("common.search"));
238
+ const emptyLabel = computed(() => props.emptyText ?? t("common.noResults"));
239
+ const clearText = computed(() => props.clearLabel ?? t("treeSelect.clear"));
240
+ const toggleText = computed(() => props.toggleLabel ?? t("treeSelect.toggle"));
241
+ const backText = computed(() => props.backLabel ?? t("common.back"));
242
+ const listText = computed(() => props.listLabel ?? t("treeSelect.list"));
243
+ const attrs = useAttrs();
244
+ const baseId = useId();
245
+ const listId = `${baseId}-listbox`;
246
+ const panelId = `${baseId}-panel`;
247
+ const valueId = `${baseId}-value`;
248
+ const readonlyId = `${baseId}-readonly`;
249
+ const rootRef = useTemplateRef("rootRef");
250
+ const triggerRef = useTemplateRef("triggerRef");
251
+ const panelRef = useTemplateRef("panelRef");
252
+ const searchRef = useTemplateRef("searchRef");
253
+ const query = ref("");
254
+ const level = ref(null);
255
+ const activeIndex = ref(-1);
256
+ const control = useFieldControl({
257
+ invalid: () => props.invalid,
258
+ disabled: () => props.disabled,
259
+ required: () => props.required,
260
+ requiredHint: true
261
+ });
262
+ const layer = useFloatingLayer({
263
+ floating: panelRef,
264
+ anchor: () => triggerRef.value,
265
+ placement: () => "bottom-start",
266
+ offset: () => 6,
267
+ mode: "manual",
268
+ matchWidth: true,
269
+ returnFocus: () => false,
270
+ onOpen: () => emit("open"),
271
+ onClose: () => emit("close")
272
+ });
273
+ const interactive = computed(() => !control.disabled.value && !props.readonly);
274
+ const formName = computed(() => props.name ?? control.field?.name.value);
275
+ const listLabelledBy = computed(
276
+ () => attrs["aria-labelledby"] ?? control.field?.labelId
277
+ );
278
+ const index = computed(() => {
279
+ const map = /* @__PURE__ */ new Map();
280
+ const visit = (nodes, parent, path) => {
281
+ for (const node of nodes) {
282
+ map.set(keyOf(node.id), { node, parent, path });
283
+ if (node.children?.length) visit(node.children, node.id, [...path, node]);
284
+ }
285
+ };
286
+ visit(props.nodes, null, []);
287
+ return map;
288
+ });
289
+ const selectedEntry = computed(
290
+ () => model.value === null || model.value === void 0 ? void 0 : index.value.get(keyOf(model.value))
291
+ );
292
+ const selectedKey = computed(() => selectedEntry.value ? keyOf(selectedEntry.value.node.id) : "");
293
+ const ancestorKeys = computed(
294
+ () => new Set(selectedEntry.value?.path.map((node) => keyOf(node.id)) ?? [])
295
+ );
296
+ const levelEntry = computed(
297
+ () => level.value === null ? void 0 : index.value.get(keyOf(level.value))
298
+ );
299
+ const showClear = computed(
300
+ () => props.clearable && interactive.value && Boolean(selectedEntry.value)
301
+ );
302
+ const needle = computed(() => normalizeSearch(query.value.trim()));
303
+ const searching = computed(() => Boolean(needle.value));
304
+ function toItem(node, path) {
305
+ const key = keyOf(node.id);
306
+ return {
307
+ node,
308
+ path,
309
+ parent: hasChildren(node),
310
+ selected: key === selectedKey.value,
311
+ ancestor: ancestorKeys.value.has(key)
312
+ };
313
+ }
314
+ const items = computed(() => {
315
+ if (searching.value) {
316
+ const found = [];
317
+ for (const entry2 of index.value.values()) {
318
+ if (props.leavesOnly && hasChildren(entry2.node)) continue;
319
+ if (normalizeSearch(entry2.node.label).includes(needle.value))
320
+ found.push(toItem(entry2.node, entry2.path));
321
+ }
322
+ return found;
323
+ }
324
+ const entry = levelEntry.value;
325
+ const nodes = entry ? entry.node.children ?? [] : props.nodes;
326
+ const path = entry ? [...entry.path, entry.node] : [];
327
+ return nodes.map((node) => toItem(node, path));
328
+ });
329
+ const activeId = computed(
330
+ () => layer.isOpen.value && activeIndex.value >= 0 && activeIndex.value < items.value.length ? optionId(activeIndex.value) : void 0
331
+ );
332
+ const statusText = computed(() => {
333
+ if (!layer.isOpen.value) return "";
334
+ if (!items.value.length) return emptyLabel.value;
335
+ const count = items.value.length;
336
+ return props.resultsText ? props.resultsText(count) : t("treeSelect.results", { count });
337
+ });
338
+ const live = useLiveMessage();
339
+ watch([statusText, query, level], ([text]) => {
340
+ if (text) live.announce(text);
341
+ else live.clear();
342
+ });
343
+ function keyOf(value) {
344
+ return String(value);
345
+ }
346
+ function hasChildren(node) {
347
+ return Boolean(node.children?.length);
348
+ }
349
+ function pathText(path) {
350
+ return path.map((node) => node.label).join(props.separator);
351
+ }
352
+ function optionId(position) {
353
+ return `${baseId}-option-${position}`;
354
+ }
355
+ function firstEnabled(from = 0, direction = 1) {
356
+ return nextEnabledIndex(
357
+ items.value.length,
358
+ from,
359
+ direction,
360
+ (position) => Boolean(items.value[position]?.node.disabled)
361
+ );
362
+ }
363
+ function activate(position) {
364
+ if (items.value[position]?.node.disabled) return;
365
+ activeIndex.value = position;
366
+ }
367
+ function activateKey(key) {
368
+ const position = items.value.findIndex((item) => keyOf(item.node.id) === key);
369
+ activeIndex.value = position >= 0 && !items.value[position]?.node.disabled ? position : firstEnabled();
370
+ }
371
+ function move(delta) {
372
+ const total = items.value.length;
373
+ if (!total) return;
374
+ const start = activeIndex.value < 0 ? delta > 0 ? 0 : total - 1 : activeIndex.value + delta;
375
+ activeIndex.value = firstEnabled((start + total) % total, delta > 0 ? 1 : -1);
376
+ }
377
+ function openList(text = "") {
378
+ if (!interactive.value || layer.isOpen.value) return;
379
+ query.value = text;
380
+ level.value = selectedEntry.value?.parent ?? null;
381
+ layer.show();
382
+ if (text) activeIndex.value = firstEnabled();
383
+ else activateKey(selectedKey.value);
384
+ nextTick(() => searchRef.value?.focus());
385
+ }
386
+ function closeList(returnFocus = false) {
387
+ if (layer.isOpen.value) layer.hide();
388
+ activeIndex.value = -1;
389
+ query.value = "";
390
+ if (returnFocus) triggerRef.value?.focus();
391
+ }
392
+ function toggleList() {
393
+ if (!interactive.value) return;
394
+ if (layer.isOpen.value) closeList(true);
395
+ else openList();
396
+ }
397
+ function onTriggerMousedown(event) {
398
+ if (interactive.value) event.preventDefault();
399
+ }
400
+ function onTriggerKeydown(event) {
401
+ if (!interactive.value || layer.isOpen.value) return;
402
+ if (["Enter", " ", "ArrowDown", "ArrowUp"].includes(event.key)) {
403
+ event.preventDefault();
404
+ openList();
405
+ return;
406
+ }
407
+ if (event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
408
+ event.preventDefault();
409
+ openList(event.key);
410
+ }
411
+ }
412
+ function onInput(event) {
413
+ query.value = event.target.value;
414
+ if (searching.value) activeIndex.value = firstEnabled();
415
+ else activateKey(selectedKey.value);
416
+ }
417
+ function onBlur(event) {
418
+ const next = event.relatedTarget;
419
+ if (next && rootRef.value?.contains(next)) return;
420
+ closeList();
421
+ }
422
+ function drill(item) {
423
+ if (item.node.disabled || !item.parent) return;
424
+ query.value = "";
425
+ level.value = item.node.id;
426
+ activeIndex.value = firstEnabled();
427
+ searchRef.value?.focus();
428
+ }
429
+ function back() {
430
+ const entry = levelEntry.value;
431
+ if (!entry) return;
432
+ level.value = entry.parent;
433
+ activateKey(keyOf(entry.node.id));
434
+ searchRef.value?.focus();
435
+ }
436
+ function choose(item) {
437
+ if (item.node.disabled) return;
438
+ if (!searching.value && props.leavesOnly && item.parent) {
439
+ drill(item);
440
+ return;
441
+ }
442
+ model.value = item.node.id;
443
+ closeList(true);
444
+ }
445
+ function clear() {
446
+ model.value = null;
447
+ closeList();
448
+ triggerRef.value?.focus();
449
+ }
450
+ function onSearchKeydown(event) {
451
+ const active = items.value[activeIndex.value];
452
+ switch (event.key) {
453
+ case "ArrowDown":
454
+ event.preventDefault();
455
+ move(1);
456
+ break;
457
+ case "ArrowUp":
458
+ event.preventDefault();
459
+ move(-1);
460
+ break;
461
+ case "Home":
462
+ if (query.value || !items.value.length) return;
463
+ event.preventDefault();
464
+ activeIndex.value = firstEnabled();
465
+ break;
466
+ case "End":
467
+ if (query.value || !items.value.length) return;
468
+ event.preventDefault();
469
+ activeIndex.value = firstEnabled(items.value.length - 1, -1);
470
+ break;
471
+ case "Enter":
472
+ if (!active) return;
473
+ event.preventDefault();
474
+ choose(active);
475
+ break;
476
+ case "ArrowRight":
477
+ if (query.value || !active?.parent) return;
478
+ event.preventDefault();
479
+ drill(active);
480
+ break;
481
+ case "ArrowLeft":
482
+ case "Backspace":
483
+ if (query.value || !levelEntry.value) return;
484
+ event.preventDefault();
485
+ back();
486
+ break;
487
+ case "Escape":
488
+ event.preventDefault();
489
+ event.stopPropagation();
490
+ closeList(true);
491
+ break;
492
+ case "Tab":
493
+ closeList(true);
494
+ break;
495
+ }
496
+ }
497
+ watch(activeIndex, (position) => {
498
+ if (position < 0) return;
499
+ nextTick(() => {
500
+ panelRef.value?.querySelector(`#${CSS.escape(optionId(position))}`)?.scrollIntoView({ block: "nearest" });
501
+ });
502
+ });
503
+ watch(
504
+ () => items.value.length,
505
+ () => {
506
+ if (layer.isOpen.value) nextTick(layer.reposition);
507
+ }
508
+ );
509
+ defineExpose({
510
+ focus: () => triggerRef.value?.focus(),
511
+ open: () => openList(),
512
+ close: () => closeList(),
513
+ el: triggerRef
514
+ });
515
+ </script>