tyrell-components 1.0.0-TC59 → 1.0.0-TC61

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