tyrell-components 1.0.0-TC58 → 1.0.0-TC60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +6 -5
- package/css/tyrell.css +8 -6
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +13 -12
- package/lib/base/ty-component.js +56 -21
- package/lib/components/button.d.ts +10 -0
- package/lib/components/button.js +22 -1
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +32 -18
- package/lib/components/calendar-navigation.js +19 -6
- package/lib/components/calendar.d.ts +25 -5
- package/lib/components/calendar.js +87 -37
- package/lib/components/checkbox.d.ts +5 -0
- package/lib/components/checkbox.js +18 -5
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +15 -31
- package/lib/components/date-picker.d.ts +7 -26
- package/lib/components/date-picker.js +14 -84
- package/lib/components/file-upload.js +6 -2
- package/lib/components/input.d.ts +0 -9
- package/lib/components/input.js +18 -40
- package/lib/components/modal.js +59 -18
- package/lib/components/option.d.ts +19 -0
- package/lib/components/option.js +38 -26
- package/lib/components/popup.js +56 -5
- package/lib/components/radio.d.ts +6 -0
- package/lib/components/radio.js +12 -28
- package/lib/components/select.d.ts +132 -194
- package/lib/components/select.js +436 -836
- package/lib/components/selected-tags.d.ts +8 -4
- package/lib/components/selected-tags.js +26 -8
- package/lib/components/switch.d.ts +4 -0
- package/lib/components/switch.js +18 -5
- package/lib/components/tabs.js +1 -1
- package/lib/components/textarea.d.ts +1 -0
- package/lib/components/textarea.js +21 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/styles/button.js +1 -0
- package/lib/styles/calendar-month.js +1 -1
- package/lib/styles/calendar.js +3 -0
- package/lib/styles/checkbox.js +11 -5
- package/lib/styles/date-picker.js +5 -10
- package/lib/styles/input.js +5 -9
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +6 -7
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +2 -0
- package/lib/styles/radio.js +10 -4
- package/lib/styles/select-base.js +6 -70
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +13 -2
- package/lib/styles/switch.js +10 -5
- package/lib/styles/tag.js +2 -1
- package/lib/types/common.d.ts +3 -1
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +0 -5
- package/lib/utils/property-manager.js +0 -11
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/validity.d.ts +27 -1
- package/lib/utils/validity.js +68 -16
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/dist/tyrell.js.map +0 -1
- package/lib/utils/error-flavor.d.ts +0 -8
- package/lib/utils/error-flavor.js +0 -1
package/lib/components/select.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_SIZE } from "../types/common.js";
|
|
2
2
|
import { ensureStyles } from "../utils/styles.js";
|
|
3
3
|
import { syncCustomFlavorSheet } from "../utils/flavor-sheet.js";
|
|
4
|
-
import { ERROR_FLAVOR } from "../utils/error-flavor.js";
|
|
5
4
|
import { selectBaseStyles, selectCustomFlavorCss } from "../styles/select-base.js";
|
|
6
5
|
import { selectStyles } from "../styles/select.js";
|
|
7
6
|
import { getLoaderSvg } from "../utils/loader-registry.js";
|
|
@@ -10,18 +9,9 @@ import { computeAnchoredPosition, placementToAnchored } from "../utils/positioni
|
|
|
10
9
|
import { isMobileTouch } from "../utils/mobile.js";
|
|
11
10
|
import { TyComponent } from "../base/ty-component.js";
|
|
12
11
|
import { CustomScrollbar, isCustomScrollbarEnabled, } from "../utils/custom-scrollbar.js";
|
|
13
|
-
let elementIdCounter = 0;
|
|
14
|
-
const elementIds = new WeakMap();
|
|
15
|
-
function getElementHash(element) {
|
|
16
|
-
let id = elementIds.get(element);
|
|
17
|
-
if (id === undefined) {
|
|
18
|
-
id = ++elementIdCounter;
|
|
19
|
-
elementIds.set(element, id);
|
|
20
|
-
}
|
|
21
|
-
return id;
|
|
22
|
-
}
|
|
23
12
|
import { REQUIRED_ICON_SVG } from "../utils/icons.js";
|
|
24
13
|
import { nativeMessage } from "../utils/validity.js";
|
|
14
|
+
let selectCount = 0;
|
|
25
15
|
const SEARCH_AUTO_THRESHOLD = 7;
|
|
26
16
|
const CHEVRON_DOWN_SVG = `<svg viewBox="0 0 20 20" fill="currentColor">
|
|
27
17
|
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
|
@@ -42,120 +32,69 @@ const CLEAR_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColo
|
|
|
42
32
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
43
33
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
44
34
|
</svg>`;
|
|
35
|
+
function assign(slot, nodes) {
|
|
36
|
+
if (!slot)
|
|
37
|
+
return;
|
|
38
|
+
const current = slot.assignedNodes();
|
|
39
|
+
if (current.length === nodes.length && nodes.every((n, i) => current[i] === n))
|
|
40
|
+
return;
|
|
41
|
+
slot.assign(...nodes);
|
|
42
|
+
}
|
|
43
|
+
const NAMED_SLOTS = ["trigger", "start", "end", "loading"];
|
|
44
|
+
function isMarked(el) {
|
|
45
|
+
const attr = el.getAttribute("selected");
|
|
46
|
+
return attr !== null && !/^(false|0)$/i.test(attr.trim());
|
|
47
|
+
}
|
|
45
48
|
export class TySelect extends TyComponent {
|
|
46
49
|
constructor() {
|
|
47
50
|
super();
|
|
48
|
-
this.
|
|
49
|
-
this._multiple = false;
|
|
50
|
-
this._compact = false;
|
|
51
|
-
this._placeholder = "Select...";
|
|
52
|
-
this._label = "";
|
|
53
|
-
this._disabled = false;
|
|
54
|
-
this._readonly = false;
|
|
55
|
-
this._required = false;
|
|
56
|
-
this._clearable = true;
|
|
57
|
-
this._externalSearch = false;
|
|
58
|
-
this._allowCreate = false;
|
|
59
|
-
this._createTransform = "none";
|
|
60
|
-
this._notSearchable = false;
|
|
61
|
-
this._loading = false;
|
|
62
|
-
this._scrollLockId = null;
|
|
63
|
-
this._size = DEFAULT_SIZE;
|
|
64
|
-
this._availableLabel = "Available";
|
|
65
|
-
this._selectedLabel = "Selected";
|
|
66
|
-
this._noOptionsMessage = "No options available";
|
|
51
|
+
this._uid = ++selectCount;
|
|
67
52
|
this._state = {
|
|
68
53
|
open: false,
|
|
69
54
|
search: "",
|
|
70
55
|
highlightedIndex: -1,
|
|
71
56
|
filteredTags: [],
|
|
72
|
-
selectedValues: [],
|
|
73
57
|
mode: "desktop",
|
|
74
58
|
};
|
|
75
|
-
this.
|
|
76
|
-
this._tagClickHandler = null;
|
|
77
|
-
this._searchInputHandler = null;
|
|
78
|
-
this._blockSearchClick = null;
|
|
59
|
+
this._scrollLockId = null;
|
|
79
60
|
this._keyboardHandler = null;
|
|
80
|
-
this._debounce = 0;
|
|
81
61
|
this._searchDebounceTimer = null;
|
|
82
62
|
this._optionsScrollbar = null;
|
|
83
63
|
this._childObserver = null;
|
|
84
|
-
this._selectedClone = null;
|
|
85
64
|
this._customFlavorSheet = null;
|
|
86
65
|
this._ariaTrigger = null;
|
|
66
|
+
this._ariaObserver = null;
|
|
87
67
|
const shadow = this.shadowRoot;
|
|
88
68
|
ensureStyles(shadow, { css: selectBaseStyles, id: "ty-select-base" });
|
|
89
69
|
ensureStyles(shadow, { css: selectStyles, id: "ty-select" });
|
|
90
70
|
}
|
|
91
71
|
onConnect() {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
dialogs.forEach((dialog) => {
|
|
95
|
-
if (dialog.open) {
|
|
96
|
-
console.warn("⚠️ Found open dialog on connect, closing it");
|
|
97
|
-
dialog.close();
|
|
98
|
-
}
|
|
99
|
-
});
|
|
72
|
+
this._childObserver = new MutationObserver((records) => {
|
|
73
|
+
if (records.some((r) => r.target !== this || r.type !== "attributes" || r.attributeName === "has-trigger")) {
|
|
100
74
|
this.render();
|
|
101
|
-
this.initializeState();
|
|
102
|
-
this.updateFormValue();
|
|
103
|
-
this._childObserver = new MutationObserver(() => {
|
|
104
|
-
this.ensureOptionRoles();
|
|
105
|
-
if (this._state.selectedValues.length > 0) {
|
|
106
|
-
this.syncSelectedTags(this._state.selectedValues);
|
|
107
75
|
}
|
|
108
|
-
this.updateSearchVisibility();
|
|
109
|
-
this.updateSelectionDisplay();
|
|
110
|
-
this.updateMobileSelectedState();
|
|
111
76
|
});
|
|
112
|
-
this._childObserver.observe(this, {
|
|
113
|
-
|
|
77
|
+
this._childObserver.observe(this, {
|
|
78
|
+
childList: true,
|
|
79
|
+
subtree: true,
|
|
80
|
+
characterData: true,
|
|
81
|
+
attributes: true,
|
|
82
|
+
attributeFilter: ["value", "label", "selected", "hidden", "filtered-out", "has-trigger"],
|
|
83
|
+
});
|
|
114
84
|
this._syncCustomFlavor();
|
|
115
|
-
this.syncErrorFlavor();
|
|
116
85
|
if (!this._keyboardHandler) {
|
|
117
86
|
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
118
87
|
document.addEventListener("keydown", this._keyboardHandler, true);
|
|
119
88
|
}
|
|
89
|
+
if (this._rendered)
|
|
90
|
+
this.render();
|
|
120
91
|
}
|
|
121
92
|
_syncCustomFlavor() {
|
|
122
93
|
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.getProperty("flavor"), ({ base }) => selectCustomFlavorCss(base));
|
|
123
94
|
}
|
|
124
|
-
syncErrorFlavor() {
|
|
125
|
-
if (!this._connected)
|
|
126
|
-
return;
|
|
127
|
-
const flavor = this.getProperty("flavor");
|
|
128
|
-
const replaced = this.getAttribute(ERROR_FLAVOR);
|
|
129
|
-
if (this.getProperty("error")) {
|
|
130
|
-
if (replaced === null && flavor === "neutral") {
|
|
131
|
-
this.setAttribute(ERROR_FLAVOR, this.getAttribute("flavor") ?? "");
|
|
132
|
-
this.setProperty("flavor", "danger");
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else if (replaced !== null) {
|
|
136
|
-
this.removeAttribute(ERROR_FLAVOR);
|
|
137
|
-
if (flavor !== "danger")
|
|
138
|
-
return;
|
|
139
|
-
if (!replaced)
|
|
140
|
-
this.removeAttribute("flavor");
|
|
141
|
-
else
|
|
142
|
-
this.setProperty("flavor", replaced);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
95
|
onDisconnect() {
|
|
146
|
-
if (this._state.open)
|
|
147
|
-
|
|
148
|
-
this.closeMobileModal();
|
|
149
|
-
else
|
|
150
|
-
this.closeDropdown();
|
|
151
|
-
}
|
|
152
|
-
const shadow = this.shadowRoot;
|
|
153
|
-
const dialogs = shadow.querySelectorAll("dialog");
|
|
154
|
-
dialogs.forEach((dialog) => {
|
|
155
|
-
if (dialog.open) {
|
|
156
|
-
dialog.close();
|
|
157
|
-
}
|
|
158
|
-
});
|
|
96
|
+
if (this._state.open)
|
|
97
|
+
this.close();
|
|
159
98
|
if (this._keyboardHandler) {
|
|
160
99
|
document.removeEventListener("keydown", this._keyboardHandler, true);
|
|
161
100
|
this._keyboardHandler = null;
|
|
@@ -165,113 +104,31 @@ clearTimeout(this._searchDebounceTimer);
|
|
|
165
104
|
this._searchDebounceTimer = null;
|
|
166
105
|
}
|
|
167
106
|
this._destroyOptionsScrollbar();
|
|
168
|
-
|
|
169
|
-
this._childObserver.disconnect();
|
|
107
|
+
this._childObserver?.disconnect();
|
|
170
108
|
this._childObserver = null;
|
|
171
109
|
}
|
|
172
|
-
}
|
|
173
110
|
onPropertiesChanged(changes) {
|
|
174
111
|
for (const { name, newValue } of changes) {
|
|
175
112
|
switch (name) {
|
|
176
|
-
case "value":
|
|
177
|
-
const selectedValues = this.parseValue(newValue);
|
|
178
|
-
this._state.selectedValues = selectedValues;
|
|
179
|
-
if (this.isConnected && this.shadowRoot) {
|
|
180
|
-
this.syncSelectedTags(selectedValues);
|
|
181
|
-
this.updateSelectionDisplay();
|
|
182
|
-
this.updateMobileSelectedState();
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
case "name":
|
|
186
|
-
this._name = newValue || "";
|
|
187
|
-
break;
|
|
188
113
|
case "flavor":
|
|
189
|
-
if (newValue !== "danger") {
|
|
190
|
-
this.removeAttribute(ERROR_FLAVOR);
|
|
191
|
-
this.syncErrorFlavor();
|
|
192
|
-
}
|
|
193
114
|
this._syncCustomFlavor();
|
|
194
115
|
break;
|
|
195
|
-
case "
|
|
196
|
-
this.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
this._multiple = newValue;
|
|
200
|
-
if (!newValue && this._state.selectedValues.length > 1) {
|
|
201
|
-
this.updateComponentValue([this._state.selectedValues[0]], false, "set", null);
|
|
116
|
+
case "multiple": {
|
|
117
|
+
const values = this.getSelectedValues();
|
|
118
|
+
if (!newValue && values.length > 1) {
|
|
119
|
+
this.updateComponentValue([values[0]]);
|
|
202
120
|
}
|
|
203
121
|
break;
|
|
204
|
-
|
|
205
|
-
this._compact = newValue;
|
|
206
|
-
break;
|
|
207
|
-
case "placeholder":
|
|
208
|
-
this._placeholder = newValue || "Select...";
|
|
209
|
-
if (this.isConnected && this.shadowRoot)
|
|
210
|
-
this.updateSelectionDisplay();
|
|
211
|
-
break;
|
|
212
|
-
case "label":
|
|
213
|
-
this._label = newValue || "";
|
|
214
|
-
break;
|
|
215
|
-
case "disabled":
|
|
216
|
-
this._disabled = newValue;
|
|
217
|
-
break;
|
|
218
|
-
case "readonly":
|
|
219
|
-
this._readonly = newValue;
|
|
220
|
-
break;
|
|
221
|
-
case "required":
|
|
222
|
-
this._required = newValue;
|
|
223
|
-
break;
|
|
224
|
-
case "noClear":
|
|
225
|
-
this._clearable = !newValue;
|
|
226
|
-
if (this.isConnected && this.shadowRoot)
|
|
227
|
-
this.updateSelectionDisplay();
|
|
228
|
-
break;
|
|
229
|
-
case "externalSearch":
|
|
230
|
-
this._externalSearch = newValue;
|
|
231
|
-
break;
|
|
232
|
-
case "notSearchable":
|
|
233
|
-
this._notSearchable = newValue;
|
|
234
|
-
if (this.isConnected && this.shadowRoot)
|
|
235
|
-
this.updateSearchVisibility();
|
|
236
|
-
break;
|
|
237
|
-
case "allowCreate":
|
|
238
|
-
this._allowCreate = newValue;
|
|
239
|
-
if (this.isConnected && this.shadowRoot)
|
|
240
|
-
this.updateSearchVisibility();
|
|
241
|
-
break;
|
|
242
|
-
case "createTransform":
|
|
243
|
-
this._createTransform = newValue;
|
|
244
|
-
break;
|
|
245
|
-
case "size":
|
|
246
|
-
this._size = newValue;
|
|
247
|
-
break;
|
|
248
|
-
case "debounce":
|
|
249
|
-
this._debounce = newValue;
|
|
250
|
-
break;
|
|
251
|
-
case "available-label":
|
|
252
|
-
this._availableLabel = newValue || "Available";
|
|
253
|
-
break;
|
|
254
|
-
case "selected-label":
|
|
255
|
-
this._selectedLabel = newValue || "Selected";
|
|
256
|
-
break;
|
|
257
|
-
case "no-options-message":
|
|
258
|
-
this._noOptionsMessage = newValue || "No options available";
|
|
259
|
-
break;
|
|
260
|
-
case "loading":
|
|
261
|
-
this._loading = newValue;
|
|
262
|
-
this.applyLoadingState();
|
|
263
|
-
break;
|
|
122
|
+
}
|
|
264
123
|
}
|
|
265
124
|
}
|
|
266
125
|
}
|
|
267
126
|
applyLoadingState() {
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
wrapper.classList.toggle("loading", this._loading);
|
|
274
|
-
if (this._loading) {
|
|
127
|
+
const loading = this.getProperty("loading");
|
|
128
|
+
const svg = loading ? getLoaderSvg() : null;
|
|
129
|
+
this.shadowRoot.querySelectorAll(".dropdown-options-wrapper").forEach((wrapper) => {
|
|
130
|
+
wrapper.classList.toggle("loading", loading);
|
|
131
|
+
if (loading) {
|
|
275
132
|
wrapper.setAttribute("aria-busy", "true");
|
|
276
133
|
const spinner = wrapper.querySelector(".dropdown-loading-spinner");
|
|
277
134
|
if (spinner && svg)
|
|
@@ -283,121 +140,117 @@ wrapper.removeAttribute("aria-busy");
|
|
|
283
140
|
});
|
|
284
141
|
}
|
|
285
142
|
getFormValue() {
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
selectedValues
|
|
292
|
-
formData.append(this._name, value);
|
|
293
|
-
});
|
|
294
|
-
return formData;
|
|
143
|
+
const name = this.name;
|
|
144
|
+
if (!name || this.externalSelection)
|
|
145
|
+
return null;
|
|
146
|
+
const selectedValues = this.getSelectedValues();
|
|
147
|
+
if (!this.multiple) {
|
|
148
|
+
return selectedValues[0] ?? "";
|
|
295
149
|
}
|
|
296
|
-
if (
|
|
297
|
-
return "";
|
|
150
|
+
if (selectedValues.length === 0)
|
|
298
151
|
return null;
|
|
152
|
+
const formData = new FormData();
|
|
153
|
+
selectedValues.forEach((value) => formData.append(name, value));
|
|
154
|
+
return formData;
|
|
299
155
|
}
|
|
300
156
|
focus(options) {
|
|
301
|
-
if (this.
|
|
157
|
+
if (this.disabled)
|
|
302
158
|
return;
|
|
303
159
|
const trigger = this.querySelector(':scope > [slot="trigger"]');
|
|
160
|
+
if (trigger) {
|
|
161
|
+
trigger.focus(options);
|
|
162
|
+
const active = trigger.getRootNode().activeElement;
|
|
163
|
+
if (active && trigger.contains(active))
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
304
166
|
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
target.focus(options);
|
|
167
|
+
if (stub)
|
|
168
|
+
stub.focus(options);
|
|
308
169
|
else
|
|
309
170
|
super.focus(options);
|
|
310
171
|
}
|
|
311
172
|
parseValue(value) {
|
|
312
|
-
if (!value
|
|
173
|
+
if (!value)
|
|
313
174
|
return [];
|
|
314
175
|
return value
|
|
315
176
|
.split(",")
|
|
316
177
|
.map((v) => v.trim())
|
|
317
178
|
.filter((v) => v !== "");
|
|
318
179
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
this._state.selectedValues = selectedValues;
|
|
324
|
-
this.syncSelectedTags(selectedValues);
|
|
325
|
-
this.updateSelectionDisplay();
|
|
326
|
-
this.updateMobileSelectedState();
|
|
327
|
-
}
|
|
328
|
-
else {
|
|
329
|
-
this.resolveDeclarativeSelection();
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
resolveDeclarativeSelection() {
|
|
333
|
-
if (this.getAttribute("value") || this._state.selectedValues.length > 0) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const preSelectedTags = this.getTagElements()
|
|
337
|
-
.filter((tag) => tag.hasAttribute("selected"))
|
|
338
|
-
.map((tag) => this.getTagData(tag).value);
|
|
339
|
-
if (preSelectedTags.length > 0) {
|
|
340
|
-
this.updateComponentValue(preSelectedTags, false);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (document.readyState === "loading") {
|
|
344
|
-
document.addEventListener("DOMContentLoaded", () => { if (this.isConnected)
|
|
345
|
-
this.resolveDeclarativeSelection(); }, { once: true });
|
|
346
|
-
}
|
|
180
|
+
getSelectedValues() {
|
|
181
|
+
if (this.externalSelection)
|
|
182
|
+
return [];
|
|
183
|
+
return this.parseValue(this.getProperty("value"));
|
|
347
184
|
}
|
|
348
185
|
getTagElements() {
|
|
349
|
-
return Array.from(this.querySelectorAll("ty-option
|
|
186
|
+
return Array.from(this.querySelectorAll("ty-option"));
|
|
187
|
+
}
|
|
188
|
+
getOfferedTags() {
|
|
189
|
+
return this.getTagElements()
|
|
190
|
+
.filter((el) => !el.hasAttribute("hidden"))
|
|
191
|
+
.map((el) => this.getTagData(el));
|
|
350
192
|
}
|
|
351
193
|
getTagData(element) {
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
"";
|
|
194
|
+
const own = element.value;
|
|
195
|
+
const value = typeof own === "string"
|
|
196
|
+
? own
|
|
197
|
+
: element.getAttribute("value") ?? (element.textContent || "").trim();
|
|
356
198
|
const text = element.getAttribute("label") || element.textContent || "";
|
|
357
199
|
return { value, text, element };
|
|
358
200
|
}
|
|
359
|
-
|
|
360
|
-
|
|
201
|
+
findOption(value) {
|
|
202
|
+
return this.getTagElements().find((el) => this.getTagData(el).value === value);
|
|
361
203
|
}
|
|
362
|
-
|
|
363
|
-
|
|
204
|
+
paintOptions(shown) {
|
|
205
|
+
const external = this.externalSelection;
|
|
206
|
+
const selected = new Set(this.getSelectedValues());
|
|
207
|
+
for (const el of this.getTagElements()) {
|
|
208
|
+
el.checked = external
|
|
209
|
+
? isMarked(el)
|
|
210
|
+
: selected.has(this.getTagData(el).value);
|
|
211
|
+
el.inTrigger = el === shown;
|
|
364
212
|
}
|
|
365
|
-
getSelectedValues() {
|
|
366
|
-
return [...this._state.selectedValues];
|
|
367
213
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
const isSelected = tag.hasAttribute("selected");
|
|
375
|
-
if (shouldBeSelected && !isSelected) {
|
|
376
|
-
this.selectTag(tag);
|
|
377
|
-
}
|
|
378
|
-
else if (!shouldBeSelected && isSelected) {
|
|
379
|
-
this.deselectTag(tag);
|
|
380
|
-
}
|
|
381
|
-
tag.setAttribute("aria-selected", String(shouldBeSelected));
|
|
382
|
-
});
|
|
214
|
+
shownOption() {
|
|
215
|
+
if (this.multiple || this._state.open)
|
|
216
|
+
return null;
|
|
217
|
+
const value = this.getSelectedValues()[0];
|
|
218
|
+
const option = value === undefined ? undefined : this.findOption(value);
|
|
219
|
+
return option && option.parentElement === this ? option : null;
|
|
383
220
|
}
|
|
384
|
-
|
|
385
|
-
this.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
221
|
+
assignSlots(shown) {
|
|
222
|
+
const shadow = this.shadowRoot;
|
|
223
|
+
const named = new Map(NAMED_SLOTS.map((n) => [n, []]));
|
|
224
|
+
const list = [];
|
|
225
|
+
for (const node of Array.from(this.childNodes)) {
|
|
226
|
+
if (node === shown)
|
|
227
|
+
continue;
|
|
228
|
+
if (node instanceof Element && named.has(node.slot))
|
|
229
|
+
named.get(node.slot).push(node);
|
|
230
|
+
else if (node instanceof Element || node instanceof Text)
|
|
231
|
+
list.push(node);
|
|
232
|
+
}
|
|
233
|
+
for (const [name, nodes] of named) {
|
|
234
|
+
assign(shadow.querySelector(`slot[name="${name}"]`), nodes);
|
|
235
|
+
}
|
|
236
|
+
assign(shadow.querySelector('slot[name="selected"]'), shown ? [shown] : []);
|
|
237
|
+
assign(shadow.querySelector("#options-slot"), list);
|
|
238
|
+
}
|
|
239
|
+
syncTrigger() {
|
|
240
|
+
const shown = this.shownOption();
|
|
241
|
+
this.assignSlots(shown);
|
|
242
|
+
this.paintOptions(shown);
|
|
243
|
+
this.updateSelectionDisplay(shown);
|
|
391
244
|
}
|
|
392
245
|
updateComponentValue(newValues, dispatchChange = false, action = "set", item = null, reveal = dispatchChange) {
|
|
393
246
|
const oldValues = this.getSelectedValues();
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
396
|
-
|
|
397
|
-
this.
|
|
247
|
+
const sameSet = [...newValues].sort().join("\u0000") === [...oldValues].sort().join("\u0000");
|
|
248
|
+
if (sameSet)
|
|
249
|
+
return;
|
|
250
|
+
this.setProperty("value", newValues.join(","));
|
|
398
251
|
if (dispatchChange) {
|
|
399
252
|
this.dispatchChangeEvent({
|
|
400
|
-
value: this.
|
|
253
|
+
value: this.multiple ? [...newValues] : (newValues[0] ?? null),
|
|
401
254
|
values: newValues,
|
|
402
255
|
items: this.getSelectedItems(newValues),
|
|
403
256
|
action,
|
|
@@ -407,7 +260,6 @@ if (reveal)
|
|
|
407
260
|
this.revealValidity();
|
|
408
261
|
}
|
|
409
262
|
}
|
|
410
|
-
}
|
|
411
263
|
getSelectedItems(values) {
|
|
412
264
|
const byValue = new Map(this.getTagElements().map((el) => [this.getTagData(el).value, el]));
|
|
413
265
|
return values.map((value) => {
|
|
@@ -453,21 +305,12 @@ const positionBelow = pos.below;
|
|
|
453
305
|
const x = pos.x - wrapPadding;
|
|
454
306
|
const y = (positionBelow ? pos.topY : pos.bottomY) - wrapPadding;
|
|
455
307
|
const width = popupWidth + wrapPadding + wrapPadding;
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
if (positionBelow) {
|
|
463
|
-
dialog.classList.add("position-below");
|
|
464
|
-
dialog.classList.remove("position-above");
|
|
465
|
-
}
|
|
466
|
-
else {
|
|
467
|
-
dialog.classList.add("position-above");
|
|
468
|
-
dialog.classList.remove("position-below");
|
|
469
|
-
}
|
|
470
|
-
this.style.setProperty("--dropdown-direction", positionBelow ? "below" : "above");
|
|
308
|
+
dialog.style.setProperty("--dropdown-x", `${x}px`);
|
|
309
|
+
dialog.style.setProperty("--dropdown-y", `${y}px`);
|
|
310
|
+
dialog.style.setProperty("--dropdown-width", `${width}px`);
|
|
311
|
+
dialog.style.setProperty("--dropdown-padding", `${wrapPadding}px`);
|
|
312
|
+
dialog.classList.toggle("position-below", positionBelow);
|
|
313
|
+
dialog.classList.toggle("position-above", !positionBelow);
|
|
471
314
|
}
|
|
472
315
|
_setupOptionsScrollbar() {
|
|
473
316
|
if (!isCustomScrollbarEnabled())
|
|
@@ -493,29 +336,48 @@ this._optionsScrollbar.destroy();
|
|
|
493
336
|
this._optionsScrollbar = null;
|
|
494
337
|
}
|
|
495
338
|
}
|
|
339
|
+
open() {
|
|
340
|
+
if (this.disabled || this.readonly || this._state.open)
|
|
341
|
+
return;
|
|
342
|
+
if (this._state.mode === "mobile")
|
|
343
|
+
this.openMobileModal();
|
|
344
|
+
else
|
|
345
|
+
this.openDropdown();
|
|
346
|
+
}
|
|
347
|
+
close() {
|
|
348
|
+
if (this._state.mode === "mobile")
|
|
349
|
+
this.closeMobileModal();
|
|
350
|
+
else
|
|
351
|
+
this.closeDropdown();
|
|
352
|
+
}
|
|
353
|
+
lockPageScroll() {
|
|
354
|
+
this._scrollLockId = `select-${this.id || "anon"}-${this._uid}`;
|
|
355
|
+
lockScroll(this._scrollLockId);
|
|
356
|
+
}
|
|
357
|
+
unlockPageScroll() {
|
|
358
|
+
if (this._scrollLockId) {
|
|
359
|
+
unlockScroll(this._scrollLockId);
|
|
360
|
+
this._scrollLockId = null;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
setExpanded(expanded) {
|
|
364
|
+
this.shadowRoot.querySelector(".select-stub")?.setAttribute("aria-expanded", String(expanded));
|
|
365
|
+
}
|
|
496
366
|
openDropdown() {
|
|
497
367
|
const shadow = this.shadowRoot;
|
|
498
368
|
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
499
369
|
if (!dialog)
|
|
500
370
|
return;
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
this._scrollLockId = lockId;
|
|
506
|
-
lockScroll(lockId);
|
|
371
|
+
this.setExpanded(true);
|
|
372
|
+
this.lockPageScroll();
|
|
373
|
+
this._state.open = true;
|
|
374
|
+
this.syncTrigger();
|
|
507
375
|
dialog.showModal();
|
|
508
376
|
this.calculatePosition();
|
|
509
377
|
dialog.classList.add("open");
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
chevron.classList.add("open");
|
|
514
|
-
const searchChevron = shadow.querySelector(".dropdown-search-chevron");
|
|
515
|
-
if (searchChevron)
|
|
516
|
-
searchChevron.classList.add("open");
|
|
517
|
-
const tags = this.getTagElements().map((el) => this.getTagData(el));
|
|
518
|
-
this._state.filteredTags = tags;
|
|
378
|
+
shadow.querySelector(".dropdown-chevron")?.classList.add("open");
|
|
379
|
+
shadow.querySelector(".dropdown-search-chevron")?.classList.add("open");
|
|
380
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
519
381
|
this._state.highlightedIndex = -1;
|
|
520
382
|
this.updateOptionsVisibility(true);
|
|
521
383
|
this._setupOptionsScrollbar();
|
|
@@ -530,47 +392,17 @@ const shadow = this.shadowRoot;
|
|
|
530
392
|
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
531
393
|
if (!dialog)
|
|
532
394
|
return;
|
|
533
|
-
|
|
534
|
-
if (stubEl)
|
|
535
|
-
stubEl.setAttribute("aria-expanded", "false");
|
|
395
|
+
this.setExpanded(false);
|
|
536
396
|
this._destroyOptionsScrollbar();
|
|
537
|
-
dialog.classList.remove("open");
|
|
538
|
-
dialog.classList.remove("position-above");
|
|
539
|
-
dialog.classList.remove("position-below");
|
|
397
|
+
dialog.classList.remove("open", "position-above", "position-below");
|
|
540
398
|
dialog.close();
|
|
541
|
-
|
|
542
|
-
unlockScroll(this._scrollLockId);
|
|
543
|
-
this._scrollLockId = null;
|
|
544
|
-
}
|
|
399
|
+
this.unlockPageScroll();
|
|
545
400
|
this._state.open = false;
|
|
546
401
|
this._state.highlightedIndex = -1;
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
chevron
|
|
550
|
-
|
|
551
|
-
if (searchChevron)
|
|
552
|
-
searchChevron.classList.remove("open");
|
|
553
|
-
const hadQuery = this._state.search !== "";
|
|
554
|
-
this._state.search = "";
|
|
555
|
-
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
556
|
-
if (searchInput) {
|
|
557
|
-
searchInput.value = "";
|
|
558
|
-
}
|
|
559
|
-
if (this._externalSearch) {
|
|
560
|
-
if (hadQuery) {
|
|
561
|
-
if (this._searchDebounceTimer !== null) {
|
|
562
|
-
clearTimeout(this._searchDebounceTimer);
|
|
563
|
-
this._searchDebounceTimer = null;
|
|
564
|
-
}
|
|
565
|
-
this.fireSearchEvent("");
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
else {
|
|
569
|
-
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
570
|
-
this._state.filteredTags = allTags;
|
|
571
|
-
this.updateTagVisibility(allTags, allTags);
|
|
572
|
-
this.clearHighlights(allTags);
|
|
573
|
-
}
|
|
402
|
+
this.syncTrigger();
|
|
403
|
+
shadow.querySelector(".dropdown-chevron")?.classList.remove("open");
|
|
404
|
+
shadow.querySelector(".dropdown-search-chevron")?.classList.remove("open");
|
|
405
|
+
this.resetSearch(".dropdown-search-input");
|
|
574
406
|
this.fireCloseEvent();
|
|
575
407
|
}
|
|
576
408
|
openMobileModal() {
|
|
@@ -578,22 +410,17 @@ const shadow = this.shadowRoot;
|
|
|
578
410
|
const dialog = shadow.querySelector(".mobile-dialog");
|
|
579
411
|
if (!dialog)
|
|
580
412
|
return;
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
this._scrollLockId = lockId;
|
|
586
|
-
lockScroll(lockId);
|
|
413
|
+
this.setExpanded(true);
|
|
414
|
+
this.lockPageScroll();
|
|
415
|
+
this._state.open = true;
|
|
416
|
+
this.syncTrigger();
|
|
587
417
|
dialog.showModal();
|
|
588
418
|
dialog.getBoundingClientRect();
|
|
589
419
|
dialog.classList.add("open");
|
|
590
|
-
this._state.open = true;
|
|
591
420
|
const tags = this.getTagElements().map((el) => this.getTagData(el));
|
|
592
|
-
this._state.filteredTags =
|
|
421
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
593
422
|
this.updateTagVisibility(tags, tags);
|
|
594
|
-
requestAnimationFrame(() =>
|
|
595
|
-
this.updateMobileSelectedState();
|
|
596
|
-
});
|
|
423
|
+
requestAnimationFrame(() => this.updateMobileSelectedState());
|
|
597
424
|
this.fireOpenEvent();
|
|
598
425
|
}
|
|
599
426
|
closeMobileModal() {
|
|
@@ -601,24 +428,23 @@ const shadow = this.shadowRoot;
|
|
|
601
428
|
const dialog = shadow.querySelector(".mobile-dialog");
|
|
602
429
|
if (!dialog)
|
|
603
430
|
return;
|
|
604
|
-
|
|
605
|
-
if (stubEl)
|
|
606
|
-
stubEl.setAttribute("aria-expanded", "false");
|
|
431
|
+
this.setExpanded(false);
|
|
607
432
|
dialog.classList.remove("open");
|
|
608
433
|
dialog.close();
|
|
609
|
-
|
|
610
|
-
unlockScroll(this._scrollLockId);
|
|
611
|
-
this._scrollLockId = null;
|
|
612
|
-
}
|
|
434
|
+
this.unlockPageScroll();
|
|
613
435
|
this._state.open = false;
|
|
614
436
|
this._state.highlightedIndex = -1;
|
|
437
|
+
this.syncTrigger();
|
|
438
|
+
this.resetSearch(".mobile-search-input");
|
|
439
|
+
this.fireCloseEvent();
|
|
440
|
+
}
|
|
441
|
+
resetSearch(inputSelector) {
|
|
615
442
|
const hadQuery = this._state.search !== "";
|
|
616
443
|
this._state.search = "";
|
|
617
|
-
const searchInput =
|
|
618
|
-
if (searchInput)
|
|
444
|
+
const searchInput = this.shadowRoot.querySelector(inputSelector);
|
|
445
|
+
if (searchInput)
|
|
619
446
|
searchInput.value = "";
|
|
620
|
-
|
|
621
|
-
if (this._externalSearch) {
|
|
447
|
+
if (this.externalSearch) {
|
|
622
448
|
if (hadQuery) {
|
|
623
449
|
if (this._searchDebounceTimer !== null) {
|
|
624
450
|
clearTimeout(this._searchDebounceTimer);
|
|
@@ -626,41 +452,38 @@ this._searchDebounceTimer = null;
|
|
|
626
452
|
}
|
|
627
453
|
this.fireSearchEvent("");
|
|
628
454
|
}
|
|
455
|
+
return;
|
|
629
456
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
this.fireCloseEvent();
|
|
457
|
+
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
458
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
459
|
+
this.updateTagVisibility(allTags, allTags);
|
|
460
|
+
this.clearHighlights(allTags);
|
|
635
461
|
}
|
|
636
462
|
handleStubClick(e) {
|
|
637
463
|
e.preventDefault();
|
|
638
464
|
e.stopPropagation();
|
|
639
|
-
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
this.openDropdown();
|
|
465
|
+
this.open();
|
|
643
466
|
}
|
|
644
467
|
handleClearClick(e) {
|
|
645
468
|
e.preventDefault();
|
|
646
469
|
e.stopPropagation();
|
|
647
|
-
if (this.
|
|
470
|
+
if (this.disabled || this.readonly) {
|
|
648
471
|
return;
|
|
649
472
|
}
|
|
650
473
|
this.clear();
|
|
651
474
|
this.revealValidity();
|
|
652
475
|
}
|
|
653
476
|
handleStubKeydown(e) {
|
|
654
|
-
if (this.
|
|
477
|
+
if (this.disabled || this.readonly || this._state.open)
|
|
655
478
|
return;
|
|
656
479
|
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
657
480
|
e.preventDefault();
|
|
658
|
-
this.
|
|
481
|
+
this.open();
|
|
659
482
|
}
|
|
660
483
|
}
|
|
661
484
|
handleTagClick(e) {
|
|
662
485
|
const target = e.target;
|
|
663
|
-
const tag = target.closest("ty-option
|
|
486
|
+
const tag = target.closest("ty-option");
|
|
664
487
|
if (!tag || tag.hasAttribute("disabled"))
|
|
665
488
|
return;
|
|
666
489
|
e.preventDefault();
|
|
@@ -669,27 +492,35 @@ this.selectByTag(tag);
|
|
|
669
492
|
}
|
|
670
493
|
selectByTag(tag) {
|
|
671
494
|
const tagValue = this.getTagData(tag).value;
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
this.
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
495
|
+
if (this.externalSelection) {
|
|
496
|
+
const selected = !this.multiple || !isMarked(tag);
|
|
497
|
+
this.dispatchChangeEvent({
|
|
498
|
+
value: tagValue,
|
|
499
|
+
values: [],
|
|
500
|
+
items: [],
|
|
501
|
+
action: !this.multiple ? "set" : selected ? "add" : "remove",
|
|
502
|
+
item: tagValue,
|
|
503
|
+
selected,
|
|
504
|
+
});
|
|
505
|
+
if (!this.multiple)
|
|
506
|
+
this.close();
|
|
507
|
+
return;
|
|
680
508
|
}
|
|
509
|
+
if (!this.multiple) {
|
|
510
|
+
this.updateComponentValue([tagValue], true, "set", tagValue);
|
|
511
|
+
this.close();
|
|
681
512
|
return;
|
|
682
513
|
}
|
|
514
|
+
const currentValues = this.getSelectedValues();
|
|
683
515
|
if (currentValues.includes(tagValue)) {
|
|
684
|
-
|
|
685
|
-
this.updateComponentValue(newValues, true, "remove", tagValue);
|
|
516
|
+
this.updateComponentValue(currentValues.filter((v) => v !== tagValue), true, "remove", tagValue);
|
|
686
517
|
}
|
|
687
518
|
else {
|
|
688
519
|
this.updateComponentValue([...currentValues, tagValue], true, "add", tagValue);
|
|
689
520
|
}
|
|
690
521
|
}
|
|
691
522
|
tryCreateFromSearch() {
|
|
692
|
-
if (!this.
|
|
523
|
+
if (!this.allowCreate)
|
|
693
524
|
return false;
|
|
694
525
|
const query = (this._state.search || "").trim();
|
|
695
526
|
if (!query)
|
|
@@ -703,7 +534,7 @@ this.selectByTag(existing.element);
|
|
|
703
534
|
return true;
|
|
704
535
|
}
|
|
705
536
|
const rawLabel = query;
|
|
706
|
-
const defaultValue = this.
|
|
537
|
+
const defaultValue = this.createTransform === "slug" ? slugify(rawLabel) : rawLabel;
|
|
707
538
|
if (!defaultValue)
|
|
708
539
|
return true;
|
|
709
540
|
const detail = { value: defaultValue, label: rawLabel };
|
|
@@ -721,56 +552,48 @@ const option = document.createElement("ty-option");
|
|
|
721
552
|
option.setAttribute("value", finalValue);
|
|
722
553
|
option.textContent = rawLabel;
|
|
723
554
|
this.appendChild(option);
|
|
724
|
-
if (
|
|
725
|
-
this.
|
|
726
|
-
if (this.
|
|
727
|
-
this.
|
|
728
|
-
|
|
729
|
-
else {
|
|
730
|
-
this.closeDropdown();
|
|
555
|
+
if (this.externalSelection) {
|
|
556
|
+
this.selectByTag(option);
|
|
557
|
+
if (this.multiple)
|
|
558
|
+
this.clearSearchAfterCreate();
|
|
559
|
+
return true;
|
|
731
560
|
}
|
|
561
|
+
if (!this.multiple) {
|
|
562
|
+
this.updateComponentValue([finalValue], true, "create", finalValue);
|
|
563
|
+
this.close();
|
|
732
564
|
return true;
|
|
733
565
|
}
|
|
734
|
-
|
|
735
|
-
this.updateComponentValue([...currentValues, finalValue], true, "create", finalValue);
|
|
566
|
+
this.updateComponentValue([...this.getSelectedValues(), finalValue], true, "create", finalValue);
|
|
736
567
|
this.clearSearchAfterCreate();
|
|
737
568
|
return true;
|
|
738
569
|
}
|
|
739
570
|
clearSearchAfterCreate() {
|
|
740
571
|
this._state.search = "";
|
|
741
572
|
this._state.highlightedIndex = -1;
|
|
742
|
-
const
|
|
743
|
-
if (
|
|
744
|
-
|
|
745
|
-
const desktopInput = shadow.querySelector(".dropdown-search-input");
|
|
746
|
-
const mobileInput = shadow.querySelector(".mobile-search-input");
|
|
747
|
-
if (desktopInput)
|
|
748
|
-
desktopInput.value = "";
|
|
749
|
-
if (mobileInput)
|
|
750
|
-
mobileInput.value = "";
|
|
573
|
+
const input = this.searchInput();
|
|
574
|
+
if (input)
|
|
575
|
+
input.value = "";
|
|
751
576
|
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
752
|
-
this._state.filteredTags =
|
|
577
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
753
578
|
this.updateTagVisibility(allTags, allTags);
|
|
754
579
|
this.updateOptionsVisibility(true);
|
|
755
580
|
this.clearHighlights(allTags);
|
|
756
581
|
this.updateMobileSelectedState();
|
|
757
|
-
|
|
582
|
+
input?.focus();
|
|
758
583
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
e.preventDefault();
|
|
584
|
+
searchInput() {
|
|
585
|
+
return this.shadowRoot.querySelector(".dropdown-search-input, .mobile-search-input");
|
|
762
586
|
}
|
|
763
587
|
handleSearchInput(e) {
|
|
764
588
|
if (this._state.mode === "mobile")
|
|
765
589
|
this.expandMobileSection("available");
|
|
766
|
-
const
|
|
767
|
-
const query = target.value;
|
|
590
|
+
const query = e.target.value;
|
|
768
591
|
this._state.search = query;
|
|
769
|
-
if (this.
|
|
592
|
+
if (this.externalSearch) {
|
|
770
593
|
this.dispatchSearchEvent(query);
|
|
771
594
|
return;
|
|
772
595
|
}
|
|
773
|
-
const allTags = this.
|
|
596
|
+
const allTags = this.getOfferedTags();
|
|
774
597
|
const filtered = this.filterTags(allTags, query);
|
|
775
598
|
this._state.filteredTags = filtered;
|
|
776
599
|
this._state.highlightedIndex = -1;
|
|
@@ -782,54 +605,36 @@ this.clearHighlights(allTags);
|
|
|
782
605
|
handleKeyboard(e) {
|
|
783
606
|
if (!this._state.open)
|
|
784
607
|
return;
|
|
785
|
-
const shadow = this.shadowRoot;
|
|
786
|
-
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
787
|
-
const target = e.target;
|
|
788
|
-
const shouldHandle = target === searchInput || document.activeElement !== searchInput;
|
|
789
|
-
if (!shouldHandle)
|
|
790
|
-
return;
|
|
791
608
|
const filteredTags = this._state.filteredTags;
|
|
792
|
-
const
|
|
793
|
-
const currentHighlightedIndex = this._state.highlightedIndex;
|
|
609
|
+
const highlighted = this._state.highlightedIndex;
|
|
794
610
|
switch (e.key) {
|
|
795
611
|
case "Escape":
|
|
796
612
|
e.preventDefault();
|
|
797
613
|
e.stopPropagation();
|
|
798
|
-
|
|
799
|
-
this.closeMobileModal();
|
|
800
|
-
}
|
|
801
|
-
else {
|
|
802
|
-
this.closeDropdown();
|
|
803
|
-
}
|
|
614
|
+
this.close();
|
|
804
615
|
this.focus();
|
|
805
616
|
break;
|
|
806
617
|
case "Enter":
|
|
807
618
|
e.preventDefault();
|
|
808
619
|
e.stopPropagation();
|
|
809
|
-
if (
|
|
810
|
-
|
|
811
|
-
this.selectByTag(filteredTags[currentHighlightedIndex].element);
|
|
620
|
+
if (highlighted >= 0 && highlighted < filteredTags.length) {
|
|
621
|
+
this.selectByTag(filteredTags[highlighted].element);
|
|
812
622
|
}
|
|
813
623
|
else {
|
|
814
624
|
this.tryCreateFromSearch();
|
|
815
625
|
}
|
|
816
626
|
break;
|
|
817
627
|
case "ArrowUp":
|
|
628
|
+
case "ArrowDown": {
|
|
818
629
|
e.preventDefault();
|
|
819
630
|
e.stopPropagation();
|
|
820
|
-
const
|
|
821
|
-
this._state.highlightedIndex =
|
|
822
|
-
this.highlightTag(filteredTags,
|
|
823
|
-
break;
|
|
824
|
-
case "ArrowDown":
|
|
825
|
-
e.preventDefault();
|
|
826
|
-
e.stopPropagation();
|
|
827
|
-
const newIndexDown = this.nextEnabledTagIndex(filteredTags, currentHighlightedIndex, 1);
|
|
828
|
-
this._state.highlightedIndex = newIndexDown;
|
|
829
|
-
this.highlightTag(filteredTags, newIndexDown);
|
|
631
|
+
const next = this.nextEnabledTagIndex(filteredTags, highlighted, e.key === "ArrowDown" ? 1 : -1);
|
|
632
|
+
this._state.highlightedIndex = next;
|
|
633
|
+
this.highlightTag(filteredTags, next);
|
|
830
634
|
break;
|
|
831
635
|
}
|
|
832
636
|
}
|
|
637
|
+
}
|
|
833
638
|
nextEnabledTagIndex(tags, fromIndex, direction) {
|
|
834
639
|
const count = tags.length;
|
|
835
640
|
if (count === 0)
|
|
@@ -838,7 +643,8 @@ let index = fromIndex === -1
|
|
|
838
643
|
? (direction === 1 ? 0 : count - 1)
|
|
839
644
|
: (fromIndex + direction + count) % count;
|
|
840
645
|
for (let i = 0; i < count; i++) {
|
|
841
|
-
|
|
646
|
+
const el = tags[index].element;
|
|
647
|
+
if (!el.hasAttribute("disabled") && !el.hasAttribute("hidden") && !el.hasAttribute("filtered-out"))
|
|
842
648
|
return index;
|
|
843
649
|
index = (index + direction + count) % count;
|
|
844
650
|
}
|
|
@@ -854,17 +660,11 @@ return tags.filter(({ text }) => text.toLowerCase().includes(searchLower));
|
|
|
854
660
|
updateTagVisibility(filteredTags, allTags) {
|
|
855
661
|
const visibleValues = new Set(filteredTags.map((tag) => tag.value));
|
|
856
662
|
allTags.forEach(({ value, element }) => {
|
|
857
|
-
|
|
858
|
-
element.removeAttribute("hidden");
|
|
859
|
-
}
|
|
860
|
-
else {
|
|
861
|
-
element.setAttribute("hidden", "");
|
|
862
|
-
}
|
|
663
|
+
element.toggleAttribute("filtered-out", !visibleValues.has(value));
|
|
863
664
|
});
|
|
864
665
|
}
|
|
865
666
|
updateOptionsVisibility(hasOptions) {
|
|
866
|
-
const
|
|
867
|
-
const options = shadow.querySelector(".dropdown-options");
|
|
667
|
+
const options = this.shadowRoot.querySelector(".dropdown-options");
|
|
868
668
|
if (options) {
|
|
869
669
|
options.style.display = hasOptions ? "" : "none";
|
|
870
670
|
}
|
|
@@ -891,11 +691,12 @@ if (this._searchDebounceTimer !== null) {
|
|
|
891
691
|
clearTimeout(this._searchDebounceTimer);
|
|
892
692
|
this._searchDebounceTimer = null;
|
|
893
693
|
}
|
|
894
|
-
|
|
694
|
+
const debounce = this.getProperty("debounce");
|
|
695
|
+
if (debounce > 0) {
|
|
895
696
|
this._searchDebounceTimer = window.setTimeout(() => {
|
|
896
697
|
this.fireSearchEvent(query);
|
|
897
698
|
this._searchDebounceTimer = null;
|
|
898
|
-
},
|
|
699
|
+
}, debounce);
|
|
899
700
|
}
|
|
900
701
|
else {
|
|
901
702
|
this.fireSearchEvent(query);
|
|
@@ -915,7 +716,7 @@ fireOpenEvent() {
|
|
|
915
716
|
this.dispatchEvent(new CustomEvent("open", {
|
|
916
717
|
detail: { mode: this._state.mode, element: this },
|
|
917
718
|
}));
|
|
918
|
-
if (this.
|
|
719
|
+
if (this.externalSearch) {
|
|
919
720
|
this.fireSearchEvent("");
|
|
920
721
|
}
|
|
921
722
|
}
|
|
@@ -932,39 +733,51 @@ cancelable: true,
|
|
|
932
733
|
}));
|
|
933
734
|
}
|
|
934
735
|
render() {
|
|
935
|
-
this.
|
|
936
|
-
|
|
937
|
-
this.
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
this.renderDesktop();
|
|
941
|
-
}
|
|
736
|
+
if (!this.shadowRoot.querySelector(".select-container"))
|
|
737
|
+
this.build();
|
|
738
|
+
this.syncTrigger();
|
|
739
|
+
if (this._state.open)
|
|
740
|
+
this.refreshOpenList();
|
|
942
741
|
this.updateSearchVisibility();
|
|
943
742
|
this.applyLoadingState();
|
|
944
743
|
this.syncFieldChrome();
|
|
744
|
+
this.syncTriggerSlot();
|
|
745
|
+
this.updateMobileSelectedState();
|
|
746
|
+
this.updateFormValue();
|
|
945
747
|
this.updateValidity();
|
|
946
748
|
}
|
|
749
|
+
refreshOpenList() {
|
|
750
|
+
const offered = this.getOfferedTags();
|
|
751
|
+
const filtered = this.externalSearch ? offered : this.filterTags(offered, this._state.search);
|
|
752
|
+
if (!this.externalSearch) {
|
|
753
|
+
this.updateTagVisibility(filtered, this.getTagElements().map((el) => this.getTagData(el)));
|
|
754
|
+
}
|
|
755
|
+
const highlighted = this._state.filteredTags[this._state.highlightedIndex]?.element;
|
|
756
|
+
this._state.filteredTags = filtered;
|
|
757
|
+
this._state.highlightedIndex = filtered.findIndex((t) => t.element === highlighted);
|
|
758
|
+
}
|
|
947
759
|
syncFieldChrome() {
|
|
948
760
|
const shadow = this.shadowRoot;
|
|
949
|
-
const container = shadow
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
const
|
|
761
|
+
const container = shadow.querySelector(".select-container");
|
|
762
|
+
const labelText = this.label;
|
|
763
|
+
const required = this.required;
|
|
764
|
+
const disabled = this.disabled;
|
|
765
|
+
const labelId = `select-label-${this._uid}`;
|
|
953
766
|
let label = container.querySelector(":scope > .ty-field-label");
|
|
954
|
-
if (
|
|
767
|
+
if (labelText) {
|
|
955
768
|
if (!label) {
|
|
956
769
|
label = document.createElement("label");
|
|
957
770
|
label.className = "ty-field-label";
|
|
958
771
|
label.id = labelId;
|
|
959
772
|
container.prepend(label);
|
|
960
773
|
}
|
|
961
|
-
label.innerHTML = `${
|
|
774
|
+
label.innerHTML = `${labelText}${required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}`;
|
|
962
775
|
}
|
|
963
776
|
else {
|
|
964
777
|
label?.remove();
|
|
965
778
|
}
|
|
966
|
-
const error = this.
|
|
967
|
-
const errorId = `select-error-${
|
|
779
|
+
const error = this.error || "";
|
|
780
|
+
const errorId = `select-error-${this._uid}`;
|
|
968
781
|
let errorLine = container.querySelector(":scope > .error-message");
|
|
969
782
|
if (error) {
|
|
970
783
|
if (!errorLine) {
|
|
@@ -979,17 +792,16 @@ else {
|
|
|
979
792
|
errorLine?.remove();
|
|
980
793
|
}
|
|
981
794
|
const stub = shadow.querySelector(".select-stub");
|
|
982
|
-
|
|
983
|
-
stub.classList.toggle("
|
|
984
|
-
stub.classList.toggle("compact", this._compact);
|
|
795
|
+
stub.classList.toggle("disabled", disabled);
|
|
796
|
+
stub.classList.toggle("compact", this.compact);
|
|
985
797
|
stub.classList.toggle("error", !!error);
|
|
986
|
-
stub.tabIndex =
|
|
987
|
-
stub.toggleAttribute("disabled",
|
|
988
|
-
if (
|
|
798
|
+
stub.tabIndex = disabled ? -1 : 0;
|
|
799
|
+
stub.toggleAttribute("disabled", disabled);
|
|
800
|
+
if (disabled)
|
|
989
801
|
stub.setAttribute("aria-disabled", "true");
|
|
990
802
|
else
|
|
991
803
|
stub.removeAttribute("aria-disabled");
|
|
992
|
-
if (
|
|
804
|
+
if (labelText)
|
|
993
805
|
stub.setAttribute("aria-labelledby", labelId);
|
|
994
806
|
else
|
|
995
807
|
stub.removeAttribute("aria-labelledby");
|
|
@@ -1001,7 +813,13 @@ else {
|
|
|
1001
813
|
stub.removeAttribute("aria-invalid");
|
|
1002
814
|
stub.removeAttribute("aria-describedby");
|
|
1003
815
|
}
|
|
816
|
+
this.syncTriggerAria();
|
|
817
|
+
shadow
|
|
818
|
+
.querySelectorAll(".dropdown-search-input, .mobile-search-input")
|
|
819
|
+
.forEach((input) => (input.disabled = disabled));
|
|
1004
820
|
}
|
|
821
|
+
syncTriggerAria() {
|
|
822
|
+
const error = this.error || "";
|
|
1005
823
|
const trigger = error
|
|
1006
824
|
? this.querySelector(':scope > [slot="trigger"]')
|
|
1007
825
|
: null;
|
|
@@ -1010,337 +828,171 @@ this._ariaTrigger.removeAttribute("aria-invalid");
|
|
|
1010
828
|
this._ariaTrigger.removeAttribute("aria-description");
|
|
1011
829
|
}
|
|
1012
830
|
if (trigger) {
|
|
831
|
+
if (trigger.getAttribute("aria-invalid") !== "true")
|
|
1013
832
|
trigger.setAttribute("aria-invalid", "true");
|
|
833
|
+
if (trigger.getAttribute("aria-description") !== error)
|
|
1014
834
|
trigger.setAttribute("aria-description", error);
|
|
1015
835
|
}
|
|
1016
836
|
this._ariaTrigger = trigger;
|
|
1017
|
-
|
|
1018
|
-
.
|
|
1019
|
-
|
|
837
|
+
this._ariaObserver ?? (this._ariaObserver = new MutationObserver(() => this.syncTriggerAria()));
|
|
838
|
+
this._ariaObserver.disconnect();
|
|
839
|
+
if (trigger) {
|
|
840
|
+
this._ariaObserver.observe(trigger, {
|
|
841
|
+
attributes: true,
|
|
842
|
+
attributeFilter: ["aria-invalid", "aria-description"],
|
|
843
|
+
});
|
|
844
|
+
}
|
|
1020
845
|
}
|
|
1021
846
|
updateValidity() {
|
|
1022
|
-
if (this.disabled) {
|
|
847
|
+
if (this.disabled || this.externalSelection) {
|
|
1023
848
|
this.applyValidity({});
|
|
1024
849
|
return;
|
|
1025
850
|
}
|
|
1026
851
|
if (this.required && this.getSelectedValues().length === 0) {
|
|
1027
852
|
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
1028
|
-
this.applyValidity({ valueMissing: true }, nativeMessage("select", { required: true, multiple: this.
|
|
853
|
+
this.applyValidity({ valueMissing: true }, nativeMessage("select", { required: true, multiple: this.multiple }), stub ?? undefined);
|
|
1029
854
|
}
|
|
1030
855
|
else {
|
|
1031
856
|
this.applyValidity({});
|
|
1032
857
|
}
|
|
1033
858
|
}
|
|
1034
|
-
|
|
859
|
+
syncTriggerSlot() {
|
|
1035
860
|
const shadow = this.shadowRoot;
|
|
1036
|
-
const stub = shadow.querySelector(".select-stub");
|
|
1037
861
|
const slot = shadow.querySelector('slot[name="trigger"]');
|
|
1038
|
-
if (!stub || !slot)
|
|
1039
|
-
return;
|
|
1040
|
-
const sync = () => {
|
|
1041
862
|
const hasTrigger = slot.assignedElements().length > 0;
|
|
1042
|
-
stub.classList.toggle("custom-trigger", hasTrigger);
|
|
863
|
+
shadow.querySelector(".select-stub").classList.toggle("custom-trigger", hasTrigger);
|
|
864
|
+
if (this.hasAttribute("has-trigger") !== hasTrigger) {
|
|
1043
865
|
this.toggleAttribute("has-trigger", hasTrigger);
|
|
1044
|
-
};
|
|
1045
|
-
slot.addEventListener("slotchange", () => {
|
|
1046
|
-
sync();
|
|
1047
|
-
this.syncFieldChrome();
|
|
1048
|
-
});
|
|
1049
|
-
sync();
|
|
1050
866
|
}
|
|
1051
|
-
setupEventListeners() {
|
|
1052
|
-
const shadow = this.shadowRoot;
|
|
1053
|
-
const stub = shadow.querySelector(".select-stub");
|
|
1054
|
-
const optionsSlot = shadow.querySelector("#options-slot");
|
|
1055
|
-
const searchInput = shadow.querySelector(".dropdown-search-input");
|
|
1056
|
-
if (stub) {
|
|
1057
|
-
this._stubClickHandler = this.handleStubClick.bind(this);
|
|
1058
|
-
stub.addEventListener("click", this._stubClickHandler);
|
|
1059
|
-
stub.addEventListener("keydown", this.handleStubKeydown.bind(this));
|
|
1060
|
-
}
|
|
1061
|
-
const clearBtn = shadow.querySelector(".select-clear");
|
|
1062
|
-
clearBtn?.addEventListener("click", this.handleClearClick.bind(this));
|
|
1063
|
-
this.setupTriggerSlot();
|
|
1064
|
-
if (optionsSlot) {
|
|
1065
|
-
this._tagClickHandler = this.handleTagClick.bind(this);
|
|
1066
|
-
optionsSlot.addEventListener("click", this._tagClickHandler);
|
|
1067
|
-
}
|
|
1068
|
-
if (searchInput) {
|
|
1069
|
-
this._searchInputHandler = this.handleSearchInput.bind(this);
|
|
1070
|
-
this._blockSearchClick = this.blockSearchClick.bind(this);
|
|
1071
|
-
searchInput.addEventListener("input", this._searchInputHandler);
|
|
1072
|
-
searchInput.addEventListener("click", this._blockSearchClick);
|
|
1073
|
-
}
|
|
1074
|
-
const dialog = shadow.querySelector(".dropdown-dialog");
|
|
1075
|
-
if (dialog) {
|
|
1076
|
-
dialog.addEventListener("click", (e) => {
|
|
1077
|
-
if (e.target === dialog) {
|
|
1078
|
-
this.closeDropdown();
|
|
1079
867
|
}
|
|
1080
|
-
|
|
1081
|
-
dialog.addEventListener("cancel", (e) => {
|
|
1082
|
-
e.preventDefault();
|
|
1083
|
-
this.closeDropdown();
|
|
1084
|
-
this.focus();
|
|
1085
|
-
});
|
|
1086
|
-
this.syncOnOutsideClose(dialog, () => this.closeDropdown());
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
buildStubClasses() {
|
|
1090
|
-
const classes = [];
|
|
1091
|
-
if (this._disabled)
|
|
1092
|
-
classes.push("disabled");
|
|
1093
|
-
if (this._compact)
|
|
1094
|
-
classes.push("compact");
|
|
1095
|
-
return classes.join(" ");
|
|
1096
|
-
}
|
|
1097
|
-
renderDesktop() {
|
|
868
|
+
build() {
|
|
1098
869
|
const shadow = this.shadowRoot;
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
const listboxId = `select-listbox-${
|
|
1102
|
-
const
|
|
1103
|
-
const
|
|
1104
|
-
? `
|
|
1105
|
-
<label class="ty-field-label" id="${labelId}">
|
|
1106
|
-
${this._label}
|
|
1107
|
-
${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}
|
|
1108
|
-
</label>
|
|
1109
|
-
`
|
|
1110
|
-
: "";
|
|
1111
|
-
const searchPlaceholder = "Search...";
|
|
1112
|
-
shadow.innerHTML = `
|
|
1113
|
-
<div class="select-container dropdown-mode-desktop">
|
|
1114
|
-
${labelHtml}
|
|
1115
|
-
<div class="dropdown-wrapper">
|
|
1116
|
-
<div class="dropdown-stub select-stub ${stubClasses}"
|
|
1117
|
-
role="combobox"
|
|
1118
|
-
aria-haspopup="listbox"
|
|
1119
|
-
aria-expanded="false"
|
|
1120
|
-
aria-controls="${listboxId}"
|
|
1121
|
-
${this._label ? `aria-labelledby="${labelId}"` : ""}
|
|
1122
|
-
tabindex="${this._disabled ? "-1" : "0"}"
|
|
1123
|
-
${this._disabled ? 'disabled aria-disabled="true"' : ""}>
|
|
1124
|
-
<slot name="trigger">
|
|
1125
|
-
<slot name="start"></slot>
|
|
1126
|
-
<slot name="selected"></slot>
|
|
1127
|
-
<span class="dropdown-placeholder">${this._placeholder}</span>
|
|
1128
|
-
<span class="select-count" hidden></span>
|
|
1129
|
-
<slot name="end"></slot>
|
|
1130
|
-
<button class="select-clear" type="button" aria-label="Clear selection" hidden>
|
|
1131
|
-
${CLEAR_ICON_SVG}
|
|
1132
|
-
</button>
|
|
1133
|
-
<div class="dropdown-chevron">
|
|
1134
|
-
${CHEVRON_DOWN_SVG}
|
|
1135
|
-
</div>
|
|
1136
|
-
</slot>
|
|
1137
|
-
</div>
|
|
1138
|
-
<dialog class="dropdown-dialog">
|
|
1139
|
-
<div class="dropdown-header">
|
|
1140
|
-
<div class="dropdown-search-icon" aria-hidden="true">
|
|
1141
|
-
${SEARCH_ICON_SVG}
|
|
1142
|
-
</div>
|
|
1143
|
-
<input
|
|
1144
|
-
class="dropdown-search-input"
|
|
1145
|
-
type="text"
|
|
1146
|
-
placeholder="${searchPlaceholder}"
|
|
1147
|
-
${this._disabled ? "disabled" : ""}
|
|
1148
|
-
/>
|
|
1149
|
-
<div class="dropdown-search-chevron">
|
|
1150
|
-
${CHEVRON_DOWN_SVG}
|
|
1151
|
-
</div>
|
|
1152
|
-
</div>
|
|
1153
|
-
<div class="dropdown-options-wrapper">
|
|
1154
|
-
<div class="dropdown-options" id="${listboxId}" role="listbox" ${this._multiple ? 'aria-multiselectable="true"' : ""}>
|
|
1155
|
-
<slot id="options-slot"></slot>
|
|
1156
|
-
</div>
|
|
870
|
+
const mobile = isMobileTouch();
|
|
871
|
+
this._state.mode = mobile ? "mobile" : "desktop";
|
|
872
|
+
const listboxId = `select-listbox-${this._uid}`;
|
|
873
|
+
const multiselectable = this.multiple ? 'aria-multiselectable="true"' : "";
|
|
874
|
+
const loadingHtml = `
|
|
1157
875
|
<div class="dropdown-loading" aria-hidden="true">
|
|
1158
876
|
<slot name="loading">
|
|
1159
877
|
<span class="dropdown-loading-spinner"></span>
|
|
1160
878
|
<span class="dropdown-loading-text">Searching…</span>
|
|
1161
879
|
</slot>
|
|
880
|
+
</div>`;
|
|
881
|
+
const desktopPopup = `
|
|
882
|
+
<dialog class="dropdown-dialog">
|
|
883
|
+
<div class="dropdown-header">
|
|
884
|
+
<div class="dropdown-search-icon" aria-hidden="true">${SEARCH_ICON_SVG}</div>
|
|
885
|
+
<input class="dropdown-search-input" type="text" placeholder="Search..." />
|
|
886
|
+
<div class="dropdown-search-chevron">${CHEVRON_DOWN_SVG}</div>
|
|
1162
887
|
</div>
|
|
888
|
+
<div class="dropdown-options-wrapper">
|
|
889
|
+
<div class="dropdown-options" id="${listboxId}" role="listbox" ${multiselectable}>
|
|
890
|
+
<slot id="options-slot"></slot>
|
|
1163
891
|
</div>
|
|
1164
|
-
|
|
1165
|
-
</div>
|
|
892
|
+
${loadingHtml}
|
|
1166
893
|
</div>
|
|
1167
|
-
|
|
1168
|
-
this.
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
renderMobile() {
|
|
1173
|
-
const shadow = this.shadowRoot;
|
|
1174
|
-
if (!shadow.querySelector(".select-container")) {
|
|
1175
|
-
const stubClasses = this.buildStubClasses();
|
|
1176
|
-
const listboxId = `select-listbox-${getElementHash(this)}`;
|
|
1177
|
-
const labelId = `select-label-${getElementHash(this)}`;
|
|
1178
|
-
const labelHtml = this._label
|
|
1179
|
-
? `
|
|
1180
|
-
<label class="ty-field-label" id="${labelId}">
|
|
1181
|
-
${this._label}
|
|
1182
|
-
${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}
|
|
1183
|
-
</label>
|
|
1184
|
-
`
|
|
1185
|
-
: "";
|
|
1186
|
-
const closeButtonSvg = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1187
|
-
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
1188
|
-
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
1189
|
-
</svg>`;
|
|
1190
|
-
const searchPlaceholder = this._label
|
|
1191
|
-
? `Search ${this._label}...`
|
|
1192
|
-
: "Search...";
|
|
1193
|
-
const searchHeaderHtml = `
|
|
894
|
+
</dialog>`;
|
|
895
|
+
const label = this.label;
|
|
896
|
+
const mobilePopup = `
|
|
897
|
+
<dialog class="mobile-dialog">
|
|
898
|
+
<div class="mobile-dialog-content">
|
|
1194
899
|
<div class="mobile-search-header">
|
|
1195
|
-
${
|
|
900
|
+
${label ? `<span class="mobile-header-label">${label}</span>` : ""}
|
|
1196
901
|
<div class="mobile-header-content">
|
|
1197
|
-
<div class="dropdown-search-icon" aria-hidden="true">
|
|
1198
|
-
|
|
902
|
+
<div class="dropdown-search-icon" aria-hidden="true">${SEARCH_ICON_SVG}</div>
|
|
903
|
+
<input class="mobile-search-input" type="text"
|
|
904
|
+
placeholder="${label ? `Search ${label}...` : "Search..."}" autofocus />
|
|
905
|
+
<button class="mobile-close-button" type="button" aria-label="Close">${CLEAR_ICON_SVG}</button>
|
|
906
|
+
</div>
|
|
1199
907
|
</div>
|
|
1200
|
-
<
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
${
|
|
1206
|
-
|
|
1207
|
-
<
|
|
1208
|
-
|
|
908
|
+
<div class="mobile-body" data-expanded="available">
|
|
909
|
+
<!-- Selected strip, pinned above the list; collapses when empty -->
|
|
910
|
+
<div class="mobile-selected-section" data-empty="true">
|
|
911
|
+
<button class="section-header" type="button" data-section="selected" aria-expanded="false">
|
|
912
|
+
<span class="section-title"></span>
|
|
913
|
+
${CHEVRON_DOWN_SVG}
|
|
914
|
+
</button>
|
|
915
|
+
<div class="section-content mobile-selected-chips"></div>
|
|
916
|
+
</div>
|
|
917
|
+
<div class="mobile-available-section" data-empty="false">
|
|
918
|
+
<button class="section-header" type="button" data-section="available" aria-expanded="true">
|
|
919
|
+
<span class="section-title"></span>
|
|
920
|
+
${CHEVRON_DOWN_SVG}
|
|
1209
921
|
</button>
|
|
922
|
+
<div class="section-content dropdown-options-wrapper" id="${listboxId}" role="listbox" ${multiselectable}>
|
|
923
|
+
<slot id="options-slot"></slot>
|
|
924
|
+
<div class="empty-state">${this.getProperty("no-options-message")}</div>
|
|
925
|
+
${loadingHtml}
|
|
1210
926
|
</div>
|
|
1211
927
|
</div>
|
|
1212
|
-
|
|
928
|
+
</div>
|
|
929
|
+
</div>
|
|
930
|
+
</dialog>`;
|
|
1213
931
|
shadow.innerHTML = `
|
|
1214
|
-
<div class="select-container dropdown-mode
|
|
1215
|
-
${labelHtml}
|
|
932
|
+
<div class="select-container dropdown-mode-${this._state.mode}">
|
|
1216
933
|
<div class="dropdown-wrapper">
|
|
1217
|
-
<div class="dropdown-stub select-stub
|
|
934
|
+
<div class="dropdown-stub select-stub"
|
|
1218
935
|
role="combobox"
|
|
1219
936
|
aria-haspopup="listbox"
|
|
1220
937
|
aria-expanded="false"
|
|
1221
938
|
aria-controls="${listboxId}"
|
|
1222
|
-
|
|
1223
|
-
tabindex="${this._disabled ? "-1" : "0"}"
|
|
1224
|
-
${this._disabled ? 'disabled aria-disabled="true"' : ""}>
|
|
939
|
+
tabindex="0">
|
|
1225
940
|
<slot name="trigger">
|
|
1226
941
|
<slot name="start"></slot>
|
|
1227
942
|
<slot name="selected"></slot>
|
|
1228
|
-
<span class="dropdown-placeholder"
|
|
943
|
+
<span class="dropdown-placeholder"></span>
|
|
1229
944
|
<span class="select-count" hidden></span>
|
|
1230
945
|
<slot name="end"></slot>
|
|
1231
946
|
<button class="select-clear" type="button" aria-label="Clear selection" hidden>
|
|
1232
947
|
${CLEAR_ICON_SVG}
|
|
1233
948
|
</button>
|
|
1234
|
-
<div class="dropdown-chevron">
|
|
1235
|
-
${CHEVRON_DOWN_SVG}
|
|
1236
|
-
</div>
|
|
949
|
+
<div class="dropdown-chevron">${CHEVRON_DOWN_SVG}</div>
|
|
1237
950
|
</slot>
|
|
1238
951
|
</div>
|
|
1239
|
-
|
|
1240
|
-
<div class="mobile-dialog-content">
|
|
1241
|
-
<!-- HEADER (matches dropdown.ts) -->
|
|
1242
|
-
${searchHeaderHtml}
|
|
1243
|
-
<!-- BODY: options list with toggleable selected state -->
|
|
1244
|
-
<div class="mobile-body" data-expanded="available">
|
|
1245
|
-
<!-- SELECTED STRIP (pinned above the list, collapses when empty) -->
|
|
1246
|
-
<div class="mobile-selected-section" data-empty="true">
|
|
1247
|
-
<button class="section-header" type="button" data-section="selected" aria-expanded="false">
|
|
1248
|
-
<span class="section-title">${this._selectedLabel} <span class="section-count">(0)</span></span>
|
|
1249
|
-
${CHEVRON_DOWN_SVG}
|
|
1250
|
-
</button>
|
|
1251
|
-
<div class="section-content mobile-selected-chips"></div>
|
|
1252
|
-
</div>
|
|
1253
|
-
<!-- AVAILABLE LIST (always visible, takes remaining space) -->
|
|
1254
|
-
<div class="mobile-available-section" data-empty="false">
|
|
1255
|
-
<button class="section-header" type="button" data-section="available" aria-expanded="true">
|
|
1256
|
-
<span class="section-title">${this._availableLabel} <span class="section-count"></span></span>
|
|
1257
|
-
${CHEVRON_DOWN_SVG}
|
|
1258
|
-
</button>
|
|
1259
|
-
<div class="section-content dropdown-options-wrapper" id="${listboxId}" role="listbox" ${this._multiple ? 'aria-multiselectable="true"' : ""}>
|
|
1260
|
-
<slot id="options-slot"></slot>
|
|
1261
|
-
<div class="empty-state">${this._noOptionsMessage}</div>
|
|
1262
|
-
<div class="dropdown-loading" aria-hidden="true">
|
|
1263
|
-
<slot name="loading">
|
|
1264
|
-
<span class="dropdown-loading-spinner"></span>
|
|
1265
|
-
<span class="dropdown-loading-text">Searching…</span>
|
|
1266
|
-
</slot>
|
|
1267
|
-
</div>
|
|
1268
|
-
</div>
|
|
1269
|
-
</div>
|
|
1270
|
-
</div>
|
|
1271
|
-
</div>
|
|
1272
|
-
</dialog>
|
|
952
|
+
${mobile ? mobilePopup : desktopPopup}
|
|
1273
953
|
</div>
|
|
1274
954
|
</div>
|
|
1275
955
|
`;
|
|
1276
|
-
this.setupMobileEventListeners();
|
|
1277
|
-
}
|
|
1278
|
-
this.updateSelectionDisplay();
|
|
1279
|
-
}
|
|
1280
|
-
setupMobileEventListeners() {
|
|
1281
|
-
const shadow = this.shadowRoot;
|
|
1282
956
|
const stub = shadow.querySelector(".select-stub");
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
stub.addEventListener("keydown", (e) => this.handleMobileStubKeydown(e));
|
|
1290
|
-
}
|
|
1291
|
-
const clearBtn = shadow.querySelector(".select-clear");
|
|
1292
|
-
clearBtn?.addEventListener("click", this.handleClearClick.bind(this));
|
|
1293
|
-
this.setupTriggerSlot();
|
|
1294
|
-
if (optionsSlot) {
|
|
1295
|
-
optionsSlot.addEventListener("click", (e) => this.handleMobileTagClick(e));
|
|
1296
|
-
}
|
|
1297
|
-
if (searchInput) {
|
|
1298
|
-
searchInput.addEventListener("input", (e) => this.handleSearchInput(e));
|
|
1299
|
-
}
|
|
1300
|
-
shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
|
|
1301
|
-
header.addEventListener("click", () => this.expandMobileSection(header.dataset.section === "selected" ? "selected" : "available"));
|
|
957
|
+
stub.addEventListener("click", (e) => this.handleStubClick(e));
|
|
958
|
+
stub.addEventListener("keydown", (e) => this.handleStubKeydown(e));
|
|
959
|
+
shadow.querySelector(".select-clear").addEventListener("click", (e) => this.handleClearClick(e));
|
|
960
|
+
shadow.querySelector('slot[name="trigger"]').addEventListener("slotchange", () => {
|
|
961
|
+
this.syncTriggerSlot();
|
|
962
|
+
this.syncFieldChrome();
|
|
1302
963
|
});
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
964
|
+
shadow.querySelector("#options-slot").addEventListener("click", (e) => this.handleTagClick(e));
|
|
965
|
+
const searchInput = this.searchInput();
|
|
966
|
+
searchInput.addEventListener("input", (e) => this.handleSearchInput(e));
|
|
967
|
+
const dialog = shadow.querySelector("dialog");
|
|
1307
968
|
dialog.addEventListener("click", (e) => {
|
|
1308
|
-
if (e.target === dialog)
|
|
1309
|
-
this.
|
|
1310
|
-
}
|
|
969
|
+
if (e.target === dialog)
|
|
970
|
+
this.close();
|
|
1311
971
|
});
|
|
1312
972
|
dialog.addEventListener("cancel", (e) => {
|
|
1313
973
|
e.preventDefault();
|
|
1314
|
-
this.
|
|
974
|
+
this.close();
|
|
1315
975
|
this.focus();
|
|
1316
976
|
});
|
|
1317
|
-
this.syncOnOutsideClose(dialog
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
close();
|
|
1324
|
-
}).observe(dialog, { attributes: true, attributeFilter: ["open"] });
|
|
977
|
+
this.syncOnOutsideClose(dialog);
|
|
978
|
+
if (mobile) {
|
|
979
|
+
shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
|
|
980
|
+
header.addEventListener("click", () => this.expandMobileSection(header.dataset.section === "selected" ? "selected" : "available"));
|
|
981
|
+
});
|
|
982
|
+
shadow.querySelector(".mobile-close-button").addEventListener("click", () => this.close());
|
|
1325
983
|
}
|
|
1326
|
-
|
|
1327
|
-
|
|
984
|
+
else {
|
|
985
|
+
searchInput.addEventListener("click", (e) => {
|
|
1328
986
|
e.stopPropagation();
|
|
1329
|
-
if (this._disabled || this._readonly) {
|
|
1330
|
-
return;
|
|
1331
|
-
}
|
|
1332
|
-
this.openMobileModal();
|
|
1333
|
-
}
|
|
1334
|
-
handleMobileStubKeydown(e) {
|
|
1335
|
-
if (this._disabled || this._readonly || this._state.open)
|
|
1336
|
-
return;
|
|
1337
|
-
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
1338
987
|
e.preventDefault();
|
|
1339
|
-
|
|
988
|
+
});
|
|
1340
989
|
}
|
|
1341
990
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
991
|
+
syncOnOutsideClose(dialog) {
|
|
992
|
+
new MutationObserver(() => {
|
|
993
|
+
if (this._state.open && !dialog.open)
|
|
994
|
+
this.close();
|
|
995
|
+
}).observe(dialog, { attributes: true, attributeFilter: ["open"] });
|
|
1344
996
|
}
|
|
1345
997
|
updateMobileSelectedState() {
|
|
1346
998
|
if (this._state.mode !== "mobile")
|
|
@@ -1349,9 +1001,11 @@ const shadow = this.shadowRoot;
|
|
|
1349
1001
|
this.renderMobileSelectedChips();
|
|
1350
1002
|
const availableSection = shadow.querySelector(".mobile-available-section");
|
|
1351
1003
|
if (availableSection) {
|
|
1352
|
-
const
|
|
1353
|
-
|
|
1354
|
-
|
|
1004
|
+
const selected = new Set(this.getSelectedValues());
|
|
1005
|
+
const shown = this.getOfferedTags().filter(({ element }) => !element.hasAttribute("filtered-out"));
|
|
1006
|
+
const visibleAvailable = shown.filter(({ value }) => !selected.has(value)).length;
|
|
1007
|
+
availableSection.setAttribute("data-empty", String(shown.length === 0));
|
|
1008
|
+
this.setMobileSectionTitle(availableSection, this.getProperty("available-label"), visibleAvailable);
|
|
1355
1009
|
}
|
|
1356
1010
|
}
|
|
1357
1011
|
setMobileSectionTitle(section, label, n) {
|
|
@@ -1368,7 +1022,7 @@ const shadow = this.shadowRoot;
|
|
|
1368
1022
|
const body = shadow?.querySelector(".mobile-body");
|
|
1369
1023
|
if (!body)
|
|
1370
1024
|
return;
|
|
1371
|
-
if (section === "selected" && this.
|
|
1025
|
+
if (section === "selected" && this.getSelectedValues().length === 0)
|
|
1372
1026
|
return;
|
|
1373
1027
|
body.dataset.expanded = section;
|
|
1374
1028
|
shadow.querySelectorAll(".mobile-body .section-header").forEach((header) => {
|
|
@@ -1382,24 +1036,20 @@ const section = shadow.querySelector(".mobile-selected-section");
|
|
|
1382
1036
|
const host = shadow.querySelector(".mobile-selected-chips");
|
|
1383
1037
|
if (!section || !host)
|
|
1384
1038
|
return;
|
|
1385
|
-
const selected = this.
|
|
1039
|
+
const selected = this.getSelectedValues();
|
|
1386
1040
|
section.setAttribute("data-empty", String(selected.length === 0));
|
|
1387
|
-
this.setMobileSectionTitle(section, this.
|
|
1041
|
+
this.setMobileSectionTitle(section, this.getProperty("selected-label"), selected.length);
|
|
1388
1042
|
if (selected.length === 0)
|
|
1389
1043
|
this.expandMobileSection("available");
|
|
1390
|
-
const labelFor = (value) => {
|
|
1391
|
-
const option = this.getTagElements().find((tag) => this.getTagData(tag).value === value);
|
|
1392
|
-
return option ? this.getTagData(option).text : value;
|
|
1393
|
-
};
|
|
1394
1044
|
host.textContent = "";
|
|
1395
|
-
for (const value of selected) {
|
|
1045
|
+
for (const { value, label } of this.getSelectedItems(selected)) {
|
|
1396
1046
|
const chip = document.createElement("button");
|
|
1397
1047
|
chip.type = "button";
|
|
1398
1048
|
chip.className = "mobile-selected-chip";
|
|
1399
1049
|
chip.dataset.value = value;
|
|
1400
|
-
chip.setAttribute("aria-label", `Remove ${
|
|
1050
|
+
chip.setAttribute("aria-label", `Remove ${label}`);
|
|
1401
1051
|
chip.innerHTML = `<span class="chip-label"></span>${CLEAR_ICON_SVG}`;
|
|
1402
|
-
chip.querySelector(".chip-label").textContent =
|
|
1052
|
+
chip.querySelector(".chip-label").textContent = label;
|
|
1403
1053
|
chip.addEventListener("click", (e) => {
|
|
1404
1054
|
e.preventDefault();
|
|
1405
1055
|
e.stopPropagation();
|
|
@@ -1409,105 +1059,40 @@ host.appendChild(chip);
|
|
|
1409
1059
|
}
|
|
1410
1060
|
}
|
|
1411
1061
|
shouldShowSearch() {
|
|
1412
|
-
if (this.
|
|
1062
|
+
if (this.externalSearch || this.allowCreate)
|
|
1413
1063
|
return true;
|
|
1414
|
-
if (this.
|
|
1415
|
-
return true;
|
|
1416
|
-
if (this._notSearchable)
|
|
1064
|
+
if (this.notSearchable)
|
|
1417
1065
|
return false;
|
|
1418
1066
|
return this.getTagElements().length > SEARCH_AUTO_THRESHOLD;
|
|
1419
1067
|
}
|
|
1420
1068
|
updateSearchVisibility() {
|
|
1421
1069
|
const shadow = this.shadowRoot;
|
|
1422
|
-
if (!shadow)
|
|
1423
|
-
return;
|
|
1424
1070
|
const show = this.shouldShowSearch();
|
|
1425
1071
|
const header = shadow.querySelector(".dropdown-header");
|
|
1426
1072
|
if (header)
|
|
1427
1073
|
header.hidden = !show;
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
updateSelectionDisplay() {
|
|
1436
|
-
const shadow = this.shadowRoot;
|
|
1437
|
-
const stub = shadow.querySelector(".select-stub");
|
|
1438
|
-
if (!stub)
|
|
1439
|
-
return;
|
|
1440
|
-
const values = this._state.selectedValues;
|
|
1074
|
+
shadow
|
|
1075
|
+
.querySelectorAll(".mobile-search-input, .mobile-header-content .dropdown-search-icon")
|
|
1076
|
+
.forEach((el) => (el.hidden = !show));
|
|
1077
|
+
}
|
|
1078
|
+
updateSelectionDisplay(shown) {
|
|
1079
|
+
const stub = this.shadowRoot.querySelector(".select-stub");
|
|
1080
|
+
const values = this.getSelectedValues();
|
|
1441
1081
|
const count = values.length;
|
|
1442
1082
|
stub.classList.toggle("has-selection", count > 0);
|
|
1443
|
-
stub.classList.toggle("
|
|
1083
|
+
stub.classList.toggle("has-option", shown !== null);
|
|
1444
1084
|
const badge = stub.querySelector(".select-count");
|
|
1445
|
-
if (badge) {
|
|
1446
1085
|
badge.textContent = String(count);
|
|
1447
|
-
badge.hidden = count === 0 || !this.
|
|
1448
|
-
}
|
|
1086
|
+
badge.hidden = count === 0 || !this.multiple || !this.compact;
|
|
1449
1087
|
const clearBtn = stub.querySelector(".select-clear");
|
|
1450
|
-
|
|
1451
|
-
clearBtn.hidden = !(count > 0 && this._clearable && !this._disabled && !this._readonly);
|
|
1452
|
-
}
|
|
1453
|
-
const wantClone = !this._multiple && count > 0 ? values[0] : null;
|
|
1454
|
-
this.syncSelectedClone(wantClone);
|
|
1455
|
-
const hasClone = this._selectedClone !== null;
|
|
1456
|
-
stub.classList.toggle("has-clone", hasClone);
|
|
1088
|
+
clearBtn.hidden = !(count > 0 && !this.noClear && !this.disabled && !this.readonly);
|
|
1457
1089
|
const textEl = stub.querySelector(".dropdown-placeholder");
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
textEl.textContent = this.
|
|
1463
|
-
.
|
|
1464
|
-
.join(", ");
|
|
1465
|
-
textEl.classList.remove("placeholder-shown");
|
|
1466
|
-
}
|
|
1467
|
-
else if (wantClone !== null) {
|
|
1468
|
-
textEl.textContent = values.join(", ");
|
|
1469
|
-
textEl.classList.remove("placeholder-shown");
|
|
1470
|
-
}
|
|
1471
|
-
else {
|
|
1472
|
-
textEl.textContent = this._placeholder;
|
|
1473
|
-
textEl.classList.add("placeholder-shown");
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
syncSelectedClone(value) {
|
|
1478
|
-
const existing = this.querySelector(':scope > [cloned][slot="selected"]');
|
|
1479
|
-
if (existing?.getAttribute("value") === value) {
|
|
1480
|
-
const stale = value !== null &&
|
|
1481
|
-
existing.childNodes.length === 0 &&
|
|
1482
|
-
(this.getTagElements().find((el) => this.getTagData(el).value === value)?.childNodes.length ?? 0) > 0;
|
|
1483
|
-
if (!stale) {
|
|
1484
|
-
this._selectedClone = existing;
|
|
1485
|
-
return;
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
existing?.remove();
|
|
1489
|
-
if (value === null) {
|
|
1490
|
-
this._selectedClone = null;
|
|
1491
|
-
return;
|
|
1492
|
-
}
|
|
1493
|
-
const option = this.getTagElements().find((el) => this.getTagData(el).value === value);
|
|
1494
|
-
if (option) {
|
|
1495
|
-
const clone = option.cloneNode(true);
|
|
1496
|
-
clone.removeAttribute("selected");
|
|
1497
|
-
clone.setAttribute("slot", "selected");
|
|
1498
|
-
clone.setAttribute("cloned", "true");
|
|
1499
|
-
this.appendChild(clone);
|
|
1500
|
-
this._selectedClone = clone;
|
|
1501
|
-
if (option.childNodes.length === 0 && document.readyState === "loading") {
|
|
1502
|
-
document.addEventListener("DOMContentLoaded", () => { if (this.isConnected)
|
|
1503
|
-
this.updateSelectionDisplay(); }, { once: true });
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
else if (this._selectedClone?.getAttribute("value") === value) {
|
|
1507
|
-
const restored = this._selectedClone.cloneNode(true);
|
|
1508
|
-
this.appendChild(restored);
|
|
1509
|
-
this._selectedClone = restored;
|
|
1510
|
-
}
|
|
1090
|
+
textEl.hidden = shown !== null;
|
|
1091
|
+
const text = this._state.open || count === 0 || (this.multiple && this.compact)
|
|
1092
|
+
? null
|
|
1093
|
+
: this.getSelectedItems(values).map((i) => i.label).join(", ");
|
|
1094
|
+
textEl.textContent = text ?? this.placeholder;
|
|
1095
|
+
textEl.classList.toggle("placeholder-shown", text === null);
|
|
1511
1096
|
}
|
|
1512
1097
|
deselectValue(value) {
|
|
1513
1098
|
const current = this.getSelectedValues();
|
|
@@ -1602,6 +1187,24 @@ return this.getProperty("externalSearch");
|
|
|
1602
1187
|
set externalSearch(value) {
|
|
1603
1188
|
this.setProperty("externalSearch", value);
|
|
1604
1189
|
}
|
|
1190
|
+
get externalSelection() {
|
|
1191
|
+
return this.getProperty("externalSelection");
|
|
1192
|
+
}
|
|
1193
|
+
set externalSelection(value) {
|
|
1194
|
+
this.setProperty("externalSelection", value);
|
|
1195
|
+
}
|
|
1196
|
+
get allowCreate() {
|
|
1197
|
+
return this.getProperty("allowCreate");
|
|
1198
|
+
}
|
|
1199
|
+
set allowCreate(value) {
|
|
1200
|
+
this.setProperty("allowCreate", value);
|
|
1201
|
+
}
|
|
1202
|
+
get createTransform() {
|
|
1203
|
+
return this.getProperty("createTransform");
|
|
1204
|
+
}
|
|
1205
|
+
set createTransform(value) {
|
|
1206
|
+
this.setProperty("createTransform", value);
|
|
1207
|
+
}
|
|
1605
1208
|
get debounce() {
|
|
1606
1209
|
return this.getProperty("debounce");
|
|
1607
1210
|
}
|
|
@@ -1631,18 +1234,13 @@ get flavor() {
|
|
|
1631
1234
|
return this.getProperty("flavor");
|
|
1632
1235
|
}
|
|
1633
1236
|
set flavor(value) {
|
|
1634
|
-
this.removeAttribute(ERROR_FLAVOR);
|
|
1635
1237
|
this.setProperty("flavor", value);
|
|
1636
1238
|
}
|
|
1637
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
1638
|
-
if (name === "flavor" && newValue === "danger" && oldValue === newValue)
|
|
1639
|
-
this.removeAttribute(ERROR_FLAVOR);
|
|
1640
|
-
super.attributeChangedCallback(name, oldValue, newValue);
|
|
1641
|
-
}
|
|
1642
1239
|
get form() {
|
|
1643
1240
|
return this._internals.form;
|
|
1644
1241
|
}
|
|
1645
1242
|
}
|
|
1243
|
+
TySelect.slotAssignment = "manual";
|
|
1646
1244
|
TySelect.properties = {
|
|
1647
1245
|
value: {
|
|
1648
1246
|
type: "string",
|
|
@@ -1713,19 +1311,21 @@ externalSearch: {
|
|
|
1713
1311
|
type: "boolean",
|
|
1714
1312
|
visual: true,
|
|
1715
1313
|
default: false,
|
|
1716
|
-
|
|
1314
|
+
},
|
|
1315
|
+
externalSelection: {
|
|
1316
|
+
type: "boolean",
|
|
1317
|
+
visual: true,
|
|
1318
|
+
default: false,
|
|
1717
1319
|
},
|
|
1718
1320
|
allowCreate: {
|
|
1719
1321
|
type: "boolean",
|
|
1720
1322
|
visual: true,
|
|
1721
1323
|
default: false,
|
|
1722
|
-
aliases: { "allow-create": true },
|
|
1723
1324
|
},
|
|
1724
1325
|
createTransform: {
|
|
1725
1326
|
type: "string",
|
|
1726
1327
|
visual: false,
|
|
1727
1328
|
default: "none",
|
|
1728
|
-
aliases: { "create-transform": true },
|
|
1729
1329
|
coerce: (v) => (v === "slug" ? "slug" : "none"),
|
|
1730
1330
|
},
|
|
1731
1331
|
notSearchable: {
|