@zazz-ui/core 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORING.md +158 -0
- package/CHANGELOG.md +345 -0
- package/README.md +55 -23
- package/dist/scroll-state-C8mA5gq6.js +1 -0
- package/dist/sri.json +124 -72
- package/dist/zazz.css +1 -1
- package/dist/zazz.js +1 -1
- package/editor/zazz.css-data.json +116794 -0
- package/editor/zazz.html-data.json +1683 -0
- package/editor/zazz.language-data.json +5001 -0
- package/editor/zazz.lint-data.json +152 -0
- package/package.json +12 -5
- package/src/base/_breakpoints.css +12 -0
- package/src/base/_layers.css +8 -9
- package/src/base/_properties-2xl.css +171 -0
- package/src/base/_properties-active.css +107 -0
- package/src/base/_properties-checked.css +107 -0
- package/src/base/_properties-current.css +107 -0
- package/src/base/_properties-disabled.css +107 -0
- package/src/base/_properties-focus-visible.css +107 -0
- package/src/base/_properties-focus-within.css +107 -0
- package/src/base/_properties-hover.css +107 -0
- package/src/base/_properties-lg.css +171 -0
- package/src/base/_properties-md.css +171 -0
- package/src/base/_properties-open.css +107 -0
- package/src/base/_properties-sm.css +171 -0
- package/src/base/_properties-starting.css +55 -0
- package/src/base/_properties-stuck.css +55 -0
- package/src/base/_properties-xl.css +171 -0
- package/src/base/_properties.css +555 -0
- package/src/base/_reset.css +67 -75
- package/src/base/_switches.css +145 -0
- package/src/base/_typography.css +437 -370
- package/src/base/_utilities-box.css +142 -0
- package/src/base/_utilities-color.css +290 -0
- package/src/base/_utilities-effects.css +235 -0
- package/src/base/_utilities-flow.css +312 -0
- package/src/base/_utilities-grid.css +143 -0
- package/src/base/_utilities-margin.css +376 -0
- package/src/base/_utilities-pseudo.css +426 -0
- package/src/base/_utilities-sizing.css +259 -0
- package/src/base/_utilities-spacing.css +190 -0
- package/src/base/_utilities-tier-2xl.css +93 -0
- package/src/base/_utilities-tier-active.css +61 -0
- package/src/base/_utilities-tier-checked.css +61 -0
- package/src/base/_utilities-tier-current.css +61 -0
- package/src/base/_utilities-tier-disabled.css +61 -0
- package/src/base/_utilities-tier-focus-visible.css +61 -0
- package/src/base/_utilities-tier-focus-within.css +61 -0
- package/src/base/_utilities-tier-hover.css +63 -0
- package/src/base/_utilities-tier-lg.css +93 -0
- package/src/base/_utilities-tier-md.css +93 -0
- package/src/base/_utilities-tier-open.css +61 -0
- package/src/base/_utilities-tier-sm.css +93 -0
- package/src/base/_utilities-tier-starting.css +35 -0
- package/src/base/_utilities-tier-stuck.css +114 -0
- package/src/base/_utilities-tier-xl.css +93 -0
- package/src/base/_utilities-typography.css +141 -0
- package/src/base/_variables.css +323 -372
- package/src/base/_view-transitions.css +10 -12
- package/src/base/command-score.d.ts.map +1 -1
- package/src/base/command-score.js +1 -2
- package/src/base/command-score.ts +1 -2
- package/src/base/dialog-lifecycle.js +1 -1
- package/src/base/dialog-lifecycle.ts +1 -1
- package/src/base/embla.d.ts +6 -7
- package/src/base/embla.d.ts.map +1 -1
- package/src/base/embla.js +89 -55
- package/src/base/embla.ts +89 -55
- package/src/base/hotkeys.d.ts +0 -5
- package/src/base/hotkeys.d.ts.map +1 -1
- package/src/base/hotkeys.ts +0 -5
- package/src/base/navigation.d.ts +12 -1
- package/src/base/navigation.d.ts.map +1 -1
- package/src/base/navigation.js +229 -86
- package/src/base/navigation.ts +224 -92
- package/src/base/reveal.js +14 -14
- package/src/base/reveal.ts +14 -14
- package/src/base/scroll-state.d.ts +21 -0
- package/src/base/scroll-state.d.ts.map +1 -0
- package/src/base/scroll-state.js +177 -0
- package/src/base/scroll-state.ts +188 -0
- package/src/base/signals.d.ts +1 -2
- package/src/base/signals.d.ts.map +1 -1
- package/src/base/signals.js +4 -6
- package/src/base/signals.ts +4 -6
- package/src/base/style-format.d.ts +33 -0
- package/src/base/style-format.d.ts.map +1 -0
- package/src/base/style-format.js +160 -0
- package/src/base/style-format.ts +180 -0
- package/src/base/typeahead.d.ts +19 -4
- package/src/base/typeahead.d.ts.map +1 -1
- package/src/base/typeahead.js +68 -21
- package/src/base/typeahead.ts +73 -23
- package/src/base/utilities.d.ts +188 -0
- package/src/base/utilities.d.ts.map +1 -0
- package/src/base/utilities.js +750 -0
- package/src/base/utilities.ts +865 -0
- package/src/base/utils.d.ts +3 -7
- package/src/base/utils.d.ts.map +1 -1
- package/src/base/utils.js +4 -8
- package/src/base/utils.ts +4 -8
- package/src/base/zazz-element.d.ts +14 -8
- package/src/base/zazz-element.d.ts.map +1 -1
- package/src/base/zazz-element.js +14 -8
- package/src/base/zazz-element.ts +15 -8
- package/src/globals.d.ts +1 -1
- package/src/head.d.ts +50 -4
- package/src/head.d.ts.map +1 -1
- package/src/head.js +119 -38
- package/src/head.ts +172 -41
- package/src/index.css +57 -14
- package/src/index.js +5 -0
- package/src/index.ts +6 -0
- package/src/manifest.d.ts +36 -5
- package/src/manifest.d.ts.map +1 -1
- package/src/manifest.js +150 -6
- package/src/manifest.ts +167 -9
- package/src/primitives/accordion/accordion.css +18 -17
- package/src/primitives/accordion/accordion.html +42 -9
- package/src/primitives/alert-dialog/alert-dialog.css +13 -13
- package/src/primitives/alert-dialog/alert-dialog.html +26 -12
- package/src/primitives/autocomplete/autocomplete-groups.html +64 -33
- package/src/primitives/autocomplete/autocomplete.css +43 -39
- package/src/primitives/autocomplete/autocomplete.d.ts +6 -5
- package/src/primitives/autocomplete/autocomplete.d.ts.map +1 -1
- package/src/primitives/autocomplete/autocomplete.html +38 -26
- package/src/primitives/autocomplete/autocomplete.js +6 -5
- package/src/primitives/autocomplete/autocomplete.ts +6 -5
- package/src/primitives/avatar/avatar.html +110 -15
- package/src/primitives/badge/badge-icon.html +22 -8
- package/src/primitives/badge/badge.css +401 -128
- package/src/primitives/badge/badge.html +12 -6
- package/src/primitives/breadcrumbs/breadcrumbs.html +25 -5
- package/src/primitives/button/button-icon-only.html +17 -11
- package/src/primitives/button/button-icon.html +9 -3
- package/src/primitives/button/button.css +408 -164
- package/src/primitives/button/button.html +14 -7
- package/src/primitives/button-group/button-group-vertical.html +5 -5
- package/src/primitives/button-group/button-group.css +61 -31
- package/src/primitives/button-group/button-group.html +18 -12
- package/src/primitives/callout/callout.css +114 -0
- package/src/primitives/callout/callout.html +188 -0
- package/src/primitives/card/card-subgrid.html +249 -34
- package/src/primitives/card/card.css +125 -0
- package/src/primitives/card/card.html +141 -20
- package/src/primitives/carousel/carousel.css +30 -20
- package/src/primitives/carousel/carousel.d.ts +7 -10
- package/src/primitives/carousel/carousel.d.ts.map +1 -1
- package/src/primitives/carousel/carousel.html +420 -84
- package/src/primitives/carousel/carousel.js +1 -1
- package/src/primitives/carousel/carousel.ts +8 -11
- package/src/primitives/checkbox/checkbox-tasklist.html +6 -6
- package/src/primitives/checkbox/checkbox.css +98 -40
- package/src/primitives/checkbox/checkbox.d.ts.map +1 -1
- package/src/primitives/checkbox/checkbox.html +13 -8
- package/src/primitives/checkbox/checkbox.js +7 -9
- package/src/primitives/checkbox/checkbox.ts +7 -15
- package/src/primitives/combobox/combobox-multiselect.html +53 -33
- package/src/primitives/combobox/combobox.css +145 -122
- package/src/primitives/combobox/combobox.d.ts +12 -11
- package/src/primitives/combobox/combobox.d.ts.map +1 -1
- package/src/primitives/combobox/combobox.html +48 -28
- package/src/primitives/combobox/combobox.js +46 -51
- package/src/primitives/combobox/combobox.ts +48 -55
- package/src/primitives/command/command-actions.d.ts +2 -3
- package/src/primitives/command/command-actions.d.ts.map +1 -1
- package/src/primitives/command/command-actions.html +48 -33
- package/src/primitives/command/command-actions.js +12 -10
- package/src/primitives/command/command-actions.ts +12 -13
- package/src/primitives/command/command-dialog.html +49 -25
- package/src/primitives/command/command.css +52 -42
- package/src/primitives/command/command.d.ts +10 -7
- package/src/primitives/command/command.d.ts.map +1 -1
- package/src/primitives/command/command.html +95 -46
- package/src/primitives/command/command.js +30 -13
- package/src/primitives/command/command.ts +30 -12
- package/src/primitives/debug/audit-core.d.ts +64 -0
- package/src/primitives/debug/audit-core.d.ts.map +1 -0
- package/src/primitives/debug/audit-core.js +356 -0
- package/src/primitives/debug/audit-core.ts +535 -0
- package/src/primitives/debug/debug.d.ts +50 -0
- package/src/primitives/debug/debug.d.ts.map +1 -0
- package/src/primitives/debug/debug.js +168 -0
- package/src/primitives/debug/debug.ts +211 -0
- package/src/primitives/dialog/dialog-with-form.html +67 -45
- package/src/primitives/dialog/dialog.css +87 -61
- package/src/primitives/dialog/dialog.html +25 -17
- package/src/primitives/fields/fields.css +108 -134
- package/src/primitives/fields/fields.html +39 -0
- package/src/primitives/input/input-icon-leading.html +3 -3
- package/src/primitives/input/input-icon-trailing.html +3 -3
- package/src/primitives/input/input.css +87 -49
- package/src/primitives/input/input.html +15 -15
- package/src/primitives/input-group/input-group-password-group.html +15 -15
- package/src/primitives/input-group/input-group.css +118 -75
- package/src/primitives/input-group/input-group.html +42 -30
- package/src/primitives/kbd/kbd-group.html +15 -2
- package/src/primitives/kbd/kbd.css +44 -31
- package/src/primitives/kbd/kbd.html +7 -1
- package/src/primitives/layout/layout.css +159 -0
- package/src/primitives/layout/layout.html +35 -0
- package/src/primitives/lightbox/lightbox.css +178 -105
- package/src/primitives/lightbox/lightbox.d.ts.map +1 -1
- package/src/primitives/lightbox/lightbox.html +138 -166
- package/src/primitives/lightbox/lightbox.js +10 -13
- package/src/primitives/lightbox/lightbox.ts +12 -13
- package/src/primitives/menu/menu-interest.html +60 -18
- package/src/primitives/menu/menu.css +22 -17
- package/src/primitives/menu/menu.d.ts +5 -5
- package/src/primitives/menu/menu.html +195 -40
- package/src/primitives/menu/menu.js +8 -8
- package/src/primitives/menu/menu.ts +8 -8
- package/src/primitives/menubar/menubar-help-search.html +78 -32
- package/src/primitives/menubar/menubar.html +166 -38
- package/src/primitives/meter/meter.css +41 -38
- package/src/primitives/meter/meter.html +44 -9
- package/src/primitives/mobile-menu/mobile-menu.css +47 -40
- package/src/primitives/mobile-menu/mobile-menu.html +1460 -179
- package/src/primitives/navigation-menu/navigation-menu-featured.html +155 -33
- package/src/primitives/navigation-menu/navigation-menu-icon-grid.html +222 -47
- package/src/primitives/navigation-menu/navigation-menu-interest.html +130 -38
- package/src/primitives/navigation-menu/navigation-menu-megamenu.html +402 -72
- package/src/primitives/navigation-menu/navigation-menu-simple.html +90 -40
- package/src/primitives/navigation-menu/navigation-menu.css +104 -106
- package/src/primitives/navigation-menu/navigation-menu.html +554 -158
- package/src/primitives/otp/otp.css +43 -44
- package/src/primitives/otp/otp.d.ts +4 -5
- package/src/primitives/otp/otp.d.ts.map +1 -1
- package/src/primitives/otp/otp.html +7 -6
- package/src/primitives/otp/otp.js +13 -18
- package/src/primitives/otp/otp.ts +12 -19
- package/src/primitives/password-group/password-group.css +132 -107
- package/src/primitives/password-group/password-group.d.ts.map +1 -1
- package/src/primitives/password-group/password-group.html +23 -16
- package/src/primitives/password-group/password-group.js +11 -12
- package/src/primitives/password-group/password-group.ts +11 -12
- package/src/primitives/popover/popover.css +88 -95
- package/src/primitives/popover/popover.html +18 -0
- package/src/primitives/progress/progress-indeterminate.html +1 -1
- package/src/primitives/progress/progress.css +34 -35
- package/src/primitives/progress/progress.html +18 -4
- package/src/primitives/prose/prose.html +19 -12
- package/src/primitives/radio/radio.css +83 -46
- package/src/primitives/radio/radio.html +16 -11
- package/src/primitives/reveal/reveal.css +37 -46
- package/src/primitives/reveal/reveal.html +15 -0
- package/src/primitives/scroll-fade/scroll-fade.css +115 -0
- package/src/primitives/scroll-fade/scroll-fade.html +69 -0
- package/src/primitives/select/multiselect.d.ts +8 -10
- package/src/primitives/select/multiselect.d.ts.map +1 -1
- package/src/primitives/select/multiselect.js +23 -27
- package/src/primitives/select/multiselect.ts +23 -29
- package/src/primitives/select/select-align.html +79 -16
- package/src/primitives/select/select-multiple.html +8 -4
- package/src/primitives/select/select-sides.html +104 -21
- package/src/primitives/select/select.css +297 -186
- package/src/primitives/select/select.html +24 -5
- package/src/primitives/separator/separator.css +15 -18
- package/src/primitives/separator/separator.html +37 -10
- package/src/primitives/slider/slider.css +48 -38
- package/src/primitives/slider/slider.html +9 -1
- package/src/primitives/style-guard/style-guard.d.ts +19 -0
- package/src/primitives/style-guard/style-guard.d.ts.map +1 -0
- package/src/primitives/style-guard/style-guard.js +125 -0
- package/src/primitives/style-guard/style-guard.ts +153 -0
- package/src/primitives/switch/switch.css +42 -33
- package/src/primitives/switch/switch.html +11 -6
- package/src/primitives/table/table-alternating.html +1 -1
- package/src/primitives/table/table-grid.html +5 -5
- package/src/primitives/table/table-size-sm.html +1 -1
- package/src/primitives/table/table.css +64 -61
- package/src/primitives/table/table.html +7 -7
- package/src/primitives/tabs/tabs.css +167 -166
- package/src/primitives/tabs/tabs.d.ts +10 -11
- package/src/primitives/tabs/tabs.d.ts.map +1 -1
- package/src/primitives/tabs/tabs.html +192 -36
- package/src/primitives/tabs/tabs.js +14 -15
- package/src/primitives/tabs/tabs.ts +14 -15
- package/src/primitives/textarea/textarea.css +69 -44
- package/src/primitives/textarea/textarea.html +3 -3
- package/src/primitives/toaster/toaster.css +90 -92
- package/src/primitives/toaster/toaster.d.ts +0 -6
- package/src/primitives/toaster/toaster.d.ts.map +1 -1
- package/src/primitives/toaster/toaster.html +22 -18
- package/src/primitives/toaster/toaster.js +64 -72
- package/src/primitives/toaster/toaster.ts +71 -87
- package/src/primitives/toggle/toggle.css +368 -153
- package/src/primitives/toggle/toggle.html +27 -9
- package/src/primitives/toggle-group/toggle-group-multiple.html +3 -3
- package/src/primitives/toggle-group/toggle-group-vertical.html +4 -4
- package/src/primitives/toggle-group/toggle-group.css +76 -26
- package/src/primitives/toggle-group/toggle-group.html +3 -3
- package/src/primitives/toolbar/toolbar.html +35 -13
- package/src/primitives/tooltip/tooltip-disabled.html +3 -3
- package/src/primitives/tooltip/tooltip-sides.html +36 -14
- package/src/primitives/tooltip/tooltip-with-kbd.html +5 -5
- package/src/primitives/tooltip/tooltip.css +111 -80
- package/src/primitives/tooltip/tooltip.html +3 -3
- package/src/primitives/utilities/aspect-ratio.html +51 -7
- package/src/primitives/utilities/basis.html +64 -11
- package/src/primitives/utilities/col-span.html +65 -9
- package/src/primitives/utilities/compose.html +48 -10
- package/src/primitives/utilities/flex-align.html +89 -19
- package/src/primitives/utilities/flex-direction.html +111 -13
- package/src/primitives/utilities/flex-grow.html +41 -7
- package/src/primitives/utilities/gap.html +158 -19
- package/src/primitives/utilities/grid-cols.html +75 -7
- package/src/primitives/utilities/grid-responsive.html +111 -12
- package/src/primitives/utilities/margin-auto.html +38 -7
- package/src/primitives/utilities/object-fit.html +75 -13
- package/src/primitives/utilities/order.html +40 -4
- package/src/primitives/utilities/overflow.html +74 -20
- package/src/primitives/utilities/padding-compose.html +67 -10
- package/src/primitives/utilities/padding.html +84 -13
- package/src/primitives/utilities/pile.html +29 -0
- package/src/primitives/utilities/position.html +65 -8
- package/src/primitives/utilities/responsive-flex.html +54 -7
- package/src/primitives/utilities/responsive-grid.html +115 -12
- package/src/primitives/utilities/size.html +120 -16
- package/src/primitives/utilities/width.html +123 -16
- package/examples/about.html +0 -583
- package/examples/components.html +0 -1028
- package/examples/forms.html +0 -504
- package/examples/index.html +0 -261
- package/examples/layout.html +0 -313
- package/examples/products.html +0 -839
- package/examples/responsive.html +0 -332
- package/src/base/_layout.css +0 -571
- package/src/base/_utilities.css +0 -6758
- package/src/primitives/utilities/grid-pile.html +0 -5
|
@@ -4,34 +4,35 @@
|
|
|
4
4
|
* @description Light-DOM custom element on the shared typeahead engine
|
|
5
5
|
* (`base/typeahead.ts`). A relative of select: the panel filters as you type,
|
|
6
6
|
* but free text can never submit. The form value lives in an authored hidden
|
|
7
|
-
* input (`data-slot="
|
|
7
|
+
* input (`data-combobox-slot="value"`), synced whenever the selection changes.
|
|
8
8
|
*
|
|
9
9
|
* The visible input carries a **display value, not the filter**. Committing
|
|
10
10
|
* writes the option label into it and clears the query, so reopening shows
|
|
11
|
-
* the full list with the committed row checked, matching
|
|
11
|
+
* the full list with the committed row checked, matching `[data-ui~="select"]`.
|
|
12
12
|
* Opening selects that label so the first keystroke replaces it, and focus
|
|
13
13
|
* alone never opens the panel (a click, the chevron, an arrow key or typing
|
|
14
14
|
* does). On blur, stray text reverts to the committed label and cleared text
|
|
15
15
|
* clears the selection.
|
|
16
16
|
*
|
|
17
|
-
* `data-variant="multiselect"` selects a set instead: committing toggles a row
|
|
17
|
+
* `data-combobox-variant="multiselect"` selects a set instead: committing toggles a row
|
|
18
18
|
* and keeps the panel open, and every selected value renders as a removable
|
|
19
19
|
* tag stamped inside the control. The tag markup is HTML, not script: author
|
|
20
|
-
* a `<template data-slot="
|
|
20
|
+
* a `<template data-combobox-slot="tag-template">` to control its classes and
|
|
21
21
|
* structure, and this file fills in the label, the value, and the remove
|
|
22
|
-
* button accessible name. Without one, the
|
|
22
|
+
* button accessible name. Without one, the badge default below applies.
|
|
23
23
|
* Backspace on an empty input drops the last tag. Options carrying
|
|
24
24
|
* `aria-selected="true"` are the single source of truth: the tags and the
|
|
25
25
|
* hidden inputs are both derived from them in DOM order so nothing can drift.
|
|
26
26
|
* The form submits repeated `name` pairs like `<select multiple>`: the authored
|
|
27
27
|
* hidden input carries the first value, and stamped siblings carry the rest.
|
|
28
28
|
*
|
|
29
|
-
* Where a no-JS fallback matters, prefer
|
|
29
|
+
* Where a no-JS fallback matters, prefer `[data-ui~="select"]` / `<ui-multiselect>`:
|
|
30
30
|
* this control is inert without its script (the hidden input still submits a
|
|
31
31
|
* server-set value, but no tags render).
|
|
32
32
|
*
|
|
33
|
-
* Attributes on the root: `data-variant="multiselect"`, `data-sort="score"`,
|
|
34
|
-
* `data-
|
|
33
|
+
* Attributes on the root: `data-combobox-variant="multiselect"`, `data-combobox-sort="score"`,
|
|
34
|
+
* `data-combobox-filter="none"` (another source filters; the engine only navigates),
|
|
35
|
+
* `data-combobox-min-length="<n>"`, `data-combobox-label-remove="Remove {label}"`.
|
|
35
36
|
* Parts: `combobox-value` (hidden input), `combobox-control` (select-look
|
|
36
37
|
* shell), `combobox-tag-template` (authored `<template>`), `combobox-tag` /
|
|
37
38
|
* `combobox-tag-label` / `combobox-tag-remove` (cloned from it),
|
|
@@ -40,17 +41,10 @@
|
|
|
40
41
|
*/
|
|
41
42
|
import { TypeaheadElement } from "../../base/typeahead.js";
|
|
42
43
|
import { defineZazzElement } from "../../base/zazz-element.js";
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* a tag (other classes, an extra icon, a different component entirely) never
|
|
48
|
-
* means editing this script. Kept as markup rather than createElement calls so
|
|
49
|
-
* the default reads the same way the override is written.
|
|
50
|
-
*/
|
|
51
|
-
const TAG_MARKUP = '<span class="ui-badge" data-slot="combobox-tag">' +
|
|
52
|
-
'<span data-slot="combobox-tag-label"></span>' +
|
|
53
|
-
'<button type="button" tabindex="-1" data-slot="combobox-tag-remove"></button>' +
|
|
44
|
+
/** Default tag markup, cloned per selected value; a `tag-template` overrides it. */
|
|
45
|
+
const TAG_MARKUP = '<span data-ui="badge" data-combobox-slot="tag">' +
|
|
46
|
+
'<span data-combobox-slot="tag-label"></span>' +
|
|
47
|
+
'<button type="button" tabindex="-1" data-combobox-slot="tag-remove"></button>' +
|
|
54
48
|
"</span>";
|
|
55
49
|
let defaultTagTemplate = null;
|
|
56
50
|
/**
|
|
@@ -85,7 +79,7 @@ function resolveBlur(typed, committedLabel, multiselect) {
|
|
|
85
79
|
return { value: committedLabel, clear: false };
|
|
86
80
|
}
|
|
87
81
|
/**
|
|
88
|
-
* @description Fills the remove-button label template (`data-label-remove`).
|
|
82
|
+
* @description Fills the remove-button label template (`data-combobox-label-remove`).
|
|
89
83
|
*
|
|
90
84
|
* @param template - Template with a `{label}` placeholder.
|
|
91
85
|
* @param label - The tag's visible label.
|
|
@@ -94,7 +88,6 @@ function resolveBlur(typed, committedLabel, multiselect) {
|
|
|
94
88
|
function resolveRemoveLabel(template, label) {
|
|
95
89
|
return template.replace("{label}", label);
|
|
96
90
|
}
|
|
97
|
-
// --- Element ---
|
|
98
91
|
class UiCombobox extends TypeaheadElement {
|
|
99
92
|
slotPrefix = "combobox";
|
|
100
93
|
/** The input holds a committed label, so focus alone must not open the list. */
|
|
@@ -111,7 +104,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
111
104
|
const multiselect = this.#multiselect();
|
|
112
105
|
this.#placeholder = input.getAttribute("placeholder") ?? "";
|
|
113
106
|
if (multiselect) {
|
|
114
|
-
this.querySelector('[data-slot~="
|
|
107
|
+
this.querySelector('[data-combobox-slot~="list"]')?.setAttribute("aria-multiselectable", "true");
|
|
115
108
|
}
|
|
116
109
|
// Adopt a server-rendered value no row claims yet, so `value` alone is
|
|
117
110
|
// enough markup to seed the selection, ensuring the sync below never
|
|
@@ -135,7 +128,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
135
128
|
this.#committedLabel = multiselect ? "" : (this.#selectedLabel() ?? "");
|
|
136
129
|
input.value = this.#committedLabel;
|
|
137
130
|
this.#syncSelection(false);
|
|
138
|
-
const control = input.closest('[data-slot~="
|
|
131
|
+
const control = input.closest('[data-combobox-slot~="control"]');
|
|
139
132
|
// A select-look control is one big hit target
|
|
140
133
|
input.addEventListener("click", () => this.#openPanel(), { signal });
|
|
141
134
|
control?.addEventListener("mousedown", (event) => {
|
|
@@ -145,7 +138,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
145
138
|
// the tag remove buttons would otherwise blur it and close the panel
|
|
146
139
|
event.preventDefault();
|
|
147
140
|
input.focus();
|
|
148
|
-
if (!event.target.closest('[data-slot~="
|
|
141
|
+
if (!event.target.closest('[data-combobox-slot~="trigger"], [data-combobox-slot~="tag"]')) {
|
|
149
142
|
this.#openPanel();
|
|
150
143
|
}
|
|
151
144
|
}, { signal });
|
|
@@ -153,17 +146,19 @@ class UiCombobox extends TypeaheadElement {
|
|
|
153
146
|
control?.addEventListener("click", (event) => {
|
|
154
147
|
if (!(event.target instanceof Element))
|
|
155
148
|
return;
|
|
156
|
-
const remove = event.target.closest('[data-slot~="
|
|
149
|
+
const remove = event.target.closest('[data-combobox-slot~="tag-remove"]');
|
|
157
150
|
if (!remove)
|
|
158
151
|
return;
|
|
159
152
|
// A template that forgets type="button" would otherwise submit the form
|
|
160
153
|
event.preventDefault();
|
|
161
|
-
const value = remove
|
|
154
|
+
const value = remove
|
|
155
|
+
.closest('[data-combobox-slot~="tag"]')
|
|
156
|
+
?.getAttribute("data-combobox-value");
|
|
162
157
|
this.#deselect(this.items().find((item) => this.#itemFormValue(item) === value));
|
|
163
158
|
input.focus();
|
|
164
159
|
}, { signal });
|
|
165
160
|
// Chevron toggles the full, unfiltered list
|
|
166
|
-
const trigger = this.querySelector('[data-slot~="
|
|
161
|
+
const trigger = this.querySelector('[data-combobox-slot~="trigger"]');
|
|
167
162
|
if (trigger instanceof HTMLElement) {
|
|
168
163
|
trigger.addEventListener("click", () => {
|
|
169
164
|
if (this.open.get())
|
|
@@ -202,7 +197,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
202
197
|
(hidden ?? input).form?.addEventListener("reset", () => queueMicrotask(() => this.#restoreDefaults()), { signal });
|
|
203
198
|
}
|
|
204
199
|
teardown() {
|
|
205
|
-
for (const node of this.querySelectorAll('[data-slot~="
|
|
200
|
+
for (const node of this.querySelectorAll('[data-combobox-slot~="tag"], [data-combobox-state~="stamped"]')) {
|
|
206
201
|
node.remove();
|
|
207
202
|
}
|
|
208
203
|
if (this.searchInput)
|
|
@@ -210,7 +205,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
210
205
|
}
|
|
211
206
|
/**
|
|
212
207
|
* @description Combobox items match against what the user sees (the label)
|
|
213
|
-
* not the machine `data-value`.
|
|
208
|
+
* not the machine `data-combobox-value`.
|
|
214
209
|
*
|
|
215
210
|
* @param item - The item element.
|
|
216
211
|
* @returns The trimmed visible label.
|
|
@@ -231,7 +226,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
231
226
|
this.query.set("");
|
|
232
227
|
}
|
|
233
228
|
/**
|
|
234
|
-
* @description Committing shows the item's label, stores its `data-value` in
|
|
229
|
+
* @description Committing shows the item's label, stores its `data-combobox-value` in
|
|
235
230
|
* the hidden input, and moves `aria-selected`. The multiselect variant
|
|
236
231
|
* toggles the row instead and keeps the panel open so picking can continue.
|
|
237
232
|
*
|
|
@@ -274,11 +269,11 @@ class UiCombobox extends TypeaheadElement {
|
|
|
274
269
|
/**
|
|
275
270
|
* @description Whether the multiselect variant is active.
|
|
276
271
|
*
|
|
277
|
-
* @returns True for `data-variant="multiselect"`.
|
|
272
|
+
* @returns True for `data-combobox-variant="multiselect"`.
|
|
278
273
|
* @private
|
|
279
274
|
*/
|
|
280
275
|
#multiselect() {
|
|
281
|
-
return this.
|
|
276
|
+
return this.config("variant") === "multiselect";
|
|
282
277
|
}
|
|
283
278
|
/**
|
|
284
279
|
* @description Opens the panel the way a select does: the full list, the
|
|
@@ -330,11 +325,11 @@ class UiCombobox extends TypeaheadElement {
|
|
|
330
325
|
* @description An item's machine value.
|
|
331
326
|
*
|
|
332
327
|
* @param item - The item element.
|
|
333
|
-
* @returns `data-value` when present, the visible label otherwise.
|
|
328
|
+
* @returns `data-combobox-value` when present, the visible label otherwise.
|
|
334
329
|
* @private
|
|
335
330
|
*/
|
|
336
331
|
#itemFormValue(item) {
|
|
337
|
-
return item.getAttribute("data-value") ?? this.itemValue(item);
|
|
332
|
+
return item.getAttribute("data-combobox-value") ?? this.itemValue(item);
|
|
338
333
|
}
|
|
339
334
|
/**
|
|
340
335
|
* @description Drops one item from the selection.
|
|
@@ -356,7 +351,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
356
351
|
* @private
|
|
357
352
|
*/
|
|
358
353
|
#valueInput() {
|
|
359
|
-
const hidden = this.querySelector('[data-slot~="
|
|
354
|
+
const hidden = this.querySelector('[data-combobox-slot~="value"]:not([data-combobox-state~="stamped"])');
|
|
360
355
|
return hidden instanceof HTMLInputElement ? hidden : null;
|
|
361
356
|
}
|
|
362
357
|
/**
|
|
@@ -382,14 +377,14 @@ class UiCombobox extends TypeaheadElement {
|
|
|
382
377
|
if (!hidden)
|
|
383
378
|
return;
|
|
384
379
|
hidden.value = values[0] ?? "";
|
|
385
|
-
for (const stale of this.querySelectorAll(
|
|
380
|
+
for (const stale of this.querySelectorAll('[data-combobox-state~="stamped"]'))
|
|
386
381
|
stale.remove();
|
|
387
382
|
let anchor = hidden;
|
|
388
383
|
for (const value of values.slice(1)) {
|
|
389
384
|
const extra = document.createElement("input");
|
|
390
385
|
extra.type = "hidden";
|
|
391
|
-
extra.setAttribute("data-slot", "
|
|
392
|
-
extra.setAttribute("data-combobox-
|
|
386
|
+
extra.setAttribute("data-combobox-slot", "value");
|
|
387
|
+
extra.setAttribute("data-combobox-state", "stamped");
|
|
393
388
|
if (hidden.name)
|
|
394
389
|
extra.name = hidden.name;
|
|
395
390
|
extra.value = value;
|
|
@@ -401,16 +396,16 @@ class UiCombobox extends TypeaheadElement {
|
|
|
401
396
|
}
|
|
402
397
|
/**
|
|
403
398
|
* @description The element cloned per selected value: the first child of an
|
|
404
|
-
* authored `<template data-slot="
|
|
405
|
-
* default
|
|
406
|
-
* fragment, so a blueprint carrying `data-slot="
|
|
399
|
+
* authored `<template data-combobox-slot="tag-template">` when present, the
|
|
400
|
+
* default badge otherwise. A template's content lives in a separate
|
|
401
|
+
* fragment, so a blueprint carrying `data-combobox-slot="tag"` is invisible to
|
|
407
402
|
* the stale-tag sweep and can never be mistaken for a rendered tag.
|
|
408
403
|
*
|
|
409
404
|
* @returns The blueprint element, or null when an authored template is empty.
|
|
410
405
|
* @private
|
|
411
406
|
*/
|
|
412
407
|
#tagBlueprint() {
|
|
413
|
-
const authored = this.querySelector('[data-slot~="
|
|
408
|
+
const authored = this.querySelector('[data-combobox-slot~="tag-template"]');
|
|
414
409
|
const template = authored instanceof HTMLTemplateElement ? authored : defaultTagBlueprint();
|
|
415
410
|
const root = template.content.firstElementChild;
|
|
416
411
|
return root instanceof HTMLElement ? root : null;
|
|
@@ -424,35 +419,35 @@ class UiCombobox extends TypeaheadElement {
|
|
|
424
419
|
* @private
|
|
425
420
|
*/
|
|
426
421
|
#renderTags(input) {
|
|
427
|
-
const control = input.closest('[data-slot~="
|
|
422
|
+
const control = input.closest('[data-combobox-slot~="control"]');
|
|
428
423
|
if (!control)
|
|
429
424
|
return;
|
|
430
|
-
for (const stale of control.querySelectorAll('[data-slot~="
|
|
425
|
+
for (const stale of control.querySelectorAll('[data-combobox-slot~="tag"]'))
|
|
431
426
|
stale.remove();
|
|
432
427
|
const blueprint = this.#tagBlueprint();
|
|
433
428
|
if (!blueprint)
|
|
434
429
|
return;
|
|
435
|
-
const removeLabel = this.
|
|
430
|
+
const removeLabel = this.config("label-remove") ?? "Remove {label}";
|
|
436
431
|
const tags = this.#selectedItems().map((item) => {
|
|
437
432
|
const label = this.itemValue(item);
|
|
438
433
|
const tag = blueprint.cloneNode(true);
|
|
439
|
-
tag.setAttribute("data-value", this.#itemFormValue(item));
|
|
434
|
+
tag.setAttribute("data-combobox-value", this.#itemFormValue(item));
|
|
440
435
|
// The slot is the contract every other moving part keys off (the CSS, the
|
|
441
436
|
// stale sweep above, and tag removal), so add the token if the template
|
|
442
437
|
// left it out rather than stamping an orphan
|
|
443
|
-
if (!tag.matches('[data-slot~="
|
|
444
|
-
const slots = tag.getAttribute("data-slot");
|
|
445
|
-
tag.setAttribute("data-slot", slots ? `${slots}
|
|
438
|
+
if (!tag.matches('[data-combobox-slot~="tag"]')) {
|
|
439
|
+
const slots = tag.getAttribute("data-combobox-slot");
|
|
440
|
+
tag.setAttribute("data-combobox-slot", slots ? `${slots} tag` : "tag");
|
|
446
441
|
}
|
|
447
442
|
// The label wants its own box: text-overflow ignores a flex container's
|
|
448
443
|
// own text, but a template without one still gets its text
|
|
449
|
-
const text = tag.querySelector('[data-slot~="
|
|
444
|
+
const text = tag.querySelector('[data-combobox-slot~="tag-label"]');
|
|
450
445
|
if (text)
|
|
451
446
|
text.textContent = label;
|
|
452
447
|
else
|
|
453
448
|
tag.prepend(document.createTextNode(label));
|
|
454
449
|
tag
|
|
455
|
-
.querySelector('[data-slot~="
|
|
450
|
+
.querySelector('[data-combobox-slot~="tag-remove"]')
|
|
456
451
|
?.setAttribute("aria-label", resolveRemoveLabel(removeLabel, label));
|
|
457
452
|
return tag;
|
|
458
453
|
});
|
|
@@ -5,34 +5,35 @@
|
|
|
5
5
|
* @description Light-DOM custom element on the shared typeahead engine
|
|
6
6
|
* (`base/typeahead.ts`). A relative of select: the panel filters as you type,
|
|
7
7
|
* but free text can never submit. The form value lives in an authored hidden
|
|
8
|
-
* input (`data-slot="
|
|
8
|
+
* input (`data-combobox-slot="value"`), synced whenever the selection changes.
|
|
9
9
|
*
|
|
10
10
|
* The visible input carries a **display value, not the filter**. Committing
|
|
11
11
|
* writes the option label into it and clears the query, so reopening shows
|
|
12
|
-
* the full list with the committed row checked, matching
|
|
12
|
+
* the full list with the committed row checked, matching `[data-ui~="select"]`.
|
|
13
13
|
* Opening selects that label so the first keystroke replaces it, and focus
|
|
14
14
|
* alone never opens the panel (a click, the chevron, an arrow key or typing
|
|
15
15
|
* does). On blur, stray text reverts to the committed label and cleared text
|
|
16
16
|
* clears the selection.
|
|
17
17
|
*
|
|
18
|
-
* `data-variant="multiselect"` selects a set instead: committing toggles a row
|
|
18
|
+
* `data-combobox-variant="multiselect"` selects a set instead: committing toggles a row
|
|
19
19
|
* and keeps the panel open, and every selected value renders as a removable
|
|
20
20
|
* tag stamped inside the control. The tag markup is HTML, not script: author
|
|
21
|
-
* a `<template data-slot="
|
|
21
|
+
* a `<template data-combobox-slot="tag-template">` to control its classes and
|
|
22
22
|
* structure, and this file fills in the label, the value, and the remove
|
|
23
|
-
* button accessible name. Without one, the
|
|
23
|
+
* button accessible name. Without one, the badge default below applies.
|
|
24
24
|
* Backspace on an empty input drops the last tag. Options carrying
|
|
25
25
|
* `aria-selected="true"` are the single source of truth: the tags and the
|
|
26
26
|
* hidden inputs are both derived from them in DOM order so nothing can drift.
|
|
27
27
|
* The form submits repeated `name` pairs like `<select multiple>`: the authored
|
|
28
28
|
* hidden input carries the first value, and stamped siblings carry the rest.
|
|
29
29
|
*
|
|
30
|
-
* Where a no-JS fallback matters, prefer
|
|
30
|
+
* Where a no-JS fallback matters, prefer `[data-ui~="select"]` / `<ui-multiselect>`:
|
|
31
31
|
* this control is inert without its script (the hidden input still submits a
|
|
32
32
|
* server-set value, but no tags render).
|
|
33
33
|
*
|
|
34
|
-
* Attributes on the root: `data-variant="multiselect"`, `data-sort="score"`,
|
|
35
|
-
* `data-
|
|
34
|
+
* Attributes on the root: `data-combobox-variant="multiselect"`, `data-combobox-sort="score"`,
|
|
35
|
+
* `data-combobox-filter="none"` (another source filters; the engine only navigates),
|
|
36
|
+
* `data-combobox-min-length="<n>"`, `data-combobox-label-remove="Remove {label}"`.
|
|
36
37
|
* Parts: `combobox-value` (hidden input), `combobox-control` (select-look
|
|
37
38
|
* shell), `combobox-tag-template` (authored `<template>`), `combobox-tag` /
|
|
38
39
|
* `combobox-tag-label` / `combobox-tag-remove` (cloned from it),
|
|
@@ -43,19 +44,11 @@
|
|
|
43
44
|
import { TypeaheadElement } from "../../base/typeahead.ts";
|
|
44
45
|
import { defineZazzElement } from "../../base/zazz-element.ts";
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The default tag markup, cloned once per selected value. Authors override it
|
|
50
|
-
* wholesale with a `<template data-slot="combobox-tag-template">`, so restyling
|
|
51
|
-
* a tag (other classes, an extra icon, a different component entirely) never
|
|
52
|
-
* means editing this script. Kept as markup rather than createElement calls so
|
|
53
|
-
* the default reads the same way the override is written.
|
|
54
|
-
*/
|
|
47
|
+
/** Default tag markup, cloned per selected value; a `tag-template` overrides it. */
|
|
55
48
|
const TAG_MARKUP =
|
|
56
|
-
'<span
|
|
57
|
-
'<span data-slot="
|
|
58
|
-
'<button type="button" tabindex="-1" data-slot="
|
|
49
|
+
'<span data-ui="badge" data-combobox-slot="tag">' +
|
|
50
|
+
'<span data-combobox-slot="tag-label"></span>' +
|
|
51
|
+
'<button type="button" tabindex="-1" data-combobox-slot="tag-remove"></button>' +
|
|
59
52
|
"</span>";
|
|
60
53
|
|
|
61
54
|
let defaultTagTemplate: HTMLTemplateElement | null = null;
|
|
@@ -74,8 +67,6 @@ function defaultTagBlueprint(): HTMLTemplateElement {
|
|
|
74
67
|
return defaultTagTemplate;
|
|
75
68
|
}
|
|
76
69
|
|
|
77
|
-
// --- Pure derivations ---
|
|
78
|
-
|
|
79
70
|
/** What a blur does to the input's text and to the committed selection. */
|
|
80
71
|
interface BlurOutcome {
|
|
81
72
|
/** The text the input shows once focus has left. */
|
|
@@ -102,7 +93,7 @@ function resolveBlur(typed: string, committedLabel: string, multiselect: boolean
|
|
|
102
93
|
}
|
|
103
94
|
|
|
104
95
|
/**
|
|
105
|
-
* @description Fills the remove-button label template (`data-label-remove`).
|
|
96
|
+
* @description Fills the remove-button label template (`data-combobox-label-remove`).
|
|
106
97
|
*
|
|
107
98
|
* @param template - Template with a `{label}` placeholder.
|
|
108
99
|
* @param label - The tag's visible label.
|
|
@@ -112,8 +103,6 @@ function resolveRemoveLabel(template: string, label: string): string {
|
|
|
112
103
|
return template.replace("{label}", label);
|
|
113
104
|
}
|
|
114
105
|
|
|
115
|
-
// --- Element ---
|
|
116
|
-
|
|
117
106
|
class UiCombobox extends TypeaheadElement {
|
|
118
107
|
protected readonly slotPrefix = "combobox";
|
|
119
108
|
/** The input holds a committed label, so focus alone must not open the list. */
|
|
@@ -132,7 +121,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
132
121
|
this.#placeholder = input.getAttribute("placeholder") ?? "";
|
|
133
122
|
|
|
134
123
|
if (multiselect) {
|
|
135
|
-
this.querySelector('[data-slot~="
|
|
124
|
+
this.querySelector('[data-combobox-slot~="list"]')?.setAttribute(
|
|
136
125
|
"aria-multiselectable",
|
|
137
126
|
"true",
|
|
138
127
|
);
|
|
@@ -163,7 +152,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
163
152
|
input.value = this.#committedLabel;
|
|
164
153
|
this.#syncSelection(false);
|
|
165
154
|
|
|
166
|
-
const control = input.closest<HTMLElement>('[data-slot~="
|
|
155
|
+
const control = input.closest<HTMLElement>('[data-combobox-slot~="control"]');
|
|
167
156
|
|
|
168
157
|
// A select-look control is one big hit target
|
|
169
158
|
input.addEventListener("click", () => this.#openPanel(), { signal });
|
|
@@ -176,7 +165,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
176
165
|
// the tag remove buttons would otherwise blur it and close the panel
|
|
177
166
|
event.preventDefault();
|
|
178
167
|
input.focus();
|
|
179
|
-
if (!event.target.closest('[data-slot~="
|
|
168
|
+
if (!event.target.closest('[data-combobox-slot~="trigger"], [data-combobox-slot~="tag"]')) {
|
|
180
169
|
this.#openPanel();
|
|
181
170
|
}
|
|
182
171
|
},
|
|
@@ -188,11 +177,13 @@ class UiCombobox extends TypeaheadElement {
|
|
|
188
177
|
"click",
|
|
189
178
|
(event) => {
|
|
190
179
|
if (!(event.target instanceof Element)) return;
|
|
191
|
-
const remove = event.target.closest('[data-slot~="
|
|
180
|
+
const remove = event.target.closest('[data-combobox-slot~="tag-remove"]');
|
|
192
181
|
if (!remove) return;
|
|
193
182
|
// A template that forgets type="button" would otherwise submit the form
|
|
194
183
|
event.preventDefault();
|
|
195
|
-
const value = remove
|
|
184
|
+
const value = remove
|
|
185
|
+
.closest('[data-combobox-slot~="tag"]')
|
|
186
|
+
?.getAttribute("data-combobox-value");
|
|
196
187
|
this.#deselect(this.items().find((item) => this.#itemFormValue(item) === value));
|
|
197
188
|
input.focus();
|
|
198
189
|
},
|
|
@@ -200,7 +191,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
200
191
|
);
|
|
201
192
|
|
|
202
193
|
// Chevron toggles the full, unfiltered list
|
|
203
|
-
const trigger = this.querySelector('[data-slot~="
|
|
194
|
+
const trigger = this.querySelector('[data-combobox-slot~="trigger"]');
|
|
204
195
|
if (trigger instanceof HTMLElement) {
|
|
205
196
|
trigger.addEventListener(
|
|
206
197
|
"click",
|
|
@@ -254,7 +245,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
254
245
|
|
|
255
246
|
protected teardown(): void {
|
|
256
247
|
for (const node of this.querySelectorAll(
|
|
257
|
-
'[data-slot~="
|
|
248
|
+
'[data-combobox-slot~="tag"], [data-combobox-state~="stamped"]',
|
|
258
249
|
)) {
|
|
259
250
|
node.remove();
|
|
260
251
|
}
|
|
@@ -263,7 +254,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
263
254
|
|
|
264
255
|
/**
|
|
265
256
|
* @description Combobox items match against what the user sees (the label)
|
|
266
|
-
* not the machine `data-value`.
|
|
257
|
+
* not the machine `data-combobox-value`.
|
|
267
258
|
*
|
|
268
259
|
* @param item - The item element.
|
|
269
260
|
* @returns The trimmed visible label.
|
|
@@ -285,7 +276,7 @@ class UiCombobox extends TypeaheadElement {
|
|
|
285
276
|
}
|
|
286
277
|
|
|
287
278
|
/**
|
|
288
|
-
* @description Committing shows the item's label, stores its `data-value` in
|
|
279
|
+
* @description Committing shows the item's label, stores its `data-combobox-value` in
|
|
289
280
|
* the hidden input, and moves `aria-selected`. The multiselect variant
|
|
290
281
|
* toggles the row instead and keeps the panel open so picking can continue.
|
|
291
282
|
*
|
|
@@ -327,11 +318,11 @@ class UiCombobox extends TypeaheadElement {
|
|
|
327
318
|
/**
|
|
328
319
|
* @description Whether the multiselect variant is active.
|
|
329
320
|
*
|
|
330
|
-
* @returns True for `data-variant="multiselect"`.
|
|
321
|
+
* @returns True for `data-combobox-variant="multiselect"`.
|
|
331
322
|
* @private
|
|
332
323
|
*/
|
|
333
324
|
#multiselect(): boolean {
|
|
334
|
-
return this.
|
|
325
|
+
return this.config("variant") === "multiselect";
|
|
335
326
|
}
|
|
336
327
|
|
|
337
328
|
/**
|
|
@@ -384,11 +375,11 @@ class UiCombobox extends TypeaheadElement {
|
|
|
384
375
|
* @description An item's machine value.
|
|
385
376
|
*
|
|
386
377
|
* @param item - The item element.
|
|
387
|
-
* @returns `data-value` when present, the visible label otherwise.
|
|
378
|
+
* @returns `data-combobox-value` when present, the visible label otherwise.
|
|
388
379
|
* @private
|
|
389
380
|
*/
|
|
390
381
|
#itemFormValue(item: HTMLElement): string {
|
|
391
|
-
return item.getAttribute("data-value") ?? this.itemValue(item);
|
|
382
|
+
return item.getAttribute("data-combobox-value") ?? this.itemValue(item);
|
|
392
383
|
}
|
|
393
384
|
|
|
394
385
|
/**
|
|
@@ -411,7 +402,9 @@ class UiCombobox extends TypeaheadElement {
|
|
|
411
402
|
* @private
|
|
412
403
|
*/
|
|
413
404
|
#valueInput(): HTMLInputElement | null {
|
|
414
|
-
const hidden = this.querySelector(
|
|
405
|
+
const hidden = this.querySelector(
|
|
406
|
+
'[data-combobox-slot~="value"]:not([data-combobox-state~="stamped"])',
|
|
407
|
+
);
|
|
415
408
|
return hidden instanceof HTMLInputElement ? hidden : null;
|
|
416
409
|
}
|
|
417
410
|
|
|
@@ -438,13 +431,13 @@ class UiCombobox extends TypeaheadElement {
|
|
|
438
431
|
const hidden = this.#valueInput();
|
|
439
432
|
if (!hidden) return;
|
|
440
433
|
hidden.value = values[0] ?? "";
|
|
441
|
-
for (const stale of this.querySelectorAll(
|
|
434
|
+
for (const stale of this.querySelectorAll('[data-combobox-state~="stamped"]')) stale.remove();
|
|
442
435
|
let anchor: Element = hidden;
|
|
443
436
|
for (const value of values.slice(1)) {
|
|
444
437
|
const extra = document.createElement("input");
|
|
445
438
|
extra.type = "hidden";
|
|
446
|
-
extra.setAttribute("data-slot", "
|
|
447
|
-
extra.setAttribute("data-combobox-
|
|
439
|
+
extra.setAttribute("data-combobox-slot", "value");
|
|
440
|
+
extra.setAttribute("data-combobox-state", "stamped");
|
|
448
441
|
if (hidden.name) extra.name = hidden.name;
|
|
449
442
|
extra.value = value;
|
|
450
443
|
anchor.after(extra);
|
|
@@ -455,16 +448,16 @@ class UiCombobox extends TypeaheadElement {
|
|
|
455
448
|
|
|
456
449
|
/**
|
|
457
450
|
* @description The element cloned per selected value: the first child of an
|
|
458
|
-
* authored `<template data-slot="
|
|
459
|
-
* default
|
|
460
|
-
* fragment, so a blueprint carrying `data-slot="
|
|
451
|
+
* authored `<template data-combobox-slot="tag-template">` when present, the
|
|
452
|
+
* default badge otherwise. A template's content lives in a separate
|
|
453
|
+
* fragment, so a blueprint carrying `data-combobox-slot="tag"` is invisible to
|
|
461
454
|
* the stale-tag sweep and can never be mistaken for a rendered tag.
|
|
462
455
|
*
|
|
463
456
|
* @returns The blueprint element, or null when an authored template is empty.
|
|
464
457
|
* @private
|
|
465
458
|
*/
|
|
466
459
|
#tagBlueprint(): HTMLElement | null {
|
|
467
|
-
const authored = this.querySelector('[data-slot~="
|
|
460
|
+
const authored = this.querySelector('[data-combobox-slot~="tag-template"]');
|
|
468
461
|
const template = authored instanceof HTMLTemplateElement ? authored : defaultTagBlueprint();
|
|
469
462
|
const root = template.content.firstElementChild;
|
|
470
463
|
return root instanceof HTMLElement ? root : null;
|
|
@@ -479,35 +472,35 @@ class UiCombobox extends TypeaheadElement {
|
|
|
479
472
|
* @private
|
|
480
473
|
*/
|
|
481
474
|
#renderTags(input: HTMLInputElement): void {
|
|
482
|
-
const control = input.closest('[data-slot~="
|
|
475
|
+
const control = input.closest('[data-combobox-slot~="control"]');
|
|
483
476
|
if (!control) return;
|
|
484
|
-
for (const stale of control.querySelectorAll('[data-slot~="
|
|
477
|
+
for (const stale of control.querySelectorAll('[data-combobox-slot~="tag"]')) stale.remove();
|
|
485
478
|
|
|
486
479
|
const blueprint = this.#tagBlueprint();
|
|
487
480
|
if (!blueprint) return;
|
|
488
481
|
|
|
489
|
-
const removeLabel = this.
|
|
482
|
+
const removeLabel = this.config("label-remove") ?? "Remove {label}";
|
|
490
483
|
const tags = this.#selectedItems().map((item) => {
|
|
491
484
|
const label = this.itemValue(item);
|
|
492
485
|
const tag = blueprint.cloneNode(true) as HTMLElement;
|
|
493
|
-
tag.setAttribute("data-value", this.#itemFormValue(item));
|
|
486
|
+
tag.setAttribute("data-combobox-value", this.#itemFormValue(item));
|
|
494
487
|
|
|
495
488
|
// The slot is the contract every other moving part keys off (the CSS, the
|
|
496
489
|
// stale sweep above, and tag removal), so add the token if the template
|
|
497
490
|
// left it out rather than stamping an orphan
|
|
498
|
-
if (!tag.matches('[data-slot~="
|
|
499
|
-
const slots = tag.getAttribute("data-slot");
|
|
500
|
-
tag.setAttribute("data-slot", slots ? `${slots}
|
|
491
|
+
if (!tag.matches('[data-combobox-slot~="tag"]')) {
|
|
492
|
+
const slots = tag.getAttribute("data-combobox-slot");
|
|
493
|
+
tag.setAttribute("data-combobox-slot", slots ? `${slots} tag` : "tag");
|
|
501
494
|
}
|
|
502
495
|
|
|
503
496
|
// The label wants its own box: text-overflow ignores a flex container's
|
|
504
497
|
// own text, but a template without one still gets its text
|
|
505
|
-
const text = tag.querySelector('[data-slot~="
|
|
498
|
+
const text = tag.querySelector('[data-combobox-slot~="tag-label"]');
|
|
506
499
|
if (text) text.textContent = label;
|
|
507
500
|
else tag.prepend(document.createTextNode(label));
|
|
508
501
|
|
|
509
502
|
tag
|
|
510
|
-
.querySelector('[data-slot~="
|
|
503
|
+
.querySelector('[data-combobox-slot~="tag-remove"]')
|
|
511
504
|
?.setAttribute("aria-label", resolveRemoveLabel(removeLabel, label));
|
|
512
505
|
|
|
513
506
|
return tag;
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
* palette-wide concerns like analytics.
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
|
-
* @description Binds this page's custom `--command` handlers
|
|
21
|
-
*
|
|
22
|
-
* Commands contract.
|
|
20
|
+
* @description Binds this page's custom `--command` handlers on the command
|
|
21
|
+
* *target* (the `commandfor` element).
|
|
23
22
|
*/
|
|
24
23
|
declare function initCommandActions(): void;
|
|
25
24
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-actions.d.ts","sourceRoot":"","sources":["command-actions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;
|
|
1
|
+
{"version":3,"file":"command-actions.d.ts","sourceRoot":"","sources":["command-actions.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,iBAAS,kBAAkB,IAAI,IAAI,CA4BlC;AAED;;;GAGG;AACH,iBAAS,wBAAwB,IAAI,IAAI,CAKxC;AAWD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,CAAC"}
|