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
|
@@ -81,9 +81,12 @@ export declare class TyFileUpload extends TyComponent<FileUploadState> implement
|
|
|
81
81
|
protected onFormReset(): void;
|
|
82
82
|
protected updateFormValue(): void;
|
|
83
83
|
/** Report `required` to the owning form, like ty-input and ty-textarea
|
|
84
|
-
do — without this the asterisk showed but submission went through.
|
|
84
|
+
do — without this the asterisk showed but submission went through.
|
|
85
|
+
The message is a native file input's. */
|
|
85
86
|
private updateValidity;
|
|
86
87
|
protected getFormValue(): FormData | string | null;
|
|
88
|
+
/** Focus the drop zone: the host itself isn't focusable. */
|
|
89
|
+
focus(options?: FocusOptions): void;
|
|
87
90
|
/**
|
|
88
91
|
* Match a file against the `accept` attribute the way native inputs do:
|
|
89
92
|
* comma-separated list of `.ext`, `type/subtype` or `type/*` entries.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { TyComponent } from "../base/ty-component.js";
|
|
2
2
|
import { ensureStyles } from "../utils/styles.js";
|
|
3
3
|
import { fileUploadStyles } from "../styles/file-upload.js";
|
|
4
|
+
import { nativeMessage } from "../utils/validity.js";
|
|
5
|
+
const DEFAULT_PLACEHOLDER = "Drop files here or click to browse";
|
|
4
6
|
const UPLOAD_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>`;
|
|
5
7
|
const FILE_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>`;
|
|
6
8
|
const X_ICON = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>`;
|
|
@@ -29,7 +31,9 @@ this._dropHandler = null;
|
|
|
29
31
|
this._inputChangeHandler = null;
|
|
30
32
|
ensureStyles(this.shadowRoot, { css: fileUploadStyles, id: "ty-file-upload" });
|
|
31
33
|
}
|
|
32
|
-
onConnect() {
|
|
34
|
+
onConnect() {
|
|
35
|
+
this.updateFormValue();
|
|
36
|
+
}
|
|
33
37
|
onDisconnect() {
|
|
34
38
|
this.removeEventListeners();
|
|
35
39
|
}
|
|
@@ -50,21 +54,31 @@ this.updateValidity();
|
|
|
50
54
|
updateValidity() {
|
|
51
55
|
if (this.required && !this.disabled && this._files.length === 0) {
|
|
52
56
|
const anchor = this.shadowRoot?.querySelector(".drop-zone");
|
|
53
|
-
this.applyValidity({ valueMissing: true }, "
|
|
57
|
+
this.applyValidity({ valueMissing: true }, nativeMessage("input", { type: "file", required: true, multiple: this.multiple }), anchor ?? undefined);
|
|
54
58
|
}
|
|
55
59
|
else {
|
|
56
60
|
this.applyValidity({});
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
getFormValue() {
|
|
60
|
-
if (
|
|
64
|
+
if (!this.name)
|
|
61
65
|
return null;
|
|
62
66
|
const fd = new FormData();
|
|
67
|
+
if (this._files.length === 0) {
|
|
68
|
+
fd.append(this.name, new File([], '', { type: 'application/octet-stream' }));
|
|
69
|
+
}
|
|
63
70
|
for (const file of this._files) {
|
|
64
71
|
fd.append(this.name, file);
|
|
65
72
|
}
|
|
66
73
|
return fd;
|
|
67
74
|
}
|
|
75
|
+
focus(options) {
|
|
76
|
+
const zone = this.shadowRoot?.querySelector('.drop-zone');
|
|
77
|
+
if (zone)
|
|
78
|
+
zone.focus(options);
|
|
79
|
+
else
|
|
80
|
+
super.focus(options);
|
|
81
|
+
}
|
|
68
82
|
matchesAccept(file) {
|
|
69
83
|
const accept = this.accept?.trim();
|
|
70
84
|
if (!accept)
|
|
@@ -146,6 +160,7 @@ names: this._files.map((f) => f.name),
|
|
|
146
160
|
};
|
|
147
161
|
setTimeout(() => {
|
|
148
162
|
this.dispatchEvent(new CustomEvent("change", { detail, bubbles: true, composed: true }));
|
|
163
|
+
this.revealValidity();
|
|
149
164
|
}, 0);
|
|
150
165
|
}
|
|
151
166
|
removeFile(index) {
|
|
@@ -367,9 +382,12 @@ const hintEl = container.querySelector(".upload-hint");
|
|
|
367
382
|
if (this._files.length > 0) {
|
|
368
383
|
hintEl.innerHTML = `<strong>${this._files.length} file${this._files.length !== 1 ? "s" : ""} selected</strong>`;
|
|
369
384
|
}
|
|
370
|
-
else {
|
|
385
|
+
else if (!this.placeholder || this.placeholder === DEFAULT_PLACEHOLDER) {
|
|
371
386
|
hintEl.innerHTML = `Drop files here or <span class="browse-link">click to browse</span>`;
|
|
372
387
|
}
|
|
388
|
+
else {
|
|
389
|
+
hintEl.textContent = this.placeholder;
|
|
390
|
+
}
|
|
373
391
|
const subHintEl = container.querySelector(".upload-sub-hint");
|
|
374
392
|
if (this.accept && this._files.length === 0) {
|
|
375
393
|
subHintEl.textContent = `Accepted: ${this.accept}`;
|
|
@@ -420,7 +438,7 @@ default: "",
|
|
|
420
438
|
placeholder: {
|
|
421
439
|
type: "string",
|
|
422
440
|
visual: true,
|
|
423
|
-
default:
|
|
441
|
+
default: DEFAULT_PLACEHOLDER,
|
|
424
442
|
},
|
|
425
443
|
error: {
|
|
426
444
|
type: "string",
|
|
@@ -59,6 +59,41 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
59
59
|
visual: boolean;
|
|
60
60
|
default: boolean;
|
|
61
61
|
};
|
|
62
|
+
pattern: {
|
|
63
|
+
type: "string";
|
|
64
|
+
visual: boolean;
|
|
65
|
+
default: string;
|
|
66
|
+
};
|
|
67
|
+
minlength: {
|
|
68
|
+
type: "string";
|
|
69
|
+
visual: boolean;
|
|
70
|
+
default: string;
|
|
71
|
+
};
|
|
72
|
+
maxlength: {
|
|
73
|
+
type: "string";
|
|
74
|
+
visual: boolean;
|
|
75
|
+
default: string;
|
|
76
|
+
};
|
|
77
|
+
min: {
|
|
78
|
+
type: "string";
|
|
79
|
+
visual: boolean;
|
|
80
|
+
default: string;
|
|
81
|
+
};
|
|
82
|
+
max: {
|
|
83
|
+
type: "string";
|
|
84
|
+
visual: boolean;
|
|
85
|
+
default: string;
|
|
86
|
+
};
|
|
87
|
+
tooShortMessage: {
|
|
88
|
+
type: "string";
|
|
89
|
+
visual: boolean;
|
|
90
|
+
default: string;
|
|
91
|
+
};
|
|
92
|
+
tooLongMessage: {
|
|
93
|
+
type: "string";
|
|
94
|
+
visual: boolean;
|
|
95
|
+
default: string;
|
|
96
|
+
};
|
|
62
97
|
error: {
|
|
63
98
|
type: "string";
|
|
64
99
|
visual: boolean;
|
|
@@ -103,7 +138,6 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
103
138
|
private _shadowValue;
|
|
104
139
|
private _isFocused;
|
|
105
140
|
private _listenersSetup;
|
|
106
|
-
private _errorAutoDanger;
|
|
107
141
|
private _customFlavorSheet;
|
|
108
142
|
private _inputHandler;
|
|
109
143
|
private _changeHandler;
|
|
@@ -143,8 +177,24 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
143
177
|
set label(v: string);
|
|
144
178
|
get disabled(): boolean;
|
|
145
179
|
set disabled(v: boolean);
|
|
180
|
+
/** Focus the inner <input>: the host itself isn't focusable. */
|
|
181
|
+
focus(options?: FocusOptions): void;
|
|
146
182
|
get required(): boolean;
|
|
147
183
|
set required(v: boolean);
|
|
184
|
+
get pattern(): string;
|
|
185
|
+
set pattern(v: string);
|
|
186
|
+
get minLength(): number;
|
|
187
|
+
set minLength(v: number);
|
|
188
|
+
get maxLength(): number;
|
|
189
|
+
set maxLength(v: number);
|
|
190
|
+
get min(): string;
|
|
191
|
+
set min(v: string);
|
|
192
|
+
get max(): string;
|
|
193
|
+
set max(v: string);
|
|
194
|
+
get tooShortMessage(): string;
|
|
195
|
+
set tooShortMessage(v: string);
|
|
196
|
+
get tooLongMessage(): string;
|
|
197
|
+
set tooLongMessage(v: string);
|
|
148
198
|
get error(): string;
|
|
149
199
|
set error(v: string);
|
|
150
200
|
get size(): Size;
|
|
@@ -165,6 +215,13 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
165
215
|
private dispatchChangeEvent;
|
|
166
216
|
private removeEventListeners;
|
|
167
217
|
/** IMPORTANT: Only called ONCE, not on every render. */
|
|
218
|
+
/**
|
|
219
|
+
* Enter submits the owning form, like a native input (HTML implicit
|
|
220
|
+
* submission): through the form's default button when it has one (nothing
|
|
221
|
+
* if that button is disabled), otherwise only when this is the form's only
|
|
222
|
+
* text field.
|
|
223
|
+
*/
|
|
224
|
+
private _implicitSubmit;
|
|
168
225
|
private setupEventListeners;
|
|
169
226
|
/** Render the input component with wrapper and slots. */
|
|
170
227
|
render(): void;
|
|
@@ -174,10 +231,23 @@ export declare class TyInput extends TyComponent<InputState> implements TyInputE
|
|
|
174
231
|
* `type` property stays "password" (form value and API unaffected).
|
|
175
232
|
*/
|
|
176
233
|
private setupPasswordToggle;
|
|
234
|
+
/**
|
|
235
|
+
* pattern, minlength and maxlength go on the inner <input>: pattern for the
|
|
236
|
+
* browser's own patternMismatch check, minlength for its tooShort message
|
|
237
|
+
* after the user types, maxlength so typing stops at the limit like a
|
|
238
|
+
* native field. Formatted (numeric) types show a display string, so they
|
|
239
|
+
* get none.
|
|
240
|
+
*/
|
|
241
|
+
private syncConstraintAttributes;
|
|
177
242
|
/**
|
|
178
243
|
* Reflect constraint validation to the owning <form> via ElementInternals.
|
|
179
|
-
* Without this
|
|
180
|
-
*
|
|
244
|
+
* Without this the inner shadow <input> can't block the outer form.
|
|
245
|
+
* Rules, first failing one supplies the message:
|
|
246
|
+
* - required: empty => valueMissing
|
|
247
|
+
* - email/url: the inner input's own typeMismatch
|
|
248
|
+
* - text types: pattern, minlength, maxlength
|
|
249
|
+
* - number/currency/percent/compact: min, max against the numeric value
|
|
250
|
+
* Empty values only fail `required`, like native inputs.
|
|
181
251
|
* Disabled fields are barred from constraint validation.
|
|
182
252
|
*/
|
|
183
253
|
private updateValidity;
|
package/lib/components/input.js
CHANGED
|
@@ -6,6 +6,7 @@ import { inputStyles, inputCustomFlavorCss } from '../styles/input.js';
|
|
|
6
6
|
import { formatNumber, parseNumericValue, shouldFormat as shouldFormatType } from '../utils/number-format.js';
|
|
7
7
|
import { getEffectiveLocale, observeLocaleChanges } from '../utils/locale.js';
|
|
8
8
|
import { REQUIRED_ICON_SVG } from '../utils/icons.js';
|
|
9
|
+
import { nativeMessage, nativeValidity, lengthValidity, toLimit } from '../utils/validity.js';
|
|
9
10
|
const EYE_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>`;
|
|
10
11
|
const EYE_OFF_ICON_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"/><path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"/><path d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"/><path d="m2 2 20 20"/></svg>`;
|
|
11
12
|
export class TyInput extends TyComponent {
|
|
@@ -14,7 +15,6 @@ super();
|
|
|
14
15
|
this._shadowValue = null;
|
|
15
16
|
this._isFocused = false;
|
|
16
17
|
this._listenersSetup = false;
|
|
17
|
-
this._errorAutoDanger = false;
|
|
18
18
|
this._customFlavorSheet = null;
|
|
19
19
|
this._inputHandler = null;
|
|
20
20
|
this._changeHandler = null;
|
|
@@ -22,6 +22,34 @@ this._focusHandler = null;
|
|
|
22
22
|
this._blurHandler = null;
|
|
23
23
|
this._inputDebounceTimer = null;
|
|
24
24
|
this._changeDebounceTimer = null;
|
|
25
|
+
this._implicitSubmit = (e) => {
|
|
26
|
+
if (e.key !== 'Enter' || e.isComposing || e.defaultPrevented)
|
|
27
|
+
return;
|
|
28
|
+
const form = this._internals.form;
|
|
29
|
+
if (!form)
|
|
30
|
+
return;
|
|
31
|
+
const controls = Array.from(form.elements);
|
|
32
|
+
const isSubmitter = (el) => (el instanceof HTMLButtonElement && el.type === 'submit') ||
|
|
33
|
+
(el instanceof HTMLInputElement && (el.type === 'submit' || el.type === 'image')) ||
|
|
34
|
+
(el.tagName === 'TY-BUTTON' && !['button', 'reset'].includes(el.getAttribute('type') ?? ''));
|
|
35
|
+
const submitter = controls.find(isSubmitter);
|
|
36
|
+
if (submitter) {
|
|
37
|
+
if (submitter.disabled || submitter.hasAttribute('disabled'))
|
|
38
|
+
return;
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
const target = submitter.tagName === 'TY-BUTTON'
|
|
41
|
+
? submitter.shadowRoot?.querySelector('button') ?? submitter
|
|
42
|
+
: submitter;
|
|
43
|
+
target.click();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const textFields = controls.filter((el) => el.tagName === 'TY-INPUT' ||
|
|
47
|
+
(el instanceof HTMLInputElement && !['button', 'checkbox', 'radio', 'file', 'hidden', 'image', 'reset', 'submit', 'range', 'color'].includes(el.type)));
|
|
48
|
+
if (textFields.length === 1) {
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
form.requestSubmit();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
25
53
|
const shadow = this.shadowRoot;
|
|
26
54
|
ensureStyles(shadow, { css: inputStyles, id: 'ty-input' });
|
|
27
55
|
}
|
|
@@ -31,6 +59,10 @@ this._localeObserver = observeLocaleChanges(this, () => {
|
|
|
31
59
|
this.render();
|
|
32
60
|
});
|
|
33
61
|
this._syncCustomFlavor();
|
|
62
|
+
if (this._rendered) {
|
|
63
|
+
this.render();
|
|
64
|
+
this.setupEventListeners();
|
|
65
|
+
}
|
|
34
66
|
}
|
|
35
67
|
_syncCustomFlavor() {
|
|
36
68
|
this._customFlavorSheet = syncCustomFlavorSheet(this.shadowRoot, this._customFlavorSheet, this.flavor, ({ base }) => inputCustomFlavorCss(base));
|
|
@@ -63,20 +95,6 @@ case 'type':
|
|
|
63
95
|
const currentValue = this.getProperty('value') || '';
|
|
64
96
|
this._shadowValue = this.parseShadowValue(currentValue);
|
|
65
97
|
break;
|
|
66
|
-
case 'error':
|
|
67
|
-
if (newValue) {
|
|
68
|
-
if (this.getProperty('flavor') === 'neutral') {
|
|
69
|
-
this.setProperty('flavor', 'danger');
|
|
70
|
-
this._errorAutoDanger = true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else if (this._errorAutoDanger) {
|
|
74
|
-
if (this.getProperty('flavor') === 'danger') {
|
|
75
|
-
this.setProperty('flavor', 'neutral');
|
|
76
|
-
}
|
|
77
|
-
this._errorAutoDanger = false;
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
98
|
}
|
|
81
99
|
}
|
|
82
100
|
}
|
|
@@ -95,14 +113,17 @@ this._changeDebounceTimer = null;
|
|
|
95
113
|
this.render();
|
|
96
114
|
}
|
|
97
115
|
getFormValue() {
|
|
98
|
-
const formValue = this._shadowValue !== null ? String(this._shadowValue) :
|
|
116
|
+
const formValue = this._shadowValue !== null ? String(this._shadowValue) : '';
|
|
99
117
|
return formValue;
|
|
100
118
|
}
|
|
101
119
|
initializeShadowValue() {
|
|
102
120
|
const currentValue = this.getProperty('value');
|
|
103
121
|
if (currentValue) {
|
|
104
122
|
this._shadowValue = this.parseShadowValue(currentValue);
|
|
105
|
-
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) :
|
|
123
|
+
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this._internals.setFormValue('');
|
|
106
127
|
}
|
|
107
128
|
}
|
|
108
129
|
parseShadowValue(value) {
|
|
@@ -155,8 +176,25 @@ get label() { return this.getProperty('label'); }
|
|
|
155
176
|
set label(v) { this.setProperty('label', v); }
|
|
156
177
|
get disabled() { return this.getProperty('disabled'); }
|
|
157
178
|
set disabled(v) { this.setProperty('disabled', v); }
|
|
179
|
+
focus(options) {
|
|
180
|
+
this.shadowRoot?.querySelector('input')?.focus(options);
|
|
181
|
+
}
|
|
158
182
|
get required() { return this.getProperty('required'); }
|
|
159
183
|
set required(v) { this.setProperty('required', v); }
|
|
184
|
+
get pattern() { return this.getProperty('pattern'); }
|
|
185
|
+
set pattern(v) { this.setProperty('pattern', v ?? ''); }
|
|
186
|
+
get minLength() { return toLimit(this.getProperty('minlength')) ?? -1; }
|
|
187
|
+
set minLength(v) { this.setProperty('minlength', v == null || v < 0 ? '' : String(v)); }
|
|
188
|
+
get maxLength() { return toLimit(this.getProperty('maxlength')) ?? -1; }
|
|
189
|
+
set maxLength(v) { this.setProperty('maxlength', v == null || v < 0 ? '' : String(v)); }
|
|
190
|
+
get min() { return this.getProperty('min'); }
|
|
191
|
+
set min(v) { this.setProperty('min', v == null ? '' : String(v)); }
|
|
192
|
+
get max() { return this.getProperty('max'); }
|
|
193
|
+
set max(v) { this.setProperty('max', v == null ? '' : String(v)); }
|
|
194
|
+
get tooShortMessage() { return this.getProperty('tooShortMessage'); }
|
|
195
|
+
set tooShortMessage(v) { this.setProperty('tooShortMessage', v ?? ''); }
|
|
196
|
+
get tooLongMessage() { return this.getProperty('tooLongMessage'); }
|
|
197
|
+
set tooLongMessage(v) { this.setProperty('tooLongMessage', v ?? ''); }
|
|
160
198
|
get error() { return this.getProperty('error'); }
|
|
161
199
|
set error(v) { this.setProperty('error', v); }
|
|
162
200
|
get size() { return this.getProperty('size'); }
|
|
@@ -235,6 +273,7 @@ if (this._blurHandler) {
|
|
|
235
273
|
inputEl.removeEventListener('blur', this._blurHandler);
|
|
236
274
|
this._blurHandler = null;
|
|
237
275
|
}
|
|
276
|
+
inputEl.removeEventListener('keydown', this._implicitSubmit);
|
|
238
277
|
this._listenersSetup = false;
|
|
239
278
|
}
|
|
240
279
|
setupEventListeners() {
|
|
@@ -249,12 +288,13 @@ console.warn('[TyInput.setupEventListeners] ⚠️ Input element not found!');
|
|
|
249
288
|
return;
|
|
250
289
|
}
|
|
251
290
|
this._inputHandler = (e) => {
|
|
291
|
+
this._userEdited = true;
|
|
252
292
|
e.stopPropagation();
|
|
253
293
|
e.stopImmediatePropagation();
|
|
254
294
|
const target = e.target;
|
|
255
295
|
const rawValue = target.value;
|
|
256
296
|
this._shadowValue = this.parseShadowValue(rawValue);
|
|
257
|
-
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) :
|
|
297
|
+
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
|
|
258
298
|
this.updateValidity();
|
|
259
299
|
if (this._inputDebounceTimer !== null) {
|
|
260
300
|
clearTimeout(this._inputDebounceTimer);
|
|
@@ -275,7 +315,7 @@ e.stopImmediatePropagation();
|
|
|
275
315
|
const target = e.target;
|
|
276
316
|
const rawValue = target.value;
|
|
277
317
|
this._shadowValue = this.parseShadowValue(rawValue);
|
|
278
|
-
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) :
|
|
318
|
+
this._internals.setFormValue(this._shadowValue !== null ? String(this._shadowValue) : '');
|
|
279
319
|
this.updateValidity();
|
|
280
320
|
if (this._changeDebounceTimer !== null) {
|
|
281
321
|
clearTimeout(this._changeDebounceTimer);
|
|
@@ -317,6 +357,8 @@ this.dispatchChangeEvent(rawValue, e);
|
|
|
317
357
|
}
|
|
318
358
|
this._isFocused = false;
|
|
319
359
|
wrapperEl.classList.remove('focused');
|
|
360
|
+
if (this._userEdited)
|
|
361
|
+
this.revealValidity();
|
|
320
362
|
if (this.shouldFormat()) {
|
|
321
363
|
inputEl.value = this.getDisplayValue();
|
|
322
364
|
}
|
|
@@ -330,6 +372,7 @@ inputEl.addEventListener('input', this._inputHandler);
|
|
|
330
372
|
inputEl.addEventListener('change', this._changeHandler);
|
|
331
373
|
inputEl.addEventListener('focus', this._focusHandler);
|
|
332
374
|
inputEl.addEventListener('blur', this._blurHandler);
|
|
375
|
+
inputEl.addEventListener('keydown', this._implicitSubmit);
|
|
333
376
|
this._listenersSetup = true;
|
|
334
377
|
}
|
|
335
378
|
render() {
|
|
@@ -339,6 +382,9 @@ const existingWrapper = shadow.querySelector('.input-wrapper');
|
|
|
339
382
|
const existingLabel = shadow.querySelector('.ty-field-label');
|
|
340
383
|
const existingError = shadow.querySelector('.error-message');
|
|
341
384
|
const classes = this.buildClassList();
|
|
385
|
+
const focused = !!existingInput && shadow.activeElement === existingInput;
|
|
386
|
+
if (!focused)
|
|
387
|
+
this._isFocused = false;
|
|
342
388
|
const inputType = ['password', 'email', 'tel', 'url'].includes(this.type)
|
|
343
389
|
? this.type
|
|
344
390
|
: 'text';
|
|
@@ -349,7 +395,10 @@ const inputMode = shouldFormatType(this.type) ? 'decimal'
|
|
|
349
395
|
: undefined;
|
|
350
396
|
const displayValue = this.getDisplayValue();
|
|
351
397
|
if (existingInput && existingWrapper) {
|
|
352
|
-
|
|
398
|
+
const revealed = inputType === 'password' &&
|
|
399
|
+
shadow.querySelector('.password-toggle')?.getAttribute('aria-pressed') === 'true';
|
|
400
|
+
existingInput.type = revealed ? 'text' : inputType;
|
|
401
|
+
if (existingInput.value !== displayValue)
|
|
353
402
|
existingInput.value = displayValue;
|
|
354
403
|
existingInput.placeholder = this.placeholder;
|
|
355
404
|
existingInput.name = this.name;
|
|
@@ -358,6 +407,7 @@ existingInput.inputMode = inputMode;
|
|
|
358
407
|
else
|
|
359
408
|
existingInput.removeAttribute('inputmode');
|
|
360
409
|
existingWrapper.className = `input-wrapper ${classes}`;
|
|
410
|
+
existingWrapper.classList.toggle('focused', focused);
|
|
361
411
|
existingInput.disabled = this.disabled;
|
|
362
412
|
if (this.disabled) {
|
|
363
413
|
existingInput.setAttribute('disabled', '');
|
|
@@ -372,6 +422,7 @@ existingInput.setAttribute('required', '');
|
|
|
372
422
|
else {
|
|
373
423
|
existingInput.removeAttribute('required');
|
|
374
424
|
}
|
|
425
|
+
this.syncConstraintAttributes(existingInput);
|
|
375
426
|
if (this.label)
|
|
376
427
|
existingInput.setAttribute('aria-label', this.label);
|
|
377
428
|
else
|
|
@@ -445,6 +496,7 @@ ${errorHtml}
|
|
|
445
496
|
const inputEl = shadow.querySelector('input');
|
|
446
497
|
inputEl.disabled = this.disabled;
|
|
447
498
|
inputEl.required = this.required;
|
|
499
|
+
this.syncConstraintAttributes(inputEl);
|
|
448
500
|
if (this.label)
|
|
449
501
|
inputEl.setAttribute('aria-label', this.label);
|
|
450
502
|
this.setupPasswordToggle();
|
|
@@ -461,12 +513,24 @@ return;
|
|
|
461
513
|
toggle.addEventListener('mousedown', (e) => e.preventDefault());
|
|
462
514
|
toggle.addEventListener('click', () => {
|
|
463
515
|
const reveal = inputEl.type === 'password';
|
|
516
|
+
const { selectionStart, selectionEnd, selectionDirection } = inputEl;
|
|
464
517
|
inputEl.type = reveal ? 'text' : 'password';
|
|
518
|
+
if (selectionStart !== null && shadow.activeElement === inputEl) {
|
|
519
|
+
inputEl.getBoundingClientRect();
|
|
520
|
+
inputEl.setSelectionRange(selectionStart, selectionEnd, selectionDirection ?? undefined);
|
|
521
|
+
}
|
|
465
522
|
toggle.innerHTML = reveal ? EYE_OFF_ICON_SVG : EYE_ICON_SVG;
|
|
466
523
|
toggle.setAttribute('aria-label', reveal ? 'Hide password' : 'Show password');
|
|
467
524
|
toggle.setAttribute('aria-pressed', String(reveal));
|
|
468
525
|
});
|
|
469
526
|
}
|
|
527
|
+
syncConstraintAttributes(inputEl) {
|
|
528
|
+
const text = !shouldFormatType(this.type);
|
|
529
|
+
const set = (name, v) => text && v !== '' ? inputEl.setAttribute(name, v) : inputEl.removeAttribute(name);
|
|
530
|
+
set('pattern', this.pattern);
|
|
531
|
+
set('minlength', toLimit(this.getProperty('minlength')) != null ? String(this.minLength) : '');
|
|
532
|
+
set('maxlength', toLimit(this.getProperty('maxlength')) != null ? String(this.maxLength) : '');
|
|
533
|
+
}
|
|
470
534
|
updateValidity() {
|
|
471
535
|
const inputEl = this.shadowRoot?.querySelector('input');
|
|
472
536
|
if (this.disabled) {
|
|
@@ -474,12 +538,48 @@ this.applyValidity({});
|
|
|
474
538
|
return;
|
|
475
539
|
}
|
|
476
540
|
const current = inputEl ? inputEl.value : String(this.getProperty('value') ?? '');
|
|
477
|
-
if (
|
|
478
|
-
this.
|
|
541
|
+
if (current.trim() === '') {
|
|
542
|
+
if (this.required) {
|
|
543
|
+
this.applyValidity({ valueMissing: true }, nativeMessage('input', { type: 'text', required: true }), inputEl ?? undefined);
|
|
479
544
|
}
|
|
480
545
|
else {
|
|
481
546
|
this.applyValidity({});
|
|
482
547
|
}
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
const flags = {};
|
|
551
|
+
const messages = [];
|
|
552
|
+
const fail = (flag, message) => {
|
|
553
|
+
flags[flag] = true;
|
|
554
|
+
messages.push(message);
|
|
555
|
+
};
|
|
556
|
+
if (shouldFormatType(this.type)) {
|
|
557
|
+
const n = typeof this._shadowValue === 'number' ? this._shadowValue : null;
|
|
558
|
+
if (n !== null && (this.min || this.max)) {
|
|
559
|
+
const { validity, message } = nativeValidity('input', { type: 'number', step: 'any', min: this.min, max: this.max }, String(n));
|
|
560
|
+
if (validity.rangeUnderflow)
|
|
561
|
+
fail('rangeUnderflow', message);
|
|
562
|
+
if (validity.rangeOverflow)
|
|
563
|
+
fail('rangeOverflow', message);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
if (inputEl?.validity.typeMismatch)
|
|
568
|
+
fail('typeMismatch', inputEl.validationMessage);
|
|
569
|
+
if (inputEl?.validity.patternMismatch)
|
|
570
|
+
fail('patternMismatch', inputEl.validationMessage);
|
|
571
|
+
const { tooShort, tooLong } = lengthValidity(current, {
|
|
572
|
+
minlength: this.getProperty('minlength'),
|
|
573
|
+
maxlength: this.getProperty('maxlength'),
|
|
574
|
+
tooShortMessage: this.tooShortMessage,
|
|
575
|
+
tooLongMessage: this.tooLongMessage,
|
|
576
|
+
}, inputEl);
|
|
577
|
+
if (tooShort)
|
|
578
|
+
fail('tooShort', tooShort);
|
|
579
|
+
if (tooLong)
|
|
580
|
+
fail('tooLong', tooLong);
|
|
581
|
+
}
|
|
582
|
+
this.applyValidity(flags, messages[0], inputEl ?? undefined);
|
|
483
583
|
}
|
|
484
584
|
}
|
|
485
585
|
TyInput.formAssociated = true;
|
|
@@ -538,6 +638,41 @@ type: 'boolean',
|
|
|
538
638
|
visual: true,
|
|
539
639
|
default: false
|
|
540
640
|
},
|
|
641
|
+
pattern: {
|
|
642
|
+
type: 'string',
|
|
643
|
+
visual: true,
|
|
644
|
+
default: ''
|
|
645
|
+
},
|
|
646
|
+
minlength: {
|
|
647
|
+
type: 'string',
|
|
648
|
+
visual: true,
|
|
649
|
+
default: ''
|
|
650
|
+
},
|
|
651
|
+
maxlength: {
|
|
652
|
+
type: 'string',
|
|
653
|
+
visual: true,
|
|
654
|
+
default: ''
|
|
655
|
+
},
|
|
656
|
+
min: {
|
|
657
|
+
type: 'string',
|
|
658
|
+
visual: true,
|
|
659
|
+
default: ''
|
|
660
|
+
},
|
|
661
|
+
max: {
|
|
662
|
+
type: 'string',
|
|
663
|
+
visual: true,
|
|
664
|
+
default: ''
|
|
665
|
+
},
|
|
666
|
+
tooShortMessage: {
|
|
667
|
+
type: 'string',
|
|
668
|
+
visual: true,
|
|
669
|
+
default: ''
|
|
670
|
+
},
|
|
671
|
+
tooLongMessage: {
|
|
672
|
+
type: 'string',
|
|
673
|
+
visual: true,
|
|
674
|
+
default: ''
|
|
675
|
+
},
|
|
541
676
|
error: {
|
|
542
677
|
type: 'string',
|
|
543
678
|
visual: true,
|
|
@@ -52,6 +52,8 @@ export declare class TyModal extends HTMLElement {
|
|
|
52
52
|
set open(v: boolean);
|
|
53
53
|
get noBackdrop(): boolean;
|
|
54
54
|
set noBackdrop(v: boolean);
|
|
55
|
+
get noZoom(): boolean;
|
|
56
|
+
set noZoom(v: boolean);
|
|
55
57
|
get preventOutsideClick(): boolean;
|
|
56
58
|
set preventOutsideClick(v: boolean);
|
|
57
59
|
get preventEscape(): boolean;
|