tyrell-components 1.0.0-RC16 → 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/css/tyrell-colors-static.css +14 -0
- package/css/tyrell-theme.css +6 -5
- package/css/tyrell.css +9 -7
- package/dist/tyrell-colors-static.css +1 -1
- package/dist/tyrell-theme.css +1 -1
- package/dist/tyrell.js +1 -1
- package/lib/base/ty-component.d.ts +23 -15
- package/lib/base/ty-component.js +63 -26
- package/lib/components/button.d.ts +14 -0
- package/lib/components/button.js +55 -7
- package/lib/components/calendar-month.d.ts +7 -1
- package/lib/components/calendar-month.js +35 -28
- package/lib/components/calendar-navigation.js +19 -6
- package/lib/components/calendar.d.ts +26 -3
- package/lib/components/calendar.js +104 -64
- package/lib/components/checkbox.d.ts +8 -1
- package/lib/components/checkbox.js +27 -6
- package/lib/components/copy.d.ts +2 -0
- package/lib/components/copy.js +15 -31
- package/lib/components/date-picker.d.ts +53 -18
- package/lib/components/date-picker.js +217 -146
- package/lib/components/file-upload.d.ts +4 -1
- package/lib/components/file-upload.js +23 -5
- package/lib/components/input.d.ts +73 -3
- package/lib/components/input.js +157 -22
- package/lib/components/modal.d.ts +2 -0
- package/lib/components/modal.js +97 -17
- package/lib/components/option.js +7 -5
- package/lib/components/popup.js +115 -15
- package/lib/components/radio.d.ts +10 -1
- package/lib/components/radio.js +22 -29
- package/lib/components/resize-observer.js +2 -0
- package/lib/components/scroll-container.js +2 -0
- package/lib/components/select.d.ts +54 -5
- package/lib/components/select.js +136 -26
- 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 +27 -6
- package/lib/components/tabs.js +1 -1
- package/lib/components/textarea.d.ts +47 -2
- package/lib/components/textarea.js +81 -17
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/styles/button.js +21 -19
- package/lib/styles/calendar-month.js +1 -1
- package/lib/styles/calendar.js +3 -0
- package/lib/styles/checkbox.js +11 -5
- package/lib/styles/date-picker.js +16 -4
- 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 +4 -0
- package/lib/styles/popup.d.ts +1 -1
- package/lib/styles/popup.js +2 -0
- package/lib/styles/radio.js +12 -6
- package/lib/styles/select-base.js +24 -3
- package/lib/styles/select.d.ts +1 -1
- package/lib/styles/select.js +4 -0
- package/lib/styles/switch.js +10 -5
- package/lib/styles/tag.js +2 -1
- package/lib/styles/textarea.d.ts +1 -1
- package/lib/styles/textarea.js +7 -0
- package/lib/utils/calendar-utils.d.ts +49 -0
- package/lib/utils/calendar-utils.js +63 -6
- package/lib/utils/property-manager.d.ts +6 -0
- package/lib/utils/property-manager.js +15 -5
- 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 +98 -2
- package/lib/utils/validity.js +244 -8
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -2
- package/lib/base/ty-component.d.ts.map +0 -1
- package/lib/base/ty-component.js.map +0 -1
- package/lib/components/button.d.ts.map +0 -1
- package/lib/components/button.js.map +0 -1
- package/lib/components/calendar-month.d.ts.map +0 -1
- package/lib/components/calendar-month.js.map +0 -1
- package/lib/components/calendar-navigation.d.ts.map +0 -1
- package/lib/components/calendar-navigation.js.map +0 -1
- package/lib/components/calendar.d.ts.map +0 -1
- package/lib/components/calendar.js.map +0 -1
- package/lib/components/checkbox.d.ts.map +0 -1
- package/lib/components/checkbox.js.map +0 -1
- package/lib/components/copy.d.ts.map +0 -1
- package/lib/components/copy.js.map +0 -1
- package/lib/components/date-picker.d.ts.map +0 -1
- package/lib/components/date-picker.js.map +0 -1
- package/lib/components/dropdown.d.ts +0 -403
- package/lib/components/dropdown.d.ts.map +0 -1
- package/lib/components/dropdown.js +0 -1315
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/icon.d.ts.map +0 -1
- package/lib/components/icon.js.map +0 -1
- package/lib/components/input.d.ts.map +0 -1
- package/lib/components/input.js.map +0 -1
- package/lib/components/modal.d.ts.map +0 -1
- package/lib/components/modal.js.map +0 -1
- package/lib/components/multiselect.d.ts +0 -389
- package/lib/components/multiselect.d.ts.map +0 -1
- package/lib/components/multiselect.js +0 -1301
- package/lib/components/multiselect.js.map +0 -1
- package/lib/components/option.d.ts.map +0 -1
- package/lib/components/option.js.map +0 -1
- package/lib/components/popup.d.ts.map +0 -1
- package/lib/components/popup.js.map +0 -1
- package/lib/components/resize-observer.d.ts.map +0 -1
- package/lib/components/resize-observer.js.map +0 -1
- package/lib/components/scroll-container.d.ts.map +0 -1
- package/lib/components/scroll-container.js.map +0 -1
- package/lib/components/step.d.ts.map +0 -1
- package/lib/components/step.js.map +0 -1
- package/lib/components/tab.d.ts.map +0 -1
- package/lib/components/tab.js.map +0 -1
- package/lib/components/tabs.d.ts.map +0 -1
- package/lib/components/tabs.js.map +0 -1
- package/lib/components/tag.d.ts.map +0 -1
- package/lib/components/tag.js.map +0 -1
- package/lib/components/textarea.d.ts.map +0 -1
- package/lib/components/textarea.js.map +0 -1
- package/lib/components/tooltip.d.ts.map +0 -1
- package/lib/components/tooltip.js.map +0 -1
- package/lib/components/wizard.d.ts.map +0 -1
- package/lib/components/wizard.js.map +0 -1
- package/lib/icons/fontawesome/brands.d.ts.map +0 -1
- package/lib/icons/fontawesome/brands.js.map +0 -1
- package/lib/icons/fontawesome/regular.d.ts.map +0 -1
- package/lib/icons/fontawesome/regular.js.map +0 -1
- package/lib/icons/fontawesome/solid.d.ts.map +0 -1
- package/lib/icons/fontawesome/solid.js.map +0 -1
- package/lib/icons/heroicons/micro.d.ts.map +0 -1
- package/lib/icons/heroicons/micro.js.map +0 -1
- package/lib/icons/heroicons/mini.d.ts.map +0 -1
- package/lib/icons/heroicons/mini.js.map +0 -1
- package/lib/icons/heroicons/outline.d.ts.map +0 -1
- package/lib/icons/heroicons/outline.js.map +0 -1
- package/lib/icons/heroicons/solid.d.ts.map +0 -1
- package/lib/icons/heroicons/solid.js.map +0 -1
- package/lib/icons/lucide.d.ts.map +0 -1
- package/lib/icons/lucide.js.map +0 -1
- package/lib/icons/material/filled.d.ts.map +0 -1
- package/lib/icons/material/filled.js.map +0 -1
- package/lib/icons/material/outlined.d.ts.map +0 -1
- package/lib/icons/material/outlined.js.map +0 -1
- package/lib/icons/material/round.d.ts.map +0 -1
- package/lib/icons/material/round.js.map +0 -1
- package/lib/icons/material/sharp.d.ts.map +0 -1
- package/lib/icons/material/sharp.js.map +0 -1
- package/lib/icons/material/two-tone.d.ts.map +0 -1
- package/lib/icons/material/two-tone.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/styles/button.d.ts.map +0 -1
- package/lib/styles/button.js.map +0 -1
- package/lib/styles/calendar-month.d.ts.map +0 -1
- package/lib/styles/calendar-month.js.map +0 -1
- package/lib/styles/calendar-navigation.d.ts.map +0 -1
- package/lib/styles/calendar-navigation.js.map +0 -1
- package/lib/styles/calendar.d.ts.map +0 -1
- package/lib/styles/calendar.js.map +0 -1
- package/lib/styles/copy.d.ts.map +0 -1
- package/lib/styles/copy.js.map +0 -1
- package/lib/styles/date-picker.d.ts.map +0 -1
- package/lib/styles/date-picker.js.map +0 -1
- package/lib/styles/dropdown.d.ts +0 -12
- package/lib/styles/dropdown.d.ts.map +0 -1
- package/lib/styles/dropdown.js +0 -725
- package/lib/styles/dropdown.js.map +0 -1
- package/lib/styles/icon.d.ts.map +0 -1
- package/lib/styles/icon.js.map +0 -1
- package/lib/styles/input.d.ts.map +0 -1
- package/lib/styles/input.js.map +0 -1
- package/lib/styles/modal.d.ts.map +0 -1
- package/lib/styles/modal.js.map +0 -1
- package/lib/styles/multiselect.d.ts +0 -6
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -568
- package/lib/styles/multiselect.js.map +0 -1
- package/lib/styles/option.d.ts.map +0 -1
- package/lib/styles/option.js.map +0 -1
- package/lib/styles/popup.d.ts.map +0 -1
- package/lib/styles/popup.js.map +0 -1
- package/lib/styles/resize-observer.d.ts.map +0 -1
- package/lib/styles/resize-observer.js.map +0 -1
- package/lib/styles/scroll-container.d.ts.map +0 -1
- package/lib/styles/scroll-container.js.map +0 -1
- package/lib/styles/step.d.ts.map +0 -1
- package/lib/styles/step.js.map +0 -1
- package/lib/styles/tab.d.ts.map +0 -1
- package/lib/styles/tab.js.map +0 -1
- package/lib/styles/tabs.d.ts.map +0 -1
- package/lib/styles/tabs.js.map +0 -1
- package/lib/styles/tag.d.ts.map +0 -1
- package/lib/styles/tag.js.map +0 -1
- package/lib/styles/textarea.d.ts.map +0 -1
- package/lib/styles/textarea.js.map +0 -1
- package/lib/styles/tooltip.d.ts.map +0 -1
- package/lib/styles/tooltip.js.map +0 -1
- package/lib/styles/wizard.d.ts.map +0 -1
- package/lib/styles/wizard.js.map +0 -1
- package/lib/types/common.d.ts.map +0 -1
- package/lib/types/common.js.map +0 -1
- package/lib/utils/calendar-utils.d.ts.map +0 -1
- package/lib/utils/calendar-utils.js.map +0 -1
- package/lib/utils/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.js.map +0 -1
- package/lib/utils/locale.d.ts.map +0 -1
- package/lib/utils/locale.js.map +0 -1
- package/lib/utils/number-format.d.ts.map +0 -1
- package/lib/utils/number-format.js.map +0 -1
- package/lib/utils/parse-boolean.d.ts +0 -39
- package/lib/utils/parse-boolean.d.ts.map +0 -1
- package/lib/utils/parse-boolean.js +0 -23
- package/lib/utils/parse-boolean.js.map +0 -1
- package/lib/utils/positioning.d.ts.map +0 -1
- package/lib/utils/positioning.js.map +0 -1
- package/lib/utils/property-capture.d.ts.map +0 -1
- package/lib/utils/property-capture.js.map +0 -1
- package/lib/utils/property-manager.d.ts.map +0 -1
- package/lib/utils/property-manager.js.map +0 -1
- package/lib/utils/resize-observer.d.ts.map +0 -1
- package/lib/utils/resize-observer.js.map +0 -1
- package/lib/utils/scroll-lock.d.ts.map +0 -1
- package/lib/utils/scroll-lock.js.map +0 -1
- package/lib/utils/styles.d.ts.map +0 -1
- package/lib/utils/styles.js.map +0 -1
- package/lib/version.d.ts.map +0 -1
- package/lib/version.js.map +0 -1
|
@@ -73,6 +73,11 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
73
73
|
visual: boolean;
|
|
74
74
|
default: boolean;
|
|
75
75
|
};
|
|
76
|
+
error: {
|
|
77
|
+
type: "string";
|
|
78
|
+
visual: boolean;
|
|
79
|
+
default: string;
|
|
80
|
+
};
|
|
76
81
|
noClear: {
|
|
77
82
|
type: "boolean";
|
|
78
83
|
visual: boolean;
|
|
@@ -190,6 +195,8 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
190
195
|
private _childObserver;
|
|
191
196
|
private _selectedClone;
|
|
192
197
|
private _customFlavorSheet;
|
|
198
|
+
private _ariaTrigger;
|
|
199
|
+
private _ariaObserver;
|
|
193
200
|
constructor();
|
|
194
201
|
/** TyComponent handles property capture automatically. */
|
|
195
202
|
protected onConnect(): void;
|
|
@@ -207,6 +214,12 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
207
214
|
private applyLoadingState;
|
|
208
215
|
/** Form value: a plain entry for single, FormData with repeated entries for multiple (HTMX standard). */
|
|
209
216
|
protected getFormValue(): FormDataEntryValue | FormData | null;
|
|
217
|
+
/**
|
|
218
|
+
* Focus the trigger: a slotted one, else the field. The host itself isn't
|
|
219
|
+
* focusable. A slotted trigger that can't take focus (a <span>, a disabled
|
|
220
|
+
* button) leaves it to the field.
|
|
221
|
+
*/
|
|
222
|
+
focus(options?: FocusOptions): void;
|
|
210
223
|
private parseValue;
|
|
211
224
|
/** Initialize component state from the value property / pre-selected children. */
|
|
212
225
|
private initializeState;
|
|
@@ -237,6 +250,12 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
237
250
|
* Get all option elements from the component (ty-option preferred, ty-tag accepted)
|
|
238
251
|
*/
|
|
239
252
|
private getTagElements;
|
|
253
|
+
/**
|
|
254
|
+
* The options on offer: all but the ones the author hid (`hidden`, like a
|
|
255
|
+
* native <option hidden>). The search filters these and the keyboard walks
|
|
256
|
+
* them; a hidden option can still be the value.
|
|
257
|
+
*/
|
|
258
|
+
private getOfferedTags;
|
|
240
259
|
private getTagData;
|
|
241
260
|
/**
|
|
242
261
|
* Select an option - attribute only. The option stays in the list with
|
|
@@ -335,11 +354,17 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
335
354
|
/**
|
|
336
355
|
* Next tag index in `direction` (-1/1) that isn't disabled, wrapping
|
|
337
356
|
* around — mirrors handleTagClick's disabled check so keyboard nav can
|
|
338
|
-
* never land on/select what a click already refuses to.
|
|
339
|
-
*
|
|
357
|
+
* never land on/select what a click already refuses to. Nor on one out of
|
|
358
|
+
* sight: `tags` is the list as it was offered, and an option can get
|
|
359
|
+
* `hidden` while it's open (a server patch). Returns -1 if every tag is
|
|
360
|
+
* skipped (or there are none).
|
|
340
361
|
*/
|
|
341
362
|
private nextEnabledTagIndex;
|
|
342
363
|
private filterTags;
|
|
364
|
+
/**
|
|
365
|
+
* Search filtering marks the options it leaves out `filtered-out`, never
|
|
366
|
+
* `hidden`: that one is the author's (see getOfferedTags).
|
|
367
|
+
*/
|
|
343
368
|
private updateTagVisibility;
|
|
344
369
|
private updateOptionsVisibility;
|
|
345
370
|
private clearHighlights;
|
|
@@ -363,12 +388,22 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
363
388
|
* `compact` after connect never showed up.
|
|
364
389
|
*/
|
|
365
390
|
private syncFieldChrome;
|
|
391
|
+
/**
|
|
392
|
+
* A slotted trigger is what takes focus (focus()), so it carries the error
|
|
393
|
+
* state too. aria-describedby can't reach into our shadow root from the
|
|
394
|
+
* light DOM: the message goes in aria-description instead. The trigger is
|
|
395
|
+
* the author's markup, so a morph can strip these while the error stays:
|
|
396
|
+
* a watch on them puts them back. Writes only on a real change, or the
|
|
397
|
+
* watch would feed itself.
|
|
398
|
+
*/
|
|
399
|
+
private syncTriggerAria;
|
|
366
400
|
/**
|
|
367
401
|
* Reflect constraint validation to the owning <form> via ElementInternals.
|
|
368
402
|
* Without this `required` is only cosmetic — form.checkValidity() (and a
|
|
369
403
|
* real submit) never actually blocks on an empty required select. Mirrors
|
|
370
|
-
* ty-input's updateValidity(): empty + required => valueMissing
|
|
371
|
-
* fields are barred from constraint
|
|
404
|
+
* ty-input's updateValidity(): empty + required => valueMissing, with a
|
|
405
|
+
* native <select>'s message; disabled fields are barred from constraint
|
|
406
|
+
* validation.
|
|
372
407
|
*/
|
|
373
408
|
private updateValidity;
|
|
374
409
|
/**
|
|
@@ -381,6 +416,16 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
381
416
|
private renderDesktop;
|
|
382
417
|
private renderMobile;
|
|
383
418
|
private setupMobileEventListeners;
|
|
419
|
+
/**
|
|
420
|
+
* The dialog was closed by someone else — a ty-modal around this select
|
|
421
|
+
* closes the dialogs still open inside it. Run our own close too, so the
|
|
422
|
+
* open state, aria-expanded and the scroll lock follow. Watches the `open`
|
|
423
|
+
* attribute rather than the `close` event: that one comes a task later,
|
|
424
|
+
* so right after modal.hide() the stub would still say expanded. Our own
|
|
425
|
+
* close() calls land here with the state already closed, and a dialog
|
|
426
|
+
* reopened since then is open again: both are no-ops.
|
|
427
|
+
*/
|
|
428
|
+
private syncOnOutsideClose;
|
|
384
429
|
private handleMobileStubClick;
|
|
385
430
|
/** Keyboard-open the (closed) mobile stub — see handleStubKeydown for why this is needed. */
|
|
386
431
|
private handleMobileStubKeydown;
|
|
@@ -442,7 +487,9 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
442
487
|
* Clear the entire selection programmatically WITH a change event
|
|
443
488
|
* (action: 'clear'). No-op if nothing is selected. Exists so slot="trigger"
|
|
444
489
|
* consumers (custom chrome, built-in clear UI hidden by design) can wire
|
|
445
|
-
* their own clear icon's click handler to it.
|
|
490
|
+
* their own clear icon's click handler to it. Shows no validation
|
|
491
|
+
* message (a code reset after a save shouldn't flag the field); the
|
|
492
|
+
* built-in × does.
|
|
446
493
|
*/
|
|
447
494
|
clear(): void;
|
|
448
495
|
get value(): string;
|
|
@@ -467,6 +514,8 @@ export declare class TySelect extends TyComponent<SelectState> {
|
|
|
467
514
|
set noClear(value: boolean);
|
|
468
515
|
get required(): boolean;
|
|
469
516
|
set required(value: boolean);
|
|
517
|
+
get error(): string;
|
|
518
|
+
set error(value: string);
|
|
470
519
|
get notSearchable(): boolean;
|
|
471
520
|
set notSearchable(value: boolean);
|
|
472
521
|
get externalSearch(): boolean;
|
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) {
|
|
@@ -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) {
|
|
@@ -903,10 +939,26 @@ label.innerHTML = `${this._label}${this._required ? `<span class="required-icon"
|
|
|
903
939
|
else {
|
|
904
940
|
label?.remove();
|
|
905
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
|
+
}
|
|
906
957
|
const stub = shadow.querySelector(".select-stub");
|
|
907
958
|
if (stub) {
|
|
908
959
|
stub.classList.toggle("disabled", this._disabled);
|
|
909
960
|
stub.classList.toggle("compact", this._compact);
|
|
961
|
+
stub.classList.toggle("error", !!error);
|
|
910
962
|
stub.tabIndex = this._disabled ? -1 : 0;
|
|
911
963
|
stub.toggleAttribute("disabled", this._disabled);
|
|
912
964
|
if (this._disabled)
|
|
@@ -917,11 +969,45 @@ if (this._label)
|
|
|
917
969
|
stub.setAttribute("aria-labelledby", labelId);
|
|
918
970
|
else
|
|
919
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
|
+
}
|
|
920
980
|
}
|
|
981
|
+
this.syncTriggerAria();
|
|
921
982
|
shadow
|
|
922
983
|
.querySelectorAll(".dropdown-search-input, .mobile-search-input")
|
|
923
984
|
.forEach((input) => (input.disabled = this._disabled));
|
|
924
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
|
+
}
|
|
925
1011
|
updateValidity() {
|
|
926
1012
|
if (this.disabled) {
|
|
927
1013
|
this.applyValidity({});
|
|
@@ -929,7 +1015,7 @@ return;
|
|
|
929
1015
|
}
|
|
930
1016
|
if (this.required && this.getSelectedValues().length === 0) {
|
|
931
1017
|
const stub = this.shadowRoot?.querySelector(".select-stub");
|
|
932
|
-
this.applyValidity({ valueMissing: true }, "
|
|
1018
|
+
this.applyValidity({ valueMissing: true }, nativeMessage("select", { required: true, multiple: this._multiple }), stub ?? undefined);
|
|
933
1019
|
}
|
|
934
1020
|
else {
|
|
935
1021
|
this.applyValidity({});
|
|
@@ -946,7 +1032,10 @@ const hasTrigger = slot.assignedElements().length > 0;
|
|
|
946
1032
|
stub.classList.toggle("custom-trigger", hasTrigger);
|
|
947
1033
|
this.toggleAttribute("has-trigger", hasTrigger);
|
|
948
1034
|
};
|
|
949
|
-
slot.addEventListener("slotchange",
|
|
1035
|
+
slot.addEventListener("slotchange", () => {
|
|
1036
|
+
sync();
|
|
1037
|
+
this.syncFieldChrome();
|
|
1038
|
+
});
|
|
950
1039
|
sync();
|
|
951
1040
|
}
|
|
952
1041
|
setupEventListeners() {
|
|
@@ -979,9 +1068,13 @@ if (e.target === dialog) {
|
|
|
979
1068
|
this.closeDropdown();
|
|
980
1069
|
}
|
|
981
1070
|
});
|
|
1071
|
+
dialog.addEventListener("cancel", (e) => {
|
|
1072
|
+
e.preventDefault();
|
|
1073
|
+
this.closeDropdown();
|
|
1074
|
+
this.focus();
|
|
1075
|
+
});
|
|
1076
|
+
this.syncOnOutsideClose(dialog, () => this.closeDropdown());
|
|
982
1077
|
}
|
|
983
|
-
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
984
|
-
document.addEventListener("keydown", this._keyboardHandler);
|
|
985
1078
|
}
|
|
986
1079
|
buildStubClasses() {
|
|
987
1080
|
const classes = [];
|
|
@@ -1175,10 +1268,6 @@ this.setupMobileEventListeners();
|
|
|
1175
1268
|
this.updateSelectionDisplay();
|
|
1176
1269
|
}
|
|
1177
1270
|
setupMobileEventListeners() {
|
|
1178
|
-
if (!this._keyboardHandler) {
|
|
1179
|
-
this._keyboardHandler = this.handleKeyboard.bind(this);
|
|
1180
|
-
document.addEventListener("keydown", this._keyboardHandler);
|
|
1181
|
-
}
|
|
1182
1271
|
const shadow = this.shadowRoot;
|
|
1183
1272
|
const stub = shadow.querySelector(".select-stub");
|
|
1184
1273
|
const optionsSlot = shadow.querySelector("#options-slot");
|
|
@@ -1213,8 +1302,16 @@ this.closeMobileModal();
|
|
|
1213
1302
|
dialog.addEventListener("cancel", (e) => {
|
|
1214
1303
|
e.preventDefault();
|
|
1215
1304
|
this.closeMobileModal();
|
|
1305
|
+
this.focus();
|
|
1216
1306
|
});
|
|
1307
|
+
this.syncOnOutsideClose(dialog, () => this.closeMobileModal());
|
|
1308
|
+
}
|
|
1217
1309
|
}
|
|
1310
|
+
syncOnOutsideClose(dialog, close) {
|
|
1311
|
+
new MutationObserver(() => {
|
|
1312
|
+
if (this._state.open && !dialog.open)
|
|
1313
|
+
close();
|
|
1314
|
+
}).observe(dialog, { attributes: true, attributeFilter: ["open"] });
|
|
1218
1315
|
}
|
|
1219
1316
|
handleMobileStubClick(e) {
|
|
1220
1317
|
e.preventDefault();
|
|
@@ -1242,7 +1339,7 @@ const shadow = this.shadowRoot;
|
|
|
1242
1339
|
this.renderMobileSelectedChips();
|
|
1243
1340
|
const availableSection = shadow.querySelector(".mobile-available-section");
|
|
1244
1341
|
if (availableSection) {
|
|
1245
|
-
const visibleAvailable = this.
|
|
1342
|
+
const visibleAvailable = this.getOfferedTags().filter(({ element }) => !element.hasAttribute("filtered-out") && !element.hasAttribute("selected")).length;
|
|
1246
1343
|
availableSection.setAttribute("data-empty", String(visibleAvailable === 0));
|
|
1247
1344
|
this.setMobileSectionTitle(availableSection, this._availableLabel, visibleAvailable);
|
|
1248
1345
|
}
|
|
@@ -1387,6 +1484,8 @@ const option = this.getTagElements().find((el) => this.getTagData(el).value ===
|
|
|
1387
1484
|
if (option) {
|
|
1388
1485
|
const clone = option.cloneNode(true);
|
|
1389
1486
|
clone.removeAttribute("selected");
|
|
1487
|
+
clone.removeAttribute("hidden");
|
|
1488
|
+
clone.removeAttribute("filtered-out");
|
|
1390
1489
|
clone.setAttribute("slot", "selected");
|
|
1391
1490
|
clone.setAttribute("cloned", "true");
|
|
1392
1491
|
this.appendChild(clone);
|
|
@@ -1409,7 +1508,7 @@ return;
|
|
|
1409
1508
|
this.updateComponentValue(current.filter((v) => v !== value), true, "remove", value);
|
|
1410
1509
|
}
|
|
1411
1510
|
clear() {
|
|
1412
|
-
this.updateComponentValue([], true, "clear", null);
|
|
1511
|
+
this.updateComponentValue([], true, "clear", null, false);
|
|
1413
1512
|
}
|
|
1414
1513
|
get value() {
|
|
1415
1514
|
return this.getSelectedValues().join(",");
|
|
@@ -1477,6 +1576,12 @@ return this.getProperty("required");
|
|
|
1477
1576
|
set required(value) {
|
|
1478
1577
|
this.setProperty("required", value);
|
|
1479
1578
|
}
|
|
1579
|
+
get error() {
|
|
1580
|
+
return this.getProperty("error");
|
|
1581
|
+
}
|
|
1582
|
+
set error(value) {
|
|
1583
|
+
this.setProperty("error", value);
|
|
1584
|
+
}
|
|
1480
1585
|
get notSearchable() {
|
|
1481
1586
|
return this.getProperty("notSearchable");
|
|
1482
1587
|
}
|
|
@@ -1580,6 +1685,11 @@ type: "boolean",
|
|
|
1580
1685
|
visual: true,
|
|
1581
1686
|
default: false,
|
|
1582
1687
|
},
|
|
1688
|
+
error: {
|
|
1689
|
+
type: "string",
|
|
1690
|
+
visual: true,
|
|
1691
|
+
default: "",
|
|
1692
|
+
},
|
|
1583
1693
|
noClear: {
|
|
1584
1694
|
type: "boolean",
|
|
1585
1695
|
visual: true,
|
|
@@ -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);
|