@xleddyl/443-components-vue 0.16.72 → 0.16.73

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
  | Money or unit prefix and suffix around an input | `InputGroup` + `InputAddon` |
47
47
  | One choice from a short list (5 or fewer) | `RadioGroup` or `SegmentedControl` |
48
48
  | One choice from a longer list, no search | `Select` |
49
+ | One choice from a short fixed list with a color dot or an icon, no search | `Combobox` with `:searchable="false"` (a button trigger with typeahead, also `multiple`) |
49
50
  | Searchable select, async search, multi select, create option | `Combobox` |
50
51
  | Pick one node of a hierarchy (category, folder) | `TreeSelect` (`leavesOnly` to allow only leaves) |
51
52
  | Create new values with a format or rule (tags, codes) | `Combobox` with `creatable`, `createTransform`, `createValidate` |
@@ -162,31 +163,31 @@ Playground paths in this file are relative to `playground/nuxt/app/pages/compone
162
163
 
163
164
  All field components work inside `FormField` and take `invalid`, `disabled`, `readonly`, `required` and `size`, except: `Select` has no `readonly`, `Slider` and `PaletteSelect` have no `required`, `Calendar` takes only `disabled` and `readonly`. They use `v-model`.
164
165
 
165
- | Component | Purpose and when to use it | Main props, models, slots, events | Playground |
166
- | ------------------ | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
167
- | `Checkbox` | One boolean, or one value in an array model. Use `Switch` for an instant setting. | Model: boolean or array. Props: `label`, `description`, `value`, `indeterminate`. Slots: default, `description`. | `forms/checkbox.vue` |
168
- | `CheckboxGroup` | Several choices as checkboxes from `options`. | Model: `T[]`. Props: `options` (`label`, `value`, `description`, `disabled`, `icon`), `legend`, `orientation`, `columns`, `variant` (default, filled), `name`. | `forms/checkbox-group.vue` |
169
- | `Radio` | One radio option, used inside `RadioGroup`. | Props: `value`, `label`, `description`, `icon`. Slots: default, `description`. | `forms/radio-group.vue` |
170
- | `RadioGroup` | One choice from a short list. Use `Select` for long lists, `SegmentedControl` for a compact toggle. | Model: value or null. Props: `options`, `legend`, `orientation`, `variant` (default, card), `name`. | `forms/radio-group.vue` |
171
- | `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` |
172
- | `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` |
173
- | `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`, `createActions`, `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` |
174
- | `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` |
175
- | `Switch` | On or off setting that applies at once. | Model: boolean. Props: `label`, `description`, `labelPosition`, `checkedIcon`, `uncheckedIcon`, `name`. Slots: default, `description`. | `forms/switch.vue` |
176
- | `NumberInput` | Locale aware number with stepper, min, max, step. | Model: number or null. Props: `min`, `max`, `step`, `largeStep`, `locale`, `formatOptions` (currency, percent), `decimalSeparator` (`'.'` or `','`, default from the locale), `stepper`, `wheel`, `align` (`start`, the default, or `end`), `icon`, `placeholder`. Numbers are left aligned like every other field. Typing keeps only digits, one decimal separator (a typed `.` or `,` becomes the separator) and a leading `-` when `min` allows negatives. | `forms/number-input.vue` |
177
- | `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` |
178
- | `PinInput` | One time code or PIN in separate cells. | Model: string. Props: `length`, `mode` (numeric, alphanumeric, alphabetic), `mask`, `uppercase`, `separatorAfter`, `autocomplete`. Event: `complete(value)`. | `forms/pin-input.vue` |
179
- | `InputGroup` | Join an input with addons or buttons on its sides. | Props: `label`, `size`, `block`. Slot: default (inputs, `InputAddon`, `Button`). | `forms/input-group.vue` |
180
- | `Fieldset` | Group of fields that can be disabled together, outside or inside a `Form` (a read only part of a page). | Props: `disabled` (every field inside is disabled, the same as `Form` `disabled`; without it the group inherits the state of its parent, `false` enables a group inside a disabled form), `legend`. Slots: default, `legend`. A native `fieldset`: buttons inside are disabled too, links are not. When it becomes disabled with the focus inside, the focus moves to the fieldset. | `forms/fieldset.vue` |
181
- | `InputAddon` | Static text or icon (currency, domain, unit) inside an `InputGroup`. | Props: `label`, `icon`, `size`. Slot: default. | `forms/input-group.vue` |
182
- | `DateInput` | Native date, datetime-local, month or week input. Use `DatePicker` for a calendar popover or ranges. | Model: ISO string or null. Props: `type`, `min`, `max`, `step`, `clearable`. | `forms/date-input.vue` |
183
- | `DatePicker` | Input with a calendar popover. Single date or `range`. | Model: ISO string, range object (`start`, `end`) or null. Props: `range`, `min`, `max`, `isDateDisabled`, `locale`, `weekStartsOn`, `format`, `closeOnSelect`, `clearable`. Slot: `footer`. | `forms/date-picker.vue` |
184
- | `Calendar` | Inline calendar. Use it for availability views, or as a building block. | Models: `v-model` (date or range), `v-model:month`. Props: `range`, `min`, `max`, `isDateDisabled`, `locale`, `weekStartsOn`, `dayText(iso)`. Slots: `day`, `footer`. Event: `select`. | `forms/calendar.vue` |
185
- | `TimeInput` | Time of day (HH:MM, optional seconds). | Model: string or null. Props: `min`, `max`, `step`, `seconds`, `clearable`. | `forms/time-input.vue` |
186
- | `ColorInput` | Color text field with picker and swatches. | Model: hex string or null. Props: `swatches` (strings or `{ value, label }`), `placeholder`, `invalidText`. | `forms/color-input.vue` |
187
- | `PaletteSelect` | Select of a palette color, with the dot and the localized color name. | Model: `ColorValue` (palette name or `#rrggbb`) or null. Props: `colors` (subset of `PALETTE_COLORS`), `clearable` (placeholder "Automatic"), `custom` (adds "Custom": choosing it shows a `ColorInput` under the select and the model becomes the hex), `customLabel` (name of the color input), `placeholder`, `size`, `disabled`, `readonly`, `invalid`. | `forms/palette-select.vue` |
188
- | `Slider` | Number in a range with drag handle. | Model: number. Props: `min`, `max`, `step`, `bubble` (true, always), `marks`, `format(value)`, `label`. Event: `change` (on release). | `forms/slider.vue` |
189
- | `FileInput` | Drop zone and file picker. Validates type, size and count. Supports folders and previews. | Model: `File`, `File[]` or null. Props: `accept`, `acceptMode`, `maxSize`, `maxFiles`, `multiple`, `directory`, `directoryAction`, `previews`, `list`, `loading`, `capture`, `title`, `dropText`, `hint`. Slots: `title`, `hint`, `actions`. Events: `add`, `remove`, `invalid`, `reject`. | `forms/file-input.vue` |
166
+ | Component | Purpose and when to use it | Main props, models, slots, events | Playground |
167
+ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- |
168
+ | `Checkbox` | One boolean, or one value in an array model. Use `Switch` for an instant setting. | Model: boolean or array. Props: `label`, `description`, `value`, `indeterminate`. Slots: default, `description`. | `forms/checkbox.vue` |
169
+ | `CheckboxGroup` | Several choices as checkboxes from `options`. | Model: `T[]`. Props: `options` (`label`, `value`, `description`, `disabled`, `icon`), `legend`, `orientation`, `columns`, `variant` (default, filled), `name`. | `forms/checkbox-group.vue` |
170
+ | `Radio` | One radio option, used inside `RadioGroup`. | Props: `value`, `label`, `description`, `icon`. Slots: default, `description`. | `forms/radio-group.vue` |
171
+ | `RadioGroup` | One choice from a short list. Use `Select` for long lists, `SegmentedControl` for a compact toggle. | Model: value or null. Props: `options`, `legend`, `orientation`, `variant` (default, card), `name`. | `forms/radio-group.vue` |
172
+ | `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` |
173
+ | `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` |
174
+ | `Combobox` | Searchable select. Local filter, async `search`, `multiple` with tags, `creatable`. `:searchable="false"` makes it a plain select with dots and icons. | 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`, `searchable` (default `true`; `false` is a button trigger without typing, with typeahead, and ignores `creatable`, `createActions` and `search`), `multiple`, `hideTags`, `creatable`, `createActions`, `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` |
175
+ | `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` |
176
+ | `Switch` | On or off setting that applies at once. | Model: boolean. Props: `label`, `description`, `labelPosition`, `checkedIcon`, `uncheckedIcon`, `name`. Slots: default, `description`. | `forms/switch.vue` |
177
+ | `NumberInput` | Locale aware number with stepper, min, max, step. | Model: number or null. Props: `min`, `max`, `step`, `largeStep`, `locale`, `formatOptions` (currency, percent), `decimalSeparator` (`'.'` or `','`, default from the locale), `stepper`, `wheel`, `align` (`start`, the default, or `end`), `icon`, `placeholder`. Numbers are left aligned like every other field. Typing keeps only digits, one decimal separator (a typed `.` or `,` becomes the separator) and a leading `-` when `min` allows negatives. | `forms/number-input.vue` |
178
+ | `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` |
179
+ | `PinInput` | One time code or PIN in separate cells. | Model: string. Props: `length`, `mode` (numeric, alphanumeric, alphabetic), `mask`, `uppercase`, `separatorAfter`, `autocomplete`. Event: `complete(value)`. | `forms/pin-input.vue` |
180
+ | `InputGroup` | Join an input with addons or buttons on its sides. | Props: `label`, `size`, `block`. Slot: default (inputs, `InputAddon`, `Button`). | `forms/input-group.vue` |
181
+ | `Fieldset` | Group of fields that can be disabled together, outside or inside a `Form` (a read only part of a page). | Props: `disabled` (every field inside is disabled, the same as `Form` `disabled`; without it the group inherits the state of its parent, `false` enables a group inside a disabled form), `legend`. Slots: default, `legend`. A native `fieldset`: buttons inside are disabled too, links are not. When it becomes disabled with the focus inside, the focus moves to the fieldset. | `forms/fieldset.vue` |
182
+ | `InputAddon` | Static text or icon (currency, domain, unit) inside an `InputGroup`. | Props: `label`, `icon`, `size`. Slot: default. | `forms/input-group.vue` |
183
+ | `DateInput` | Native date, datetime-local, month or week input. Use `DatePicker` for a calendar popover or ranges. | Model: ISO string or null. Props: `type`, `min`, `max`, `step`, `clearable`. | `forms/date-input.vue` |
184
+ | `DatePicker` | Input with a calendar popover. Single date or `range`. | Model: ISO string, range object (`start`, `end`) or null. Props: `range`, `min`, `max`, `isDateDisabled`, `locale`, `weekStartsOn`, `format`, `closeOnSelect`, `clearable`. Slot: `footer`. | `forms/date-picker.vue` |
185
+ | `Calendar` | Inline calendar. Use it for availability views, or as a building block. | Models: `v-model` (date or range), `v-model:month`. Props: `range`, `min`, `max`, `isDateDisabled`, `locale`, `weekStartsOn`, `dayText(iso)`. Slots: `day`, `footer`. Event: `select`. | `forms/calendar.vue` |
186
+ | `TimeInput` | Time of day (HH:MM, optional seconds). | Model: string or null. Props: `min`, `max`, `step`, `seconds`, `clearable`. | `forms/time-input.vue` |
187
+ | `ColorInput` | Color text field with picker and swatches. | Model: hex string or null. Props: `swatches` (strings or `{ value, label }`), `placeholder`, `invalidText`. | `forms/color-input.vue` |
188
+ | `PaletteSelect` | Select of a palette color, with the dot and the localized color name. | Model: `ColorValue` (palette name or `#rrggbb`) or null. A non-searchable `Combobox` (pass `:searchable="true"` to type a filter). Props: `colors` (subset of `PALETTE_COLORS`), `clearable` (placeholder "Automatic"), `custom` (adds "Custom": choosing it shows a `ColorInput` under the select and the model becomes the hex), `customLabel` (name of the color input), `placeholder`, `size`, `disabled`, `readonly`, `invalid`. | `forms/palette-select.vue` |
189
+ | `Slider` | Number in a range with drag handle. | Model: number. Props: `min`, `max`, `step`, `bubble` (true, always), `marks`, `format(value)`, `label`. Event: `change` (on release). | `forms/slider.vue` |
190
+ | `FileInput` | Drop zone and file picker. Validates type, size and count. Supports folders and previews. | Model: `File`, `File[]` or null. Props: `accept`, `acceptMode`, `maxSize`, `maxFiles`, `multiple`, `directory`, `directoryAction`, `previews`, `list`, `loading`, `capture`, `title`, `dropText`, `hint`. Slots: `title`, `hint`, `actions`. Events: `add`, `remove`, `invalid`, `reject`. | `forms/file-input.vue` |
190
191
 
