tyrell-components 1.0.0-RC15 → 1.0.0-RC17
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 +44 -52
- package/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +13 -7
- package/css/tyrell.css +15 -22
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +37 -15
- package/lib/base/ty-component.js +90 -26
- package/lib/components/button.d.ts +14 -0
- package/lib/components/button.js +61 -7
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +38 -30
- package/lib/components/calendar-navigation.d.ts +11 -0
- package/lib/components/calendar-navigation.js +68 -44
- package/lib/components/calendar.d.ts +52 -3
- package/lib/components/calendar.js +274 -61
- package/lib/components/checkbox.d.ts +8 -1
- package/lib/components/checkbox.js +29 -8
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +24 -33
- package/lib/components/date-picker.d.ts +68 -34
- package/lib/components/date-picker.js +386 -389
- package/lib/components/file-upload.d.ts +7 -0
- package/lib/components/file-upload.js +36 -4
- package/lib/components/input.d.ts +73 -3
- package/lib/components/input.js +159 -24
- package/lib/components/modal.d.ts +4 -8
- package/lib/components/modal.js +103 -33
- package/lib/components/option.js +7 -5
- package/lib/components/popup.js +117 -14
- package/lib/components/radio.d.ts +24 -0
- package/lib/components/radio.js +55 -32
- package/lib/components/resize-observer.js +2 -0
- package/lib/components/scroll-container.d.ts +3 -2
- package/lib/components/scroll-container.js +7 -8
- package/lib/components/select.d.ts +68 -11
- package/lib/components/select.js +196 -44
- package/lib/components/selected-tags.d.ts +7 -1
- package/lib/components/selected-tags.js +10 -1
- package/lib/components/switch.d.ts +9 -1
- package/lib/components/switch.js +29 -8
- package/lib/components/tab.d.ts +49 -1
- package/lib/components/tab.js +151 -10
- package/lib/components/tabs.d.ts +14 -2
- package/lib/components/tabs.js +185 -136
- package/lib/components/tag.d.ts +4 -7
- package/lib/components/tag.js +6 -7
- package/lib/components/textarea.d.ts +51 -5
- package/lib/components/textarea.js +95 -30
- package/lib/components/tooltip.d.ts +4 -3
- package/lib/components/tooltip.js +34 -24
- package/lib/components/wizard.d.ts +5 -4
- package/lib/components/wizard.js +120 -156
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/styles/button.js +21 -19
- package/lib/styles/calendar-month.d.ts +3 -0
- package/lib/styles/calendar-month.js +43 -27
- package/lib/styles/calendar-navigation.d.ts +1 -1
- package/lib/styles/calendar-navigation.js +55 -26
- package/lib/styles/calendar.d.ts +3 -2
- package/lib/styles/calendar.js +77 -0
- package/lib/styles/checkbox.js +31 -13
- package/lib/styles/copy.js +5 -1
- package/lib/styles/date-picker.js +68 -26
- package/lib/styles/file-upload.d.ts +1 -1
- package/lib/styles/file-upload.js +3 -3
- package/lib/styles/icon.d.ts +1 -1
- package/lib/styles/icon.js +2 -2
- package/lib/styles/input.js +6 -10
- package/lib/styles/option.d.ts +1 -1
- package/lib/styles/option.js +7 -3
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +10 -5
- package/lib/styles/radio.js +18 -6
- package/lib/styles/scroll-container.d.ts +1 -1
- package/lib/styles/scroll-container.js +1 -1
- package/lib/styles/select-base.js +24 -3
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +10 -0
- package/lib/styles/step.d.ts +1 -1
- package/lib/styles/step.js +1 -9
- package/lib/styles/switch.js +14 -6
- package/lib/styles/tab.d.ts +1 -1
- package/lib/styles/tab.js +67 -3
- package/lib/styles/tabs.d.ts +1 -1
- package/lib/styles/tabs.js +7 -3
- package/lib/styles/tag.js +3 -3
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +7 -0
- package/lib/styles/wizard.d.ts +9 -5
- package/lib/styles/wizard.js +211 -99
- package/lib/types/common.d.ts +2 -2
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +7 -1
- package/lib/utils/property-manager.js +16 -4
- package/lib/utils/scroll-lock.d.ts +10 -4
- package/lib/utils/scroll-lock.js +102 -2
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +27 -5
package/lib/components/select.js
CHANGED
|
@@ -20,6 +20,7 @@ elementIds.set(element, id);
|
|
|
20
20
|
return id;
|
|
21
21
|
}
|
|
22
22
|
import { REQUIRED_ICON_SVG } from "../utils/icons.js";
|
|
23
|
+
import { nativeMessage } from "../utils/validity.js";
|
|
23
24
|
const SEARCH_AUTO_THRESHOLD = 7;
|
|
24
25
|
const CHEVRON_DOWN_SVG = `<svg viewBox="0 0 20 20" fill="currentColor">
|
|
25
26
|
<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" />
|
|
@@ -81,6 +82,8 @@ this._optionsScrollbar = null;
|
|
|
81
82
|
this._childObserver = null;
|
|
82
83
|
this._selectedClone = null;
|
|
83
84
|
this._customFlavorSheet = null;
|
|
85
|
+
this._ariaTrigger = null;
|
|
86
|
+
this._ariaObserver = null;
|
|
84
87
|
const shadow = this.shadowRoot;
|
|
85
88
|
ensureStyles(shadow, { css: selectBaseStyles, id: "ty-select-base" });
|
|
86
89
|
ensureStyles(shadow, { css: selectStyles, id: "ty-select" });
|
|
@@ -96,6 +99,7 @@ dialog.close();
|
|
|
96
99
|
});
|
|
97
100
|
this.render();
|
|
98
101
|
this.initializeState();
|
|
102
|
+
this.updateFormValue();
|
|
99
103
|
this._childObserver = new MutationObserver(() => {
|
|
100
104
|
this.ensureOptionRoles();
|
|
101
105
|
if (this._state.selectedValues.length > 0) {
|
|
@@ -108,11 +112,21 @@ this.updateMobileSelectedState();
|
|
|
108
112
|
this._childObserver.observe(this, { childList: true });
|
|
109
113
|
this.ensureOptionRoles();
|
|
110
114
|
this._syncCustomFlavor();
|
|
115
|
+
if (!this._keyboardHandler) {
|
|
116
|
+
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
117
|
+
document.addEventListener("keydown", this._keyboardHandler, true);
|
|
118
|
+
}
|
|
111
119
|
}
|
|
112
120
|
_syncCustomFlavor() {
|
|
113
121
|
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.getProperty("flavor"), ({ base }) => selectCustomFlavorCss(base));
|
|
114
122
|
}
|
|
115
123
|
onDisconnect() {
|
|
124
|
+
if (this._state.open) {
|
|
125
|
+
if (this._state.mode === "mobile")
|
|
126
|
+
this.closeMobileModal();
|
|
127
|
+
else
|
|
128
|
+
this.closeDropdown();
|
|
129
|
+
}
|
|
116
130
|
const shadow = this.shadowRoot;
|
|
117
131
|
const dialogs = shadow.querySelectorAll("dialog");
|
|
118
132
|
dialogs.forEach((dialog) => {
|
|
@@ -121,7 +135,7 @@ dialog.close();
|
|
|
121
135
|
}
|
|
122
136
|
});
|
|
123
137
|
if (this._keyboardHandler) {
|
|
124
|
-
document.removeEventListener("keydown", this._keyboardHandler);
|
|
138
|
+
document.removeEventListener("keydown", this._keyboardHandler, true);
|
|
125
139
|
this._keyboardHandler = null;
|
|
126
140
|
}
|
|
127
141
|
if (this._searchDebounceTimer !== null) {
|
|
@@ -178,8 +192,8 @@ break;
|
|
|
178
192
|
case "required":
|
|
179
193
|
this._required = newValue;
|
|
180
194
|
break;
|
|
181
|
-
case "
|
|
182
|
-
this._clearable = newValue;
|
|
195
|
+
case "noClear":
|
|
196
|
+
this._clearable = !newValue;
|
|
183
197
|
if (this.isConnected && this.shadowRoot)
|
|
184
198
|
this.updateSelectionDisplay();
|
|
185
199
|
break;
|
|
@@ -250,8 +264,26 @@ formData.append(this._name, value);
|
|
|
250
264
|
});
|
|
251
265
|
return formData;
|
|
252
266
|
}
|
|
267
|
+
if (this._name && !this._multiple)
|
|
268
|
+
return "";
|
|
253
269
|
return null;
|
|
254
270
|
}
|
|
271
|
+
focus(options) {
|
|
272
|
+
if (this._disabled)
|
|
273
|
+
return;
|
|
274
|
+
const trigger = this.querySelector(':scope > [slot="trigger"]');
|
|
275
|
+
if (trigger) {
|
|
276
|
+
trigger.focus(options);
|
|
277
|
+
const active = trigger.getRootNode().activeElement;
|
|
278
|
+
if (active && trigger.contains(active))
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
282
|
+
if (stub)
|
|
283
|
+
stub.focus(options);
|
|
284
|
+
else
|
|
285
|
+
super.focus(options);
|
|
286
|
+
}
|
|
255
287
|
parseValue(value) {
|
|
256
288
|
if (!value || typeof value !== "string" || value.trim() === "")
|
|
257
289
|
return [];
|
|
@@ -292,6 +324,11 @@ this.resolveDeclarativeSelection(); }, { once: true });
|
|
|
292
324
|
getTagElements() {
|
|
293
325
|
return Array.from(this.querySelectorAll("ty-option:not([cloned]), ty-tag:not([cloned])"));
|
|
294
326
|
}
|
|
327
|
+
getOfferedTags() {
|
|
328
|
+
return this.getTagElements()
|
|
329
|
+
.filter((el) => !el.hasAttribute("hidden"))
|
|
330
|
+
.map((el) => this.getTagData(el));
|
|
331
|
+
}
|
|
295
332
|
getTagData(element) {
|
|
296
333
|
const value = element.value ||
|
|
297
334
|
element.getAttribute("value") ||
|
|
@@ -333,7 +370,7 @@ if (!tag.hasAttribute("aria-selected"))
|
|
|
333
370
|
tag.setAttribute("aria-selected", "false");
|
|
334
371
|
});
|
|
335
372
|
}
|
|
336
|
-
updateComponentValue(newValues, dispatchChange = false, action = "set", item = null) {
|
|
373
|
+
updateComponentValue(newValues, dispatchChange = false, action = "set", item = null, reveal = dispatchChange) {
|
|
337
374
|
const oldValues = this.getSelectedValues();
|
|
338
375
|
const valueStr = newValues.join(",");
|
|
339
376
|
if (JSON.stringify(newValues.sort()) !== JSON.stringify(oldValues.sort())) {
|
|
@@ -347,6 +384,8 @@ items: this.getSelectedItems(newValues),
|
|
|
347
384
|
action,
|
|
348
385
|
item,
|
|
349
386
|
});
|
|
387
|
+
if (reveal)
|
|
388
|
+
this.revealValidity();
|
|
350
389
|
}
|
|
351
390
|
}
|
|
352
391
|
}
|
|
@@ -456,8 +495,7 @@ chevron.classList.add("open");
|
|
|
456
495
|
const searchChevron = shadow.querySelector(".dropdown-search-chevron");
|
|
457
496
|
if (searchChevron)
|
|
458
497
|
searchChevron.classList.add("open");
|
|
459
|
-
|
|
460
|
-
this._state.filteredTags = tags;
|
|
498
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
461
499
|
this._state.highlightedIndex = -1;
|
|
462
500
|
this.updateOptionsVisibility(true);
|
|
463
501
|
this._setupOptionsScrollbar();
|
|
@@ -509,7 +547,7 @@ this.fireSearchEvent("");
|
|
|
509
547
|
}
|
|
510
548
|
else {
|
|
511
549
|
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
512
|
-
this._state.filteredTags =
|
|
550
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
513
551
|
this.updateTagVisibility(allTags, allTags);
|
|
514
552
|
this.clearHighlights(allTags);
|
|
515
553
|
}
|
|
@@ -531,7 +569,7 @@ dialog.getBoundingClientRect();
|
|
|
531
569
|
dialog.classList.add("open");
|
|
532
570
|
this._state.open = true;
|
|
533
571
|
const tags = this.getTagElements().map((el) => this.getTagData(el));
|
|
534
|
-
this._state.filteredTags =
|
|
572
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
535
573
|
this.updateTagVisibility(tags, tags);
|
|
536
574
|
requestAnimationFrame(() => {
|
|
537
575
|
this.updateMobileSelectedState();
|
|
@@ -571,7 +609,7 @@ this.fireSearchEvent("");
|
|
|
571
609
|
}
|
|
572
610
|
else {
|
|
573
611
|
const allTags = this.getTagElements();
|
|
574
|
-
allTags.forEach((el) => el.removeAttribute("
|
|
612
|
+
allTags.forEach((el) => el.removeAttribute("filtered-out"));
|
|
575
613
|
}
|
|
576
614
|
this.fireCloseEvent();
|
|
577
615
|
}
|
|
@@ -590,6 +628,7 @@ if (this._disabled || this._readonly) {
|
|
|
590
628
|
return;
|
|
591
629
|
}
|
|
592
630
|
this.clear();
|
|
631
|
+
this.revealValidity();
|
|
593
632
|
}
|
|
594
633
|
handleStubKeydown(e) {
|
|
595
634
|
if (this._disabled || this._readonly || this._state.open)
|
|
@@ -690,7 +729,7 @@ desktopInput.value = "";
|
|
|
690
729
|
if (mobileInput)
|
|
691
730
|
mobileInput.value = "";
|
|
692
731
|
const allTags = this.getTagElements().map((el) => this.getTagData(el));
|
|
693
|
-
this._state.filteredTags =
|
|
732
|
+
this._state.filteredTags = this.getOfferedTags();
|
|
694
733
|
this.updateTagVisibility(allTags, allTags);
|
|
695
734
|
this.updateOptionsVisibility(true);
|
|
696
735
|
this.clearHighlights(allTags);
|
|
@@ -711,7 +750,7 @@ if (this._externalSearch) {
|
|
|
711
750
|
this.dispatchSearchEvent(query);
|
|
712
751
|
return;
|
|
713
752
|
}
|
|
714
|
-
const allTags = this.
|
|
753
|
+
const allTags = this.getOfferedTags();
|
|
715
754
|
const filtered = this.filterTags(allTags, query);
|
|
716
755
|
this._state.filteredTags = filtered;
|
|
717
756
|
this._state.highlightedIndex = -1;
|
|
@@ -742,6 +781,7 @@ this.closeMobileModal();
|
|
|
742
781
|
else {
|
|
743
782
|
this.closeDropdown();
|
|
744
783
|
}
|
|
784
|
+
this.focus();
|
|
745
785
|
break;
|
|
746
786
|
case "Enter":
|
|
747
787
|
e.preventDefault();
|
|
@@ -778,7 +818,8 @@ let index = fromIndex === -1
|
|
|
778
818
|
? (direction === 1 ? 0 : count - 1)
|
|
779
819
|
: (fromIndex + direction + count) % count;
|
|
780
820
|
for (let i = 0; i < count; i++) {
|
|
781
|
-
|
|
821
|
+
const el = tags[index].element;
|
|
822
|
+
if (!el.hasAttribute("disabled") && !el.hasAttribute("hidden") && !el.hasAttribute("filtered-out"))
|
|
782
823
|
return index;
|
|
783
824
|
index = (index + direction + count) % count;
|
|
784
825
|
}
|
|
@@ -794,12 +835,7 @@ return tags.filter(({ text }) => text.toLowerCase().includes(searchLower));
|
|
|
794
835
|
updateTagVisibility(filteredTags, allTags) {
|
|
795
836
|
const visibleValues = new Set(filteredTags.map((tag) => tag.value));
|
|
796
837
|
allTags.forEach(({ value, element }) => {
|
|
797
|
-
|
|
798
|
-
element.removeAttribute("hidden");
|
|
799
|
-
}
|
|
800
|
-
else {
|
|
801
|
-
element.setAttribute("hidden", "");
|
|
802
|
-
}
|
|
838
|
+
element.toggleAttribute("filtered-out", !visibleValues.has(value));
|
|
803
839
|
});
|
|
804
840
|
}
|
|
805
841
|
updateOptionsVisibility(hasOptions) {
|
|
@@ -881,19 +917,108 @@ this.renderDesktop();
|
|
|
881
917
|
}
|
|
882
918
|
this.updateSearchVisibility();
|
|
883
919
|
this.applyLoadingState();
|
|
920
|
+
this.syncFieldChrome();
|
|
884
921
|
this.updateValidity();
|
|
885
922
|
}
|
|
923
|
+
syncFieldChrome() {
|
|
924
|
+
const shadow = this.shadowRoot;
|
|
925
|
+
const container = shadow?.querySelector(".select-container");
|
|
926
|
+
if (!shadow || !container)
|
|
927
|
+
return;
|
|
928
|
+
const labelId = `select-label-${getElementHash(this)}`;
|
|
929
|
+
let label = container.querySelector(":scope > .ty-field-label");
|
|
930
|
+
if (this._label) {
|
|
931
|
+
if (!label) {
|
|
932
|
+
label = document.createElement("label");
|
|
933
|
+
label.className = "ty-field-label";
|
|
934
|
+
label.id = labelId;
|
|
935
|
+
container.prepend(label);
|
|
936
|
+
}
|
|
937
|
+
label.innerHTML = `${this._label}${this._required ? `<span class="required-icon">${REQUIRED_ICON_SVG}</span>` : ""}`;
|
|
938
|
+
}
|
|
939
|
+
else {
|
|
940
|
+
label?.remove();
|
|
941
|
+
}
|
|
942
|
+
const error = this.getProperty("error") || "";
|
|
943
|
+
const errorId = `select-error-${getElementHash(this)}`;
|
|
944
|
+
let errorLine = container.querySelector(":scope > .error-message");
|
|
945
|
+
if (error) {
|
|
946
|
+
if (!errorLine) {
|
|
947
|
+
errorLine = document.createElement("div");
|
|
948
|
+
errorLine.className = "error-message";
|
|
949
|
+
errorLine.id = errorId;
|
|
950
|
+
container.append(errorLine);
|
|
951
|
+
}
|
|
952
|
+
errorLine.textContent = error;
|
|
953
|
+
}
|
|
954
|
+
else {
|
|
955
|
+
errorLine?.remove();
|
|
956
|
+
}
|
|
957
|
+
const stub = shadow.querySelector(".select-stub");
|
|
958
|
+
if (stub) {
|
|
959
|
+
stub.classList.toggle("disabled", this._disabled);
|
|
960
|
+
stub.classList.toggle("compact", this._compact);
|
|
961
|
+
stub.classList.toggle("error", !!error);
|
|
962
|
+
stub.tabIndex = this._disabled ? -1 : 0;
|
|
963
|
+
stub.toggleAttribute("disabled", this._disabled);
|
|
964
|
+
if (this._disabled)
|
|
965
|
+
stub.setAttribute("aria-disabled", "true");
|
|
966
|
+
else
|
|
967
|
+
stub.removeAttribute("aria-disabled");
|
|
968
|
+
if (this._label)
|
|
969
|
+
stub.setAttribute("aria-labelledby", labelId);
|
|
970
|
+
else
|
|
971
|
+
stub.removeAttribute("aria-labelledby");
|
|
972
|
+
if (error) {
|
|
973
|
+
stub.setAttribute("aria-invalid", "true");
|
|
974
|
+
stub.setAttribute("aria-describedby", errorId);
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
stub.removeAttribute("aria-invalid");
|
|
978
|
+
stub.removeAttribute("aria-describedby");
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
this.syncTriggerAria();
|
|
982
|
+
shadow
|
|
983
|
+
.querySelectorAll(".dropdown-search-input, .mobile-search-input")
|
|
984
|
+
.forEach((input) => (input.disabled = this._disabled));
|
|
985
|
+
}
|
|
986
|
+
syncTriggerAria() {
|
|
987
|
+
const error = this.getProperty("error") || "";
|
|
988
|
+
const trigger = error
|
|
989
|
+
? this.querySelector(':scope > [slot="trigger"]')
|
|
990
|
+
: null;
|
|
991
|
+
if (this._ariaTrigger && this._ariaTrigger !== trigger) {
|
|
992
|
+
this._ariaTrigger.removeAttribute("aria-invalid");
|
|
993
|
+
this._ariaTrigger.removeAttribute("aria-description");
|
|
994
|
+
}
|
|
995
|
+
if (trigger) {
|
|
996
|
+
if (trigger.getAttribute("aria-invalid") !== "true")
|
|
997
|
+
trigger.setAttribute("aria-invalid", "true");
|
|
998
|
+
if (trigger.getAttribute("aria-description") !== error)
|
|
999
|
+
trigger.setAttribute("aria-description", error);
|
|
1000
|
+
}
|
|
1001
|
+
this._ariaTrigger = trigger;
|
|
1002
|
+
this._ariaObserver ?? (this._ariaObserver = new MutationObserver(() => this.syncTriggerAria()));
|
|
1003
|
+
this._ariaObserver.disconnect();
|
|
1004
|
+
if (trigger) {
|
|
1005
|
+
this._ariaObserver.observe(trigger, {
|
|
1006
|
+
attributes: true,
|
|
1007
|
+
attributeFilter: ["aria-invalid", "aria-description"],
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
886
1011
|
updateValidity() {
|
|
887
1012
|
if (this.disabled) {
|
|
888
|
-
this.
|
|
1013
|
+
this.applyValidity({});
|
|
889
1014
|
return;
|
|
890
1015
|
}
|
|
891
1016
|
if (this.required && this.getSelectedValues().length === 0) {
|
|
892
1017
|
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
893
|
-
this.
|
|
1018
|
+
this.applyValidity({ valueMissing: true }, nativeMessage("select", { required: true, multiple: this._multiple }), stub ?? undefined);
|
|
894
1019
|
}
|
|
895
1020
|
else {
|
|
896
|
-
this.
|
|
1021
|
+
this.applyValidity({});
|
|
897
1022
|
}
|
|
898
1023
|
}
|
|
899
1024
|
setupTriggerSlot() {
|
|
@@ -907,7 +1032,10 @@ const hasTrigger = slot.assignedElements().length > 0;
|
|
|
907
1032
|
stub.classList.toggle("custom-trigger", hasTrigger);
|
|
908
1033
|
this.toggleAttribute("has-trigger", hasTrigger);
|
|
909
1034
|
};
|
|
910
|
-
slot.addEventListener("slotchange",
|
|
1035
|
+
slot.addEventListener("slotchange", () => {
|
|
1036
|
+
sync();
|
|
1037
|
+
this.syncFieldChrome();
|
|
1038
|
+
});
|
|
911
1039
|
sync();
|
|
912
1040
|
}
|
|
913
1041
|
setupEventListeners() {
|
|
@@ -940,9 +1068,13 @@ if (e.target === dialog) {
|
|
|
940
1068
|
this.closeDropdown();
|
|
941
1069
|
}
|
|
942
1070
|
});
|
|
1071
|
+
dialog.addEventListener("cancel", (e) => {
|
|
1072
|
+
e.preventDefault();
|
|
1073
|
+
this.closeDropdown();
|
|
1074
|
+
this.focus();
|
|
1075
|
+
});
|
|
1076
|
+
this.syncOnOutsideClose(dialog, () => this.closeDropdown());
|
|
943
1077
|
}
|
|
944
|
-
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
945
|
-
document.addEventListener("keydown", this._keyboardHandler);
|
|
946
1078
|
}
|
|
947
1079
|
buildStubClasses() {
|
|
948
1080
|
const classes = [];
|
|
@@ -1111,7 +1243,7 @@ ${CHEVRON_DOWN_SVG}
|
|
|
1111
1243
|
<!-- AVAILABLE LIST (always visible, takes remaining space) -->
|
|
1112
1244
|
<div class="mobile-available-section" data-empty="false">
|
|
1113
1245
|
<button class="section-header" type="button" data-section="available" aria-expanded="true">
|
|
1114
|
-
<span class="section-title">${this._availableLabel}
|
|
1246
|
+
<span class="section-title">${this._availableLabel} <span class="section-count"></span></span>
|
|
1115
1247
|
${CHEVRON_DOWN_SVG}
|
|
1116
1248
|
</button>
|
|
1117
1249
|
<div class="section-content dropdown-options-wrapper" id="${listboxId}" role="listbox" ${this._multiple ? 'aria-multiselectable="true"' : ""}>
|
|
@@ -1136,10 +1268,6 @@ this.setupMobileEventListeners();
|
|
|
1136
1268
|
this.updateSelectionDisplay();
|
|
1137
1269
|
}
|
|
1138
1270
|
setupMobileEventListeners() {
|
|
1139
|
-
if (!this._keyboardHandler) {
|
|
1140
|
-
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
1141
|
-
document.addEventListener("keydown", this._keyboardHandler);
|
|
1142
|
-
}
|
|
1143
1271
|
const shadow = this.shadowRoot;
|
|
1144
1272
|
const stub = shadow.querySelector(".select-stub");
|
|
1145
1273
|
const optionsSlot = shadow.querySelector("#options-slot");
|
|
@@ -1174,8 +1302,16 @@ this.closeMobileModal();
|
|
|
1174
1302
|
dialog.addEventListener("cancel", (e) => {
|
|
1175
1303
|
e.preventDefault();
|
|
1176
1304
|
this.closeMobileModal();
|
|
1305
|
+
this.focus();
|
|
1177
1306
|
});
|
|
1307
|
+
this.syncOnOutsideClose(dialog, () => this.closeMobileModal());
|
|
1308
|
+
}
|
|
1178
1309
|
}
|
|
1310
|
+
syncOnOutsideClose(dialog, close) {
|
|
1311
|
+
new MutationObserver(() => {
|
|
1312
|
+
if (this._state.open && !dialog.open)
|
|
1313
|
+
close();
|
|
1314
|
+
}).observe(dialog, { attributes: true, attributeFilter: ["open"] });
|
|
1179
1315
|
}
|
|
1180
1316
|
handleMobileStubClick(e) {
|
|
1181
1317
|
e.preventDefault();
|
|
@@ -1203,13 +1339,19 @@ const shadow = this.shadowRoot;
|
|
|
1203
1339
|
this.renderMobileSelectedChips();
|
|
1204
1340
|
const availableSection = shadow.querySelector(".mobile-available-section");
|
|
1205
1341
|
if (availableSection) {
|
|
1206
|
-
const visibleAvailable = this.
|
|
1342
|
+
const visibleAvailable = this.getOfferedTags().filter(({ element }) => !element.hasAttribute("filtered-out") && !element.hasAttribute("selected")).length;
|
|
1207
1343
|
availableSection.setAttribute("data-empty", String(visibleAvailable === 0));
|
|
1208
|
-
|
|
1209
|
-
if (availableTitleSpan) {
|
|
1210
|
-
availableTitleSpan.textContent = `${this._availableLabel} (${visibleAvailable})`;
|
|
1344
|
+
this.setMobileSectionTitle(availableSection, this._availableLabel, visibleAvailable);
|
|
1211
1345
|
}
|
|
1212
1346
|
}
|
|
1347
|
+
setMobileSectionTitle(section, label, n) {
|
|
1348
|
+
const title = section.querySelector(".section-title");
|
|
1349
|
+
if (!title)
|
|
1350
|
+
return;
|
|
1351
|
+
const count = document.createElement("span");
|
|
1352
|
+
count.className = "section-count";
|
|
1353
|
+
count.textContent = `(${n})`;
|
|
1354
|
+
title.replaceChildren(`${label} `, count);
|
|
1213
1355
|
}
|
|
1214
1356
|
expandMobileSection(section) {
|
|
1215
1357
|
const shadow = this.shadowRoot;
|
|
@@ -1232,9 +1374,7 @@ if (!section || !host)
|
|
|
1232
1374
|
return;
|
|
1233
1375
|
const selected = this._state.selectedValues;
|
|
1234
1376
|
section.setAttribute("data-empty", String(selected.length === 0));
|
|
1235
|
-
|
|
1236
|
-
if (count)
|
|
1237
|
-
count.textContent = `(${selected.length})`;
|
|
1377
|
+
this.setMobileSectionTitle(section, this._selectedLabel, selected.length);
|
|
1238
1378
|
if (selected.length === 0)
|
|
1239
1379
|
this.expandMobileSection("available");
|
|
1240
1380
|
const labelFor = (value) => {
|
|
@@ -1344,6 +1484,8 @@ const option = this.getTagElements().find((el) => this.getTagData(el).value ===
|
|
|
1344
1484
|
if (option) {
|
|
1345
1485
|
const clone = option.cloneNode(true);
|
|
1346
1486
|
clone.removeAttribute("selected");
|
|
1487
|
+
clone.removeAttribute("hidden");
|
|
1488
|
+
clone.removeAttribute("filtered-out");
|
|
1347
1489
|
clone.setAttribute("slot", "selected");
|
|
1348
1490
|
clone.setAttribute("cloned", "true");
|
|
1349
1491
|
this.appendChild(clone);
|
|
@@ -1366,7 +1508,7 @@ return;
|
|
|
1366
1508
|
this.updateComponentValue(current.filter((v) => v !== value), true, "remove", value);
|
|
1367
1509
|
}
|
|
1368
1510
|
clear() {
|
|
1369
|
-
this.updateComponentValue([], true, "clear", null);
|
|
1511
|
+
this.updateComponentValue([], true, "clear", null, false);
|
|
1370
1512
|
}
|
|
1371
1513
|
get value() {
|
|
1372
1514
|
return this.getSelectedValues().join(",");
|
|
@@ -1422,11 +1564,11 @@ return this.getProperty("readonly");
|
|
|
1422
1564
|
set readonly(value) {
|
|
1423
1565
|
this.setProperty("readonly", value);
|
|
1424
1566
|
}
|
|
1425
|
-
get
|
|
1426
|
-
return this.getProperty("
|
|
1567
|
+
get noClear() {
|
|
1568
|
+
return this.getProperty("noClear");
|
|
1427
1569
|
}
|
|
1428
|
-
set
|
|
1429
|
-
this.setProperty("
|
|
1570
|
+
set noClear(value) {
|
|
1571
|
+
this.setProperty("noClear", value);
|
|
1430
1572
|
}
|
|
1431
1573
|
get required() {
|
|
1432
1574
|
return this.getProperty("required");
|
|
@@ -1434,6 +1576,12 @@ return this.getProperty("required");
|
|
|
1434
1576
|
set required(value) {
|
|
1435
1577
|
this.setProperty("required", value);
|
|
1436
1578
|
}
|
|
1579
|
+
get error() {
|
|
1580
|
+
return this.getProperty("error");
|
|
1581
|
+
}
|
|
1582
|
+
set error(value) {
|
|
1583
|
+
this.setProperty("error", value);
|
|
1584
|
+
}
|
|
1437
1585
|
get notSearchable() {
|
|
1438
1586
|
return this.getProperty("notSearchable");
|
|
1439
1587
|
}
|
|
@@ -1537,11 +1685,15 @@ type: "boolean",
|
|
|
1537
1685
|
visual: true,
|
|
1538
1686
|
default: false,
|
|
1539
1687
|
},
|
|
1540
|
-
|
|
1688
|
+
error: {
|
|
1689
|
+
type: "string",
|
|
1690
|
+
visual: true,
|
|
1691
|
+
default: "",
|
|
1692
|
+
},
|
|
1693
|
+
noClear: {
|
|
1541
1694
|
type: "boolean",
|
|
1542
1695
|
visual: true,
|
|
1543
|
-
default:
|
|
1544
|
-
aliases: { "not-clearable": false },
|
|
1696
|
+
default: false,
|
|
1545
1697
|
},
|
|
1546
1698
|
externalSearch: {
|
|
1547
1699
|
type: "boolean",
|
|
@@ -28,6 +28,8 @@ export declare class TySelectedOptions extends HTMLElement {
|
|
|
28
28
|
* Interpolation context for a value: value, label, flavor plus every
|
|
29
29
|
* data-* attribute of the picker's matching option.
|
|
30
30
|
*/
|
|
31
|
+
/** The picker's option for a value (never its display clone). */
|
|
32
|
+
private option;
|
|
31
33
|
private context;
|
|
32
34
|
/**
|
|
33
35
|
* The template's blueprint fragment. HTML-parsed templates carry children in
|
|
@@ -42,7 +44,11 @@ export declare class TySelectedOptions extends HTMLElement {
|
|
|
42
44
|
* no flavor on the option).
|
|
43
45
|
*/
|
|
44
46
|
private stampTemplate;
|
|
45
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Default chip when no template is provided: the option's own content,
|
|
49
|
+
* cloned, so a rich option makes a rich chip. An explicit `label` on the
|
|
50
|
+
* option replaces it with that text; a <template> child replaces it entirely.
|
|
51
|
+
*/
|
|
46
52
|
private defaultChip;
|
|
47
53
|
private renderChips;
|
|
48
54
|
/** Remove a value from the picker; picker re-emits change → chips re-render. */
|
|
@@ -93,8 +93,11 @@ return parseValues(this._picker?.value ?? '');
|
|
|
93
93
|
template() {
|
|
94
94
|
return this.querySelector(':scope > template');
|
|
95
95
|
}
|
|
96
|
+
option(value) {
|
|
97
|
+
return this._picker?.querySelector(`[value="${CSS.escape(value)}"]:not([cloned])`);
|
|
98
|
+
}
|
|
96
99
|
context(value) {
|
|
97
|
-
const opt = this.
|
|
100
|
+
const opt = this.option(value);
|
|
98
101
|
const ctx = {
|
|
99
102
|
value,
|
|
100
103
|
label: opt?.getAttribute('label') || opt?.textContent?.trim() || value,
|
|
@@ -150,12 +153,18 @@ return clone;
|
|
|
150
153
|
}
|
|
151
154
|
defaultChip(value) {
|
|
152
155
|
const ctx = this.context(value);
|
|
156
|
+
const opt = this.option(value);
|
|
153
157
|
const tag = document.createElement('ty-tag');
|
|
154
158
|
tag.setAttribute('value', value);
|
|
155
159
|
tag.setAttribute('dismissible', 'true');
|
|
156
160
|
if (ctx.flavor)
|
|
157
161
|
tag.setAttribute('flavor', ctx.flavor);
|
|
162
|
+
if (opt && !opt.hasAttribute('label') && opt.hasChildNodes()) {
|
|
163
|
+
opt.childNodes.forEach(n => tag.appendChild(n.cloneNode(true)));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
158
166
|
tag.textContent = ctx.label;
|
|
167
|
+
}
|
|
159
168
|
tag.addEventListener('dismiss', () => this.deselect(value));
|
|
160
169
|
return tag;
|
|
161
170
|
}
|
|
@@ -24,6 +24,8 @@ export interface TySwitchElement extends HTMLElement {
|
|
|
24
24
|
}
|
|
25
25
|
export declare class TySwitch extends TyComponent<SwitchState> implements TySwitchElement {
|
|
26
26
|
static formAssociated: boolean;
|
|
27
|
+
protected static delegatesFocus: boolean;
|
|
28
|
+
protected static labelClicks: boolean;
|
|
27
29
|
protected static properties: {
|
|
28
30
|
checked: {
|
|
29
31
|
type: "boolean";
|
|
@@ -78,11 +80,17 @@ export declare class TySwitch extends TyComponent<SwitchState> implements TySwit
|
|
|
78
80
|
protected getFormValue(): FormDataEntryValue | null;
|
|
79
81
|
private buildClassList;
|
|
80
82
|
private handleSwitchClick;
|
|
83
|
+
/** Keys show the ring, a click hides it (see checkbox.ts). */
|
|
84
|
+
private showFocusRing;
|
|
81
85
|
private handleSwitchKeydown;
|
|
82
86
|
private removeEventListeners;
|
|
83
87
|
private setupEventListeners;
|
|
84
88
|
protected render(): void;
|
|
85
|
-
/**
|
|
89
|
+
/** Focus the switch itself (the host is not focusable; its role element is). */
|
|
90
|
+
focus(options?: FocusOptions): void;
|
|
91
|
+
/** required + unchecked => valueMissing; otherwise valid. The message is a
|
|
92
|
+
* native checkbox's, as a switch where the browser has one (Safari's
|
|
93
|
+
* `switch` attribute). */
|
|
86
94
|
private updateValidity;
|
|
87
95
|
get checked(): boolean;
|
|
88
96
|
set checked(value: boolean);
|
package/lib/components/switch.js
CHANGED
|
@@ -3,6 +3,7 @@ import { TyComponent } from "../base/ty-component.js";
|
|
|
3
3
|
import { ensureStyles } from "../utils/styles.js";
|
|
4
4
|
import { syncCustomFlavorSheet } from "../utils/flavor-sheet.js";
|
|
5
5
|
import { switchStyles, switchCustomFlavorCss } from "../styles/switch.js";
|
|
6
|
+
import { nativeMessage } from "../utils/validity.js";
|
|
6
7
|
export class TySwitch extends TyComponent {
|
|
7
8
|
constructor() {
|
|
8
9
|
super();
|
|
@@ -18,6 +19,9 @@ ensureStyles(shadow, { css: switchStyles, id: "ty-switch" });
|
|
|
18
19
|
onConnect() {
|
|
19
20
|
this.setupEventListeners();
|
|
20
21
|
this._syncCustomFlavor();
|
|
22
|
+
const el = this.shadowRoot.querySelector(".switch-container");
|
|
23
|
+
if (el && this.shadowRoot.activeElement !== el)
|
|
24
|
+
el.classList.remove("focused");
|
|
21
25
|
}
|
|
22
26
|
onDisconnect() {
|
|
23
27
|
this.removeEventListeners();
|
|
@@ -44,8 +48,7 @@ return classes.join(" ");
|
|
|
44
48
|
handleSwitchClick(e) {
|
|
45
49
|
if (this.disabled)
|
|
46
50
|
return;
|
|
47
|
-
|
|
48
|
-
return;
|
|
51
|
+
this.showFocusRing(e instanceof KeyboardEvent);
|
|
49
52
|
const newValue = !this.checked;
|
|
50
53
|
this.checked = newValue;
|
|
51
54
|
setTimeout(() => {
|
|
@@ -59,6 +62,9 @@ this.dispatchEvent(new CustomEvent("input", { detail: eventDetail, bubbles: true
|
|
|
59
62
|
this.dispatchEvent(new CustomEvent("change", { detail: eventDetail, bubbles: true, composed: true }));
|
|
60
63
|
}, 0);
|
|
61
64
|
}
|
|
65
|
+
showFocusRing(on) {
|
|
66
|
+
this.shadowRoot?.querySelector(".switch-container")?.classList.toggle("focused", on);
|
|
67
|
+
}
|
|
62
68
|
handleSwitchKeydown(e) {
|
|
63
69
|
if (this.disabled)
|
|
64
70
|
return;
|
|
@@ -106,7 +112,7 @@ if (!el)
|
|
|
106
112
|
return;
|
|
107
113
|
this._clickHandler = (e) => this.handleSwitchClick(e);
|
|
108
114
|
this._keydownHandler = (e) => this.handleSwitchKeydown(e);
|
|
109
|
-
this._focusHandler = () => el.classList.
|
|
115
|
+
this._focusHandler = () => el.classList.toggle("focused", el.matches(":focus-visible"));
|
|
110
116
|
this._blurHandler = () => el.classList.remove("focused");
|
|
111
117
|
this.addEventListener("click", this._clickHandler);
|
|
112
118
|
el.addEventListener("keydown", this._keydownHandler);
|
|
@@ -121,7 +127,8 @@ const classes = this.buildClassList();
|
|
|
121
127
|
if (!switchEl) {
|
|
122
128
|
switchEl = document.createElement("div");
|
|
123
129
|
switchEl.className = "switch-container " + classes;
|
|
124
|
-
|
|
130
|
+
if (!this.disabled)
|
|
131
|
+
switchEl.tabIndex = 0;
|
|
125
132
|
switchEl.setAttribute("role", "switch");
|
|
126
133
|
switchEl.setAttribute("aria-checked", this.checked ? "true" : "false");
|
|
127
134
|
switchEl.setAttribute("aria-disabled", this.disabled ? "true" : "false");
|
|
@@ -135,8 +142,13 @@ switchEl.appendChild(track);
|
|
|
135
142
|
shadow.appendChild(switchEl);
|
|
136
143
|
}
|
|
137
144
|
else {
|
|
145
|
+
const focused = switchEl.classList.contains("focused") && shadow.activeElement === switchEl;
|
|
138
146
|
switchEl.className = "switch-container " + classes;
|
|
139
|
-
switchEl.
|
|
147
|
+
switchEl.classList.toggle("focused", focused && !this.disabled);
|
|
148
|
+
if (this.disabled)
|
|
149
|
+
switchEl.removeAttribute("tabindex");
|
|
150
|
+
else
|
|
151
|
+
switchEl.tabIndex = 0;
|
|
140
152
|
switchEl.setAttribute("aria-checked", this.checked ? "true" : "false");
|
|
141
153
|
switchEl.setAttribute("aria-disabled", this.disabled ? "true" : "false");
|
|
142
154
|
switchEl.setAttribute("aria-required", this.required ? "true" : "false");
|
|
@@ -145,17 +157,24 @@ this.setupEventListeners();
|
|
|
145
157
|
this.applyLabelName(switchEl);
|
|
146
158
|
this.updateValidity();
|
|
147
159
|
}
|
|
160
|
+
focus(options) {
|
|
161
|
+
const el = this.shadowRoot?.querySelector(".switch-container");
|
|
162
|
+
if (el)
|
|
163
|
+
el.focus(options);
|
|
164
|
+
else
|
|
165
|
+
super.focus(options);
|
|
166
|
+
}
|
|
148
167
|
updateValidity() {
|
|
149
168
|
const anchor = this.shadowRoot?.querySelector(".switch-container");
|
|
150
169
|
if (this.disabled) {
|
|
151
|
-
this.
|
|
170
|
+
this.applyValidity({});
|
|
152
171
|
return;
|
|
153
172
|
}
|
|
154
173
|
if (this.required && !this.checked) {
|
|
155
|
-
this.
|
|
174
|
+
this.applyValidity({ valueMissing: true }, nativeMessage("input", { type: "checkbox", switch: true, required: true }), anchor ?? undefined);
|
|
156
175
|
}
|
|
157
176
|
else {
|
|
158
|
-
this.
|
|
177
|
+
this.applyValidity({});
|
|
159
178
|
}
|
|
160
179
|
}
|
|
161
180
|
get checked() { return this.getProperty("checked"); }
|
|
@@ -175,6 +194,8 @@ set flavor(value) { this.setProperty("flavor", value); }
|
|
|
175
194
|
get form() { return this._internals.form; }
|
|
176
195
|
}
|
|
177
196
|
TySwitch.formAssociated = true;
|
|
197
|
+
TySwitch.delegatesFocus = true;
|
|
198
|
+
TySwitch.labelClicks = true;
|
|
178
199
|
TySwitch.properties = {
|
|
179
200
|
checked: {
|
|
180
201
|
type: "boolean",
|