191
192
  ## Overlays
192
193
 
package/README.md CHANGED
@@ -511,6 +511,7 @@ On your own elements, `paletteClass(color)` gives the class of a palette name an
511
511
  - `CheckboxGroup` takes `columns` (a number): the options are laid out in a grid with that many equal columns. Unset keeps the `orientation` layout. `variant="filled"` (`CheckboxGroupVariant`, `'default' | 'filled'`, default `'default'`) puts the options in a subtle filled panel, styled by `--k-checkbox-group-background` (`--k-subtle`), `--k-checkbox-group-padding` (0.75rem), `--k-checkbox-group-radius` (`--k-radius-md`) and `--k-checkbox-group-border` (none).
512
512
  - `Combobox` with `creatable` takes `createTransform` (`ComboboxCreateTransform`, `(input) => string | null | undefined`) and `createValidate` (`ComboboxCreateValidate`, `(input) => string | true | undefined`). The transform runs on the typed text first: the "Create" option shows its result, and an empty result (or `null`) shows no create option. The validator gets the transformed text when the user picks the create option: a returned string is the error, shown inline through the surrounding `FormField` (`useFieldControl().setControlError`, or a `FieldMessage` under the control and an announcement without a field) with `aria-invalid` on the input, and nothing is created; `true` or nothing accepts it. The error clears when the query changes. Both work with `multiple`, where created values become tags: `<KCombobox v-model="tags" multiple creatable :create-transform="(input) => input.toLowerCase()" :create-validate="(input) => input.length >= 3 || 'Too short'" />`.
513
513
  - `Combobox` takes `createActions` (`ComboboxCreateActions`, `(query) => ComboboxCreateAction[]`) to show several create items instead of the single "Create" item. Each action has `id` (the item key is `__create:<id>`), `label`, `icon` (default `plus`) and `run(query)`. The actions show at the end of the list under the same conditions as the create item: a non-empty query after `createTransform`, with no option whose label or value matches it exactly. The function gets that text, and an empty array shows no action. `createValidate` runs before `run`. When `run` returns an option, the combobox remembers it, emits `create` and selects it. When it returns nothing (for example it opens a form for the full record), nothing is selected: the query clears and the list closes (with `multiple`, only the query clears). Errors from `run` are logged. `createActions` replaces `creatable`: `<KCombobox v-model="category" :options="categories" :create-actions="(query) => [{ id: 'quick', label: 'Create here', run: createCategory }, { id: 'form', label: 'Create with details', icon: 'pencil-square', run: openForm }]" />`.
514
+ - `Combobox` with `:searchable="false"` is a plain select that keeps the option dots, icons, descriptions and groups: the control is a `<button>` with `role="combobox"` and `aria-haspopup="listbox"` that shows the selected label (with the color dot or the `icon`), or the placeholder when empty. There is no text to type and no filter. Click, Enter, Space, ArrowDown or ArrowUp open the list, the arrows, Home and End move, Enter or Space select (with `multiple` the list stays open), Escape and Tab close, and typing letters moves to the next option whose label starts with them (typeahead, like a native select). `clearable`, `disabled`, `readonly`, `invalid`, `size`, `icon`, `multiple` and `hideTags` work as usual; `creatable`, `createActions` and the async `search` are ignored. Use it for a short fixed list that needs a color dot or an icon (`PaletteSelect` uses it): `<KCombobox v-model="status" :options="statuses" :searchable="false" />`. The exposed `el` is the input, or the trigger button when not searchable.
514
515
  - `Combobox` with `multiple` takes `hideTags`: the selected values are not rendered as tags inside the control (the host shows them elsewhere), the placeholder stays visible and Backspace no longer removes the last value. Selection is still announced through the options. A long tag label is truncated with an ellipsis and the full label (with the option group or description) is in the tag tooltip.
515
516
  - `RecordList` keeps each title on one line with an ellipsis; the full title is in its `title` attribute. With a `row-click` listener each row is a navigation item (padding, the hover and press background of a ghost button, no separators, the list bleeds into the inline padding so the text stays aligned). The title of a clickable row is a button: Tab reaches every row, Enter or Space emits `row-click`, the focus ring is drawn around the row and the description is the button description. A click anywhere else in the row emits it too, except on a button, link, input, menu item or tab inside the row and inside an open menu, popover or dialog that the row contains; pressing those does not tint the row. Keep the actions of a row as buttons in `#action`, never as a second clickable area. `rowClickable(item)` returns `false` for the rows that open nothing: they keep the same padding, without the button, hover and pointer.
516
517
  - `Fieldset` is a native `fieldset`: `disabled` disables every control inside (also the buttons, not the links) and every `FormField` through the form disabled state. `:disabled="false"` enables a group inside a disabled `Form`. When it becomes disabled while a control inside has focus, the focus moves to the fieldset, never to the page. The legend comes from `legend` or the `#legend` slot.
@@ -7,6 +7,7 @@
7
7
  {
8
8
  'is-open': layer.isOpen.value,
9
9
  'is-multiple': multiple,
10
+ 'is-select': !searchable,
10
11
  'is-disabled': control.disabled.value,
11
12
  'has-lead': Boolean(icon || leadColor)
12
13
  },
@@ -57,6 +58,7 @@
57
58
  </span>
58
59
  </template>
59
60
  <input
61
+ v-if="searchable"
60
62
  ref="inputRef"
61
63
  :id="control.id.value"
62
64
  v-bind="$attrs"
@@ -88,6 +90,40 @@
88
90
  @focus="onFocus"
89
91
  @blur="onBlur"
90
92
  />
93
+ <button
94
+ v-else
95
+ ref="triggerRef"
96
+ :id="control.id.value"
97
+ :aria-labelledby="
98
+ control.labelledBy.value && !$attrs['aria-label'] ? `${control.labelledBy.value} ${valueId}` : void 0
99
+ "
100
+ v-bind="$attrs"
101
+ :disabled="control.disabled.value || void 0"
102
+ :aria-required="control.required.value ? 'true' : void 0"
103
+ :aria-invalid="invalid ? 'true' : void 0"
104
+ :aria-readonly="readonly ? 'true' : void 0"
105
+ :aria-describedby="joinIds($attrs['aria-describedby'], control.describedBy.value)"
106
+ type="button"
107
+ class="k-combobox-trigger"
108
+ role="combobox"
109
+ aria-haspopup="listbox"
110
+ :aria-expanded="layer.isOpen.value ? 'true' : 'false'"
111
+ :aria-controls="listId"
112
+ :aria-activedescendant="activeId"
113
+ @keydown="onTriggerKeydown"
114
+ @focus="onFocus"
115
+ @blur="onBlur"
116
+ >
117
+ <span
118
+ :id="valueId"
119
+ class="k-combobox-value"
120
+ :class="{ 'is-placeholder': !triggerText && !hiddenText }"
121
+ >
122
+ <template v-if="triggerText">{{ triggerText }}</template>
123
+ <span v-else-if="hiddenText" class="k-visually-hidden">{{ hiddenText }}</span>
124
+ <template v-else>{{ placeholder }}</template>
125
+ </span>
126
+ </button>
91
127
  <span class="k-combobox-trail">
92
128
  <Spinner v-if="busy" decorative size="xs" class="k-combobox-spinner" />
93
129
  <button
@@ -237,7 +273,7 @@ import {
237
273
  import { useFieldControl } from "../../composables/useField";
238
274
  import { useLocale } from "../../composables/useLocale";
239
275
  import { useFloatingLayer } from "../../internal/floating/layer";
240
- import { nextEnabledIndex } from "../../internal/core/roving";
276
+ import { nextEnabledIndex, useTypeahead } from "../../internal/core/roving";
241
277
  import { useAsyncSearch } from "../../internal/core/search";
242
278
  import LiveRegion from "../../internal/core/LiveRegion.vue";
243
279
  import { useLiveMessage } from "../../internal/core/live";
@@ -253,6 +289,7 @@ const props = defineProps({
253
289
  options: { type: Array, required: false, default: () => [] },
254
290
  name: { type: String, required: false },
255
291
  search: { type: Function, required: false },
292
+ searchable: { type: Boolean, required: false, default: true },
256
293
  filter: { type: Function, required: false },
257
294
  multiple: { type: Boolean, required: false },
258
295
  hideTags: { type: Boolean, required: false },
@@ -303,10 +340,15 @@ const attrs = useAttrs();
303
340
  const baseId = useId();
304
341
  const listId = `${baseId}-listbox`;
305
342
  const panelId = `${baseId}-panel`;
343
+ const valueId = `${baseId}-value`;
306
344
  const rootRef = useTemplateRef("rootRef");
307
345
  const controlRef = useTemplateRef("controlRef");
308
346
  const panelRef = useTemplateRef("panelRef");
309
347
  const inputRef = useTemplateRef("inputRef");
348
+ const triggerRef = useTemplateRef("triggerRef");
349
+ const controlEl = computed(
350
+ () => inputRef.value ?? triggerRef.value
351
+ );
310
352
  const errorId = `${baseId}-create-error`;
311
353
  const createError = ref();
312
354
  const editing = ref(false);
@@ -324,8 +366,9 @@ const control = useFieldControl({
324
366
  disabled: () => props.disabled,
325
367
  required: () => props.required
326
368
  });
369
+ const asyncSearch = computed(() => props.searchable ? props.search : void 0);
327
370
  const search = useAsyncSearch({
328
- search: () => props.search,
371
+ search: () => asyncSearch.value,
329
372
  onResults: (found, text) => {
330
373
  results.value = found;
331
374
  searchedOnce.value = true;
@@ -385,13 +428,17 @@ const inputValue = computed(() => {
385
428
  const inputPlaceholder = computed(
386
429
  () => props.multiple && !props.hideTags && selectedValues.value.length ? void 0 : props.placeholder
387
430
  );
431
+ const triggerText = computed(() => props.multiple ? "" : selectedLabel.value);
432
+ const hiddenText = computed(
433
+ () => props.multiple && !props.hideTags ? selectedValues.value.map(labelFor).join(", ") : ""
434
+ );
388
435
  const showClear = computed(
389
436
  () => props.clearable && interactive.value && selectedValues.value.length > 0
390
437
  );
391
438
  const activeQuery = computed(() => editing.value ? query.value.trim() : "");
392
- const sourceOptions = computed(() => props.search ? results.value : props.options);
439
+ const sourceOptions = computed(() => asyncSearch.value ? results.value : props.options);
393
440
  const filteredOptions = computed(() => {
394
- if (props.search) return results.value;
441
+ if (asyncSearch.value) return results.value;
395
442
  const needle = normalizeSearch(activeQuery.value);
396
443
  if (!needle) return props.options;
397
444
  return props.options.filter(
@@ -502,7 +549,7 @@ function openList() {
502
549
  if (!interactive.value || layer.isOpen.value) return;
503
550
  layer.show();
504
551
  initialActive();
505
- if (props.search && !searchedOnce.value) scheduleSearch(0);
552
+ if (asyncSearch.value && !searchedOnce.value) scheduleSearch(0);
506
553
  }
507
554
  function closeList() {
508
555
  layer.hide();
@@ -529,6 +576,9 @@ function onBlur(event) {
529
576
  closeList();
530
577
  resetQuery();
531
578
  }
579
+ function focusControl() {
580
+ controlEl.value?.focus();
581
+ }
532
582
  function onControlMousedown(event) {
533
583
  if (!interactive.value) return;
534
584
  const target = event.target;
@@ -536,21 +586,71 @@ function onControlMousedown(event) {
536
586
  if (!layer.isOpen.value) openList();
537
587
  return;
538
588
  }
539
- if (target.closest("button")) {
589
+ if (target.closest("button") && !triggerRef.value?.contains(target)) {
540
590
  event.preventDefault();
541
591
  return;
542
592
  }
543
593
  event.preventDefault();
544
- inputRef.value?.focus();
594
+ focusControl();
545
595
  if (layer.isOpen.value) closeList();
546
596
  else openList();
547
597
  }
548
598
  function onToggleClick() {
549
599
  if (!interactive.value) return;
550
- inputRef.value?.focus();
600
+ focusControl();
551
601
  if (layer.isOpen.value) closeList();
552
602
  else openList();
553
603
  }
604
+ const typeahead = useTypeahead();
605
+ function onTypeahead(event) {
606
+ if (event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey) return false;
607
+ if (event.key === " " && !typeahead.typing()) return false;
608
+ const { query: text, cycle } = typeahead.type(event.key);
609
+ openList();
610
+ const needle = normalizeSearch(text);
611
+ const list = items.value;
612
+ const start = cycle ? activeIndex.value + 1 : Math.max(activeIndex.value, 0);
613
+ for (let offset = 0; offset < list.length; offset++) {
614
+ const index = (start + offset) % list.length;
615
+ const option = list[index].option;
616
+ if (!option.disabled && normalizeSearch(option.label).startsWith(needle)) {
617
+ activeIndex.value = index;
618
+ break;
619
+ }
620
+ }
621
+ return true;
622
+ }
623
+ function openAt(index) {
624
+ openList();
625
+ if (index >= 0) activeIndex.value = index;
626
+ }
627
+ function onTriggerKeydown(event) {
628
+ if (!interactive.value) return;
629
+ if (onTypeahead(event)) {
630
+ event.preventDefault();
631
+ return;
632
+ }
633
+ const open = layer.isOpen.value;
634
+ const last = () => firstEnabled(items.value.length - 1, -1);
635
+ if (!open && (event.key === "Enter" || event.key === " " || event.key === "ArrowDown")) {
636
+ event.preventDefault();
637
+ openList();
638
+ if (!event.altKey && activeIndex.value < 0) activeIndex.value = firstEnabled();
639
+ return;
640
+ }
641
+ if (!open && (event.key === "Home" || event.key === "End")) {
642
+ event.preventDefault();
643
+ openAt(event.key === "Home" ? firstEnabled() : last());
644
+ return;
645
+ }
646
+ if (open && event.key === " ") {
647
+ event.preventDefault();
648
+ const item = items.value[activeIndex.value];
649
+ if (item) void choose(item);
650
+ return;
651
+ }
652
+ onKeydown(event);
653
+ }
554
654
  function onKeydown(event) {
555
655
  if (!interactive.value) return;
556
656
  const open = layer.isOpen.value;
@@ -666,7 +766,7 @@ function select(option) {
666
766
  }
667
767
  if (editing.value && query.value) {
668
768
  resetQuery();
669
- if (props.search) scheduleSearch(0);
769
+ if (asyncSearch.value) scheduleSearch(0);
670
770
  nextTick(() => {
671
771
  activeIndex.value = items.value.findIndex((item) => keyOf(item.option.value) === key);
672
772
  });
@@ -675,17 +775,17 @@ function select(option) {
675
775
  function dismissQuery() {
676
776
  resetQuery();
677
777
  if (!props.multiple) closeList();
678
- else if (props.search) scheduleSearch(0);
778
+ else if (asyncSearch.value) scheduleSearch(0);
679
779
  }
680
780
  function remove(value) {
681
781
  const key = keyOf(value);
682
782
  model.value = selectedValues.value.filter((entry) => keyOf(entry) !== key);
683
- inputRef.value?.focus();
783
+ focusControl();
684
784
  }
685
785
  function clear() {
686
786
  model.value = props.multiple ? [] : null;
687
787
  resetQuery();
688
- inputRef.value?.focus();
788
+ focusControl();
689
789
  }
690
790
  function scheduleSearch(delay) {
691
791
  const text = activeQuery.value;
@@ -717,9 +817,9 @@ watch(
717
817
  { immediate: true }
718
818
  );
719
819
  defineExpose({
720
- focus: () => inputRef.value?.focus(),
820
+ focus: focusControl,
721
821
  open: openList,
722
822
  close: closeList,
723
- el: inputRef
823
+ el: controlEl
724
824
  });
725
825
  </script>
@@ -6,6 +6,7 @@ declare const __VLS_export: <T extends string | number, M extends T | T[] | null
6
6
  options?: ComboboxOption<T>[];
7
7
  name?: string;
8
8
  search?: ComboboxSearch<T>;
9
+ searchable?: boolean;
9
10
  filter?: (option: ComboboxOption<T>, query: string) => boolean;
10
11
  multiple?: boolean;
11
12
  hideTags?: boolean;
@@ -45,14 +46,14 @@ declare const __VLS_export: <T extends string | number, M extends T | T[] | null
45
46
  onOpen?: (() => any) | undefined;
46
47
  "onUpdate:modelValue"?: ((value: M | undefined) => any) | undefined;
47
48
  "onUpdate:query"?: ((value: string) => any) | undefined;
48
- } & Partial<import("vue").InputHTMLAttributes & import("vue").ReservedProps>> & (typeof globalThis extends {
49
+ } & Partial<import("vue").InputHTMLAttributes & import("vue").ReservedProps & import("vue").ButtonHTMLAttributes>> & (typeof globalThis extends {
49
50
  __VLS_PROPS_FALLBACK: infer P;
50
51
  } ? P : {});
51
52
  expose: (exposed: import("vue").ShallowUnwrapRef<{
52
- focus: () => void | undefined;
53
+ focus: () => void;
53
54
  open: () => void;
54
55
  close: () => void;
55
- el: Readonly<import("vue").ShallowRef<HTMLInputElement | null>>;
56
+ el: import("vue").ComputedRef<HTMLInputElement | HTMLButtonElement | null>;
56
57
  }>) => void;
57
58
  attrs: any;
58
59
  slots: {
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <div class="k-palette-select" :class="[props.class]" :style="props.style">
3
3
  <Combobox
4
+ :searchable="false"
4
5
  v-bind="$attrs"
5
6
  v-model="selected"
6
7
  :options="options"
@@ -139,7 +139,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
139
139
  color?: string | undefined | undefined;
140
140
  height?: (string | number) | undefined;
141
141
  lang?: string | undefined | undefined;
142
- type?: import("vue").InputTypeHTMLAttribute | undefined;
142
+ type?: "submit" | "button" | "reset" | undefined;
143
143
  width?: (string | number) | undefined;
144
144
  tabindex?: (string | number) | undefined;
145
145
  'aria-activedescendant'?: string | undefined | undefined;
@@ -256,6 +256,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
256
256
  onCreate?: ((option: ComboboxOption<PaletteOptionValue>) => any) | undefined;
257
257
  onOpen?: (() => any) | undefined;
258
258
  "onUpdate:query"?: ((value: string) => any) | undefined;
259
+ searchable?: boolean | undefined;
259
260
  hideTags?: boolean | undefined;
260
261
  creatable?: boolean | import("./types").ComboboxCreate<PaletteOptionValue> | undefined;
261
262
  createActions?: import("./types").ComboboxCreateActions<PaletteOptionValue> | undefined;
@@ -408,7 +409,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
408
409
  color?: string | undefined | undefined;
409
410
  height?: (string | number) | undefined;
410
411
  lang?: string | undefined | undefined;
411
- type?: import("vue").InputTypeHTMLAttribute | undefined;
412
+ type?: "submit" | "button" | "reset" | undefined;
412
413
  width?: (string | number) | undefined;
413
414
  tabindex?: (string | number) | undefined;
414
415
  'aria-activedescendant'?: string | undefined | undefined;
@@ -525,6 +526,7 @@ declare const __VLS_export: import("vue").DefineComponent<{
525
526
  onCreate?: ((option: ComboboxOption<PaletteOptionValue>) => any) | undefined;
526
527
  onOpen?: (() => any) | undefined;
527
528
  "onUpdate:query"?: ((value: string) => any) | undefined;
529
+ searchable?: boolean | undefined;
528
530
  hideTags?: boolean | undefined;
529
531
  creatable?: boolean | import("./types").ComboboxCreate<PaletteOptionValue> | undefined;
530
532
  createActions?: import("./types").ComboboxCreateActions<PaletteOptionValue> | undefined;
@@ -428,8 +428,8 @@ declare const __VLS_base: import("vue").DefineComponent<{
428
428
  onFiltersReset?: (() => any) | undefined;
429
429
  onFilterRemove?: ((id: string) => any) | undefined;
430
430
  }>, {
431
- debounce: number;
432
431
  searchable: boolean;
432
+ debounce: number;
433
433
  columnMenu: boolean;
434
434
  exportable: boolean;
435
435
  exportFileName: string;
@@ -55,10 +55,54 @@
55
55
  padding-left: 0.25rem;
56
56
  }
57
57
 
58
- .k-combobox-input:disabled {
58
+ .k-combobox-input:disabled,
59
+ .k-combobox-trigger:disabled {
59
60
  cursor: not-allowed;
60
61
  }
61
62
 
63
+ .k-combobox-trigger:disabled {
64
+ color: var(--k-text-muted);
65
+ }
66
+
67
+ .k-combobox.is-select .k-combobox-control:not(.is-disabled, .is-readonly) {
68
+ cursor: pointer;
69
+ }
70
+
71
+ .k-combobox.is-select .k-combobox-control.is-readonly {
72
+ cursor: default;
73
+ }
74
+
75
+ .k-combobox-trigger {
76
+ display: flex;
77
+ flex: 1 1 4rem;
78
+ align-items: center;
79
+ min-width: 4rem;
80
+ height: var(--k-combobox-tag-height);
81
+ padding: 0;
82
+ border: 0;
83
+ outline: none;
84
+ background: transparent;
85
+ color: var(--k-text);
86
+ font: inherit;
87
+ text-align: left;
88
+ cursor: inherit;
89
+ }
90
+
91
+ .k-combobox.is-multiple .k-combobox-control:has(.k-combobox-tag) .k-combobox-trigger {
92
+ padding-left: 0.25rem;
93
+ }
94
+
95
+ .k-combobox-value {
96
+ min-width: 0;
97
+ overflow-x: clip;
98
+ text-overflow: ellipsis;
99
+ white-space: nowrap;
100
+ }
101
+
102
+ .k-combobox-value.is-placeholder {
103
+ color: var(--k-text-muted);
104
+ }
105
+
62
106
  .k-combobox-lead {
63
107
  display: flex;
64
108
  margin-right: 0.25rem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xleddyl/443-components-vue",
3
- "version": "0.16.72",
3
+ "version": "0.16.73",
4
4
  "description": "Compact, scoped dashboard components for Vue and Nuxt",
5
5
  "license": "MIT",
6
6
  "author": "Edoardo Alberti (https://github.com/xleddyl)",