@commmerce/ui 1.13.0 → 1.14.0
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/dist/cdn.js +583 -573
- package/dist/components/checkbox.d.ts +3 -0
- package/dist/components/checkbox.js +18 -7
- package/dist/components/color-field.js +8 -4
- package/dist/components/combobox.js +12 -7
- package/dist/components/date-picker.js +17 -6
- package/dist/components/date-range-picker.js +12 -6
- package/dist/components/file-upload.js +12 -9
- package/dist/components/option-group.js +13 -5
- package/dist/components/radio.js +11 -7
- package/dist/components/select.js +12 -8
- package/dist/components/signature-field.js +9 -5
- package/dist/components/text-field.d.ts +35 -0
- package/dist/components/text-field.js +58 -8
- package/dist/custom-elements.json +183 -0
- package/dist/validation.d.ts +39 -0
- package/dist/validation.js +121 -0
- package/package.json +3 -3
|
@@ -9,10 +9,11 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CmOptionGroup_instances, _CmOptionGroup_internals, _CmOptionGroup_id, _CmOptionGroup_defaultValue, _CmOptionGroup_observer, _CmOptionGroup_readChildren, _CmOptionGroup_select, _CmOptionGroup_onKeyDown;
|
|
12
|
+
var _CmOptionGroup_instances, _CmOptionGroup_internals, _CmOptionGroup_v, _CmOptionGroup_id, _CmOptionGroup_defaultValue, _CmOptionGroup_observer, _CmOptionGroup_readChildren, _CmOptionGroup_select, _CmOptionGroup_onKeyDown;
|
|
13
13
|
import { html, css, nothing } from 'lit';
|
|
14
14
|
import { base, define, nextId, logicalKey } from '../base.js';
|
|
15
15
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
16
|
+
import { FieldValidity } from '../validation.js';
|
|
16
17
|
const strings = defineStrings('optionGroup', {
|
|
17
18
|
/** Validation message when `required` and nothing is chosen. */
|
|
18
19
|
required: 'Please select one of these options.',
|
|
@@ -47,6 +48,7 @@ export class CmOptionGroup extends CmLocalizedElement {
|
|
|
47
48
|
this.disabled = false;
|
|
48
49
|
this._slotted = [];
|
|
49
50
|
_CmOptionGroup_internals.set(this, this.attachInternals());
|
|
51
|
+
_CmOptionGroup_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmOptionGroup_internals, "f"), () => this.renderRoot.querySelector('button[tabindex="0"]')?.focus()));
|
|
50
52
|
_CmOptionGroup_id.set(this, nextId('cm-og'));
|
|
51
53
|
_CmOptionGroup_defaultValue.set(this, '');
|
|
52
54
|
_CmOptionGroup_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmOptionGroup_instances, "m", _CmOptionGroup_readChildren).call(this)));
|
|
@@ -64,8 +66,8 @@ export class CmOptionGroup extends CmLocalizedElement {
|
|
|
64
66
|
get validity() { return __classPrivateFieldGet(this, _CmOptionGroup_internals, "f").validity; }
|
|
65
67
|
get validationMessage() { return __classPrivateFieldGet(this, _CmOptionGroup_internals, "f").validationMessage; }
|
|
66
68
|
checkValidity() { return __classPrivateFieldGet(this, _CmOptionGroup_internals, "f").checkValidity(); }
|
|
67
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmOptionGroup_internals, "f").reportValidity(); }
|
|
68
|
-
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmOptionGroup_defaultValue, "f"); }
|
|
69
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmOptionGroup_v, "f").report(() => __classPrivateFieldGet(this, _CmOptionGroup_internals, "f").reportValidity()); }
|
|
70
|
+
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmOptionGroup_defaultValue, "f"); __classPrivateFieldGet(this, _CmOptionGroup_v, "f").reset(); }
|
|
69
71
|
formDisabledCallback(d) { this.disabled = d; }
|
|
70
72
|
formStateRestoreCallback(state) { this.value = state; }
|
|
71
73
|
/** Focuses the selected option, or the first one. */
|
|
@@ -86,26 +88,30 @@ export class CmOptionGroup extends CmLocalizedElement {
|
|
|
86
88
|
__classPrivateFieldGet(this, _CmOptionGroup_internals, "f").setValidity({ valueMissing: true }, this.t('required'), anchor);
|
|
87
89
|
else
|
|
88
90
|
__classPrivateFieldGet(this, _CmOptionGroup_internals, "f").setValidity({});
|
|
91
|
+
__classPrivateFieldGet(this, _CmOptionGroup_v, "f").sync();
|
|
89
92
|
}
|
|
90
93
|
render() {
|
|
91
94
|
const items = this.items;
|
|
92
95
|
const sel = items.findIndex((o) => o.value === this.value && !o.disabled);
|
|
93
96
|
const stop = sel >= 0 ? sel : items.findIndex((o) => !o.disabled);
|
|
94
97
|
const hostLabel = this.getAttribute('aria-label');
|
|
98
|
+
const message = __classPrivateFieldGet(this, _CmOptionGroup_v, "f").message;
|
|
95
99
|
return html `
|
|
96
100
|
${this.label ? html `<span class="label" id="${__classPrivateFieldGet(this, _CmOptionGroup_id, "f")}-l" part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>` : nothing}
|
|
97
101
|
<div class="options" part="options" role="radiogroup"
|
|
98
102
|
aria-labelledby=${this.label ? `${__classPrivateFieldGet(this, _CmOptionGroup_id, "f")}-l` : nothing} aria-label=${!this.label && hostLabel ? hostLabel : nothing}
|
|
99
|
-
aria-required=${this.required ? 'true' : nothing}
|
|
103
|
+
aria-required=${this.required ? 'true' : nothing} aria-invalid=${message ? 'true' : nothing}
|
|
104
|
+
aria-describedby=${message ? `${__classPrivateFieldGet(this, _CmOptionGroup_id, "f")}-err` : nothing}>
|
|
100
105
|
${items.map((o, i) => html `<button type="button" role="radio" part="option" class=${o.tone === 'critical' || o.tone === 'success' ? `tone-${o.tone}` : nothing} aria-checked=${o.value === this.value ? 'true' : 'false'}
|
|
101
106
|
tabindex=${i === stop ? '0' : '-1'} ?disabled=${this.disabled || !!o.disabled}
|
|
102
107
|
@click=${() => __classPrivateFieldGet(this, _CmOptionGroup_instances, "m", _CmOptionGroup_select).call(this, i)} @keydown=${(e) => __classPrivateFieldGet(this, _CmOptionGroup_instances, "m", _CmOptionGroup_onKeyDown).call(this, e, i)}>${o.label}</button>`)}
|
|
103
108
|
</div>
|
|
109
|
+
${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmOptionGroup_id, "f")}-err" role="alert">${message}</p>` : nothing}
|
|
104
110
|
<slot></slot>
|
|
105
111
|
`;
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
|
-
_CmOptionGroup_internals = new WeakMap(), _CmOptionGroup_id = new WeakMap(), _CmOptionGroup_defaultValue = new WeakMap(), _CmOptionGroup_observer = new WeakMap(), _CmOptionGroup_instances = new WeakSet(), _CmOptionGroup_readChildren = function _CmOptionGroup_readChildren() {
|
|
114
|
+
_CmOptionGroup_internals = new WeakMap(), _CmOptionGroup_v = new WeakMap(), _CmOptionGroup_id = new WeakMap(), _CmOptionGroup_defaultValue = new WeakMap(), _CmOptionGroup_observer = new WeakMap(), _CmOptionGroup_instances = new WeakSet(), _CmOptionGroup_readChildren = function _CmOptionGroup_readChildren() {
|
|
109
115
|
const opts = [...this.querySelectorAll('option')];
|
|
110
116
|
this._slotted = opts.map((o) => {
|
|
111
117
|
const opt = { value: o.value, label: o.label || o.textContent.trim(), disabled: o.disabled };
|
|
@@ -190,6 +196,8 @@ CmOptionGroup.styles = [
|
|
|
190
196
|
background: color-mix(in srgb, var(--_tone) 80%, var(--cm-text-default)); border-color: color-mix(in srgb, var(--_tone) 80%, var(--cm-text-default));
|
|
191
197
|
}
|
|
192
198
|
slot { display: none; }
|
|
199
|
+
/* 1.14: the field's own message under the options. */
|
|
200
|
+
.error { margin: var(--cm-space-8) 0 0; font-size: var(--cm-type-body-xs-size); line-height: var(--cm-type-body-xs-line-height); color: var(--cm-text-critical); }
|
|
193
201
|
@media (pointer: coarse) { button { min-height: var(--cm-control-height-touch, 44px); } }
|
|
194
202
|
`,
|
|
195
203
|
];
|
package/dist/components/radio.js
CHANGED
|
@@ -9,10 +9,11 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CmRadio_id, _CmRadioGroup_instances, _CmRadioGroup_internals, _CmRadioGroup_id, _CmRadioGroup_defaultValue, _CmRadioGroup_pristine, _CmRadioGroup_rendered, _CmRadioGroup_adopting, _CmRadioGroup_adoptInitial, _CmRadioGroup_onSlotChange, _CmRadioGroup_radios, _CmRadioGroup_enabled, _CmRadioGroup_sync, _CmRadioGroup_select, _CmRadioGroup_onClick, _CmRadioGroup_onKeyDown, _CmRadioGroup_hasLabel;
|
|
12
|
+
var _CmRadio_id, _CmRadioGroup_instances, _CmRadioGroup_internals, _CmRadioGroup_v, _CmRadioGroup_id, _CmRadioGroup_defaultValue, _CmRadioGroup_pristine, _CmRadioGroup_rendered, _CmRadioGroup_adopting, _CmRadioGroup_adoptInitial, _CmRadioGroup_onSlotChange, _CmRadioGroup_radios, _CmRadioGroup_enabled, _CmRadioGroup_sync, _CmRadioGroup_select, _CmRadioGroup_onClick, _CmRadioGroup_onKeyDown, _CmRadioGroup_hasLabel;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { base, define, nextId, logicalKey } from '../base.js';
|
|
15
15
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
16
|
+
import { FieldValidity } from '../validation.js';
|
|
16
17
|
/**
|
|
17
18
|
* One option in a `<cm-radio-group>`. On its own it does nothing: the group owns
|
|
18
19
|
* the value, the keyboard behaviour and the form submission.
|
|
@@ -120,6 +121,7 @@ export class CmRadioGroup extends CmLocalizedElement {
|
|
|
120
121
|
/** Blocks every option. Also set by a disabled `<fieldset>`. */
|
|
121
122
|
this.disabled = false;
|
|
122
123
|
_CmRadioGroup_internals.set(this, this.attachInternals());
|
|
124
|
+
_CmRadioGroup_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmRadioGroup_internals, "f")));
|
|
123
125
|
_CmRadioGroup_id.set(this, nextId('cm-rg'));
|
|
124
126
|
_CmRadioGroup_defaultValue.set(this, '');
|
|
125
127
|
// Options may be parsed or upgraded after the group, so the initial value is taken from a
|
|
@@ -178,8 +180,8 @@ export class CmRadioGroup extends CmLocalizedElement {
|
|
|
178
180
|
get validity() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").validity; }
|
|
179
181
|
get validationMessage() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").validationMessage; }
|
|
180
182
|
checkValidity() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").checkValidity(); }
|
|
181
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").reportValidity(); }
|
|
182
|
-
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmRadioGroup_defaultValue, "f"); }
|
|
183
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmRadioGroup_v, "f").report(() => __classPrivateFieldGet(this, _CmRadioGroup_internals, "f").reportValidity()); }
|
|
184
|
+
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmRadioGroup_defaultValue, "f"); __classPrivateFieldGet(this, _CmRadioGroup_v, "f").reset(); }
|
|
183
185
|
formDisabledCallback(d) { this.disabled = d; }
|
|
184
186
|
formStateRestoreCallback(state) { this.value = state; }
|
|
185
187
|
/** Focuses the selected option, or the first one. */
|
|
@@ -199,22 +201,24 @@ export class CmRadioGroup extends CmLocalizedElement {
|
|
|
199
201
|
__classPrivateFieldGet(this, _CmRadioGroup_internals, "f").setValidity({ valueMissing: true }, this.t('required'), anchor);
|
|
200
202
|
else
|
|
201
203
|
__classPrivateFieldGet(this, _CmRadioGroup_internals, "f").setValidity({});
|
|
204
|
+
__classPrivateFieldGet(this, _CmRadioGroup_v, "f").sync();
|
|
202
205
|
}
|
|
203
206
|
render() {
|
|
204
|
-
const
|
|
207
|
+
const message = __classPrivateFieldGet(this, _CmRadioGroup_v, "f").message;
|
|
208
|
+
const described = [message && `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-help`].filter(Boolean).join(' ');
|
|
205
209
|
return html `<div class="group" role="radiogroup" part="group"
|
|
206
210
|
aria-labelledby=${__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_hasLabel).call(this) ? `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-l` : nothing} aria-label=${__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_hasLabel).call(this) ? nothing : this.getAttribute('aria-label') ?? nothing}
|
|
207
211
|
aria-describedby=${described || nothing}
|
|
208
|
-
aria-required=${this.required ? 'true' : nothing} aria-invalid=${
|
|
212
|
+
aria-required=${this.required ? 'true' : nothing} aria-invalid=${message ? 'true' : nothing}
|
|
209
213
|
aria-disabled=${this.disabled ? 'true' : nothing}>
|
|
210
214
|
<span class="label" id="${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-l" part="label" ?hidden=${!__classPrivateFieldGet(this, _CmRadioGroup_instances, "m", _CmRadioGroup_hasLabel).call(this)}>${this.label}<slot name="label"></slot>${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>
|
|
211
215
|
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
212
|
-
${
|
|
216
|
+
${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-err" role="alert">${message}</p>` : nothing}
|
|
213
217
|
<div class="options" part="options"><slot @slotchange=${__classPrivateFieldGet(this, _CmRadioGroup_onSlotChange, "f")}></slot></div>
|
|
214
218
|
</div>`;
|
|
215
219
|
}
|
|
216
220
|
}
|
|
217
|
-
_CmRadioGroup_internals = new WeakMap(), _CmRadioGroup_id = new WeakMap(), _CmRadioGroup_defaultValue = new WeakMap(), _CmRadioGroup_pristine = new WeakMap(), _CmRadioGroup_rendered = new WeakMap(), _CmRadioGroup_adopting = new WeakMap(), _CmRadioGroup_onSlotChange = new WeakMap(), _CmRadioGroup_sync = new WeakMap(), _CmRadioGroup_onClick = new WeakMap(), _CmRadioGroup_onKeyDown = new WeakMap(), _CmRadioGroup_instances = new WeakSet(), _CmRadioGroup_adoptInitial = function _CmRadioGroup_adoptInitial() {
|
|
221
|
+
_CmRadioGroup_internals = new WeakMap(), _CmRadioGroup_v = new WeakMap(), _CmRadioGroup_id = new WeakMap(), _CmRadioGroup_defaultValue = new WeakMap(), _CmRadioGroup_pristine = new WeakMap(), _CmRadioGroup_rendered = new WeakMap(), _CmRadioGroup_adopting = new WeakMap(), _CmRadioGroup_onSlotChange = new WeakMap(), _CmRadioGroup_sync = new WeakMap(), _CmRadioGroup_onClick = new WeakMap(), _CmRadioGroup_onKeyDown = new WeakMap(), _CmRadioGroup_instances = new WeakSet(), _CmRadioGroup_adoptInitial = function _CmRadioGroup_adoptInitial() {
|
|
218
222
|
if (!__classPrivateFieldGet(this, _CmRadioGroup_pristine, "f"))
|
|
219
223
|
return;
|
|
220
224
|
if (!this.value) {
|
|
@@ -9,10 +9,11 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CmSelect_instances, _CmSelect_internals, _CmSelect_id, _CmSelect_defaultValue, _CmSelect_typed, _CmSelect_typedAt, _CmSelect_observer, _CmSelect_readChildren, _CmSelect_layer, _CmSelect_enabledIndexes, _CmSelect_show, _CmSelect_hide, _CmSelect_commit, _CmSelect_move, _CmSelect_typeahead, _CmSelect_onKeyDown, _CmSelect_onOutside, _CmSelect_onBoxClick, _CmSelect_display, _CmSelect_focusBox;
|
|
12
|
+
var _CmSelect_instances, _CmSelect_internals, _CmSelect_v, _CmSelect_id, _CmSelect_defaultValue, _CmSelect_typed, _CmSelect_typedAt, _CmSelect_observer, _CmSelect_readChildren, _CmSelect_layer, _CmSelect_enabledIndexes, _CmSelect_show, _CmSelect_hide, _CmSelect_commit, _CmSelect_move, _CmSelect_typeahead, _CmSelect_onKeyDown, _CmSelect_onOutside, _CmSelect_onBoxClick, _CmSelect_display, _CmSelect_focusBox;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { base, define, nextId } from '../base.js';
|
|
15
15
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
16
|
+
import { FieldValidity } from '../validation.js';
|
|
16
17
|
import { groupStyles, sortByGroup, groupRuns } from '../popover.js';
|
|
17
18
|
import { fieldStyles, optionStyles } from '../field.js';
|
|
18
19
|
import { TopLayer, topLayerStyles } from '../top-layer.js';
|
|
@@ -79,6 +80,7 @@ export class CmSelect extends CmLocalizedElement {
|
|
|
79
80
|
this._active = -1;
|
|
80
81
|
this._slotted = [];
|
|
81
82
|
_CmSelect_internals.set(this, this.attachInternals());
|
|
83
|
+
_CmSelect_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmSelect_internals, "f")));
|
|
82
84
|
_CmSelect_id.set(this, nextId('cm-sel'));
|
|
83
85
|
_CmSelect_defaultValue.set(this, '');
|
|
84
86
|
_CmSelect_typed.set(this, '');
|
|
@@ -198,8 +200,8 @@ export class CmSelect extends CmLocalizedElement {
|
|
|
198
200
|
get validity() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").validity; }
|
|
199
201
|
get validationMessage() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").validationMessage; }
|
|
200
202
|
checkValidity() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").checkValidity(); }
|
|
201
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmSelect_internals, "f").reportValidity(); }
|
|
202
|
-
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmSelect_defaultValue, "f"); this.open = false; }
|
|
203
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmSelect_v, "f").report(() => __classPrivateFieldGet(this, _CmSelect_internals, "f").reportValidity()); }
|
|
204
|
+
formResetCallback() { this.value = __classPrivateFieldGet(this, _CmSelect_defaultValue, "f"); this.open = false; __classPrivateFieldGet(this, _CmSelect_v, "f").reset(); }
|
|
203
205
|
formDisabledCallback(d) { this.disabled = d; if (d)
|
|
204
206
|
this.open = false; }
|
|
205
207
|
formStateRestoreCallback(state) { this.value = state; }
|
|
@@ -219,6 +221,7 @@ export class CmSelect extends CmLocalizedElement {
|
|
|
219
221
|
__classPrivateFieldGet(this, _CmSelect_internals, "f").setValidity({ valueMissing: true }, this.t('required'), box);
|
|
220
222
|
else
|
|
221
223
|
__classPrivateFieldGet(this, _CmSelect_internals, "f").setValidity({});
|
|
224
|
+
__classPrivateFieldGet(this, _CmSelect_v, "f").sync();
|
|
222
225
|
// The list opens in the top layer (1.10.1, #35), so later rows and scroll containers can't cover or clip it.
|
|
223
226
|
if (changed.has('open')) {
|
|
224
227
|
if (this.open)
|
|
@@ -235,7 +238,8 @@ export class CmSelect extends CmLocalizedElement {
|
|
|
235
238
|
render() {
|
|
236
239
|
const items = this.items;
|
|
237
240
|
const current = items.find((o) => o.value === this.value);
|
|
238
|
-
const
|
|
241
|
+
const message = __classPrivateFieldGet(this, _CmSelect_v, "f").message;
|
|
242
|
+
const described = [message && `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-help`].filter(Boolean).join(' ');
|
|
239
243
|
const hostLabel = this.getAttribute('aria-label');
|
|
240
244
|
const option = (o, i) => html `<li role="option" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-o${i}" class=${i === this._active ? 'active' : ''}
|
|
241
245
|
aria-selected=${o.value === this.value ? 'true' : 'false'} aria-disabled=${o.disabled ? 'true' : nothing}
|
|
@@ -250,7 +254,7 @@ export class CmSelect extends CmLocalizedElement {
|
|
|
250
254
|
aria-label=${!this.label && hostLabel ? hostLabel : nothing}
|
|
251
255
|
aria-haspopup="listbox" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-list"
|
|
252
256
|
aria-activedescendant=${this.open && this._active >= 0 ? `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-o${this._active}` : nothing}
|
|
253
|
-
aria-required=${this.required ? 'true' : nothing} aria-invalid=${
|
|
257
|
+
aria-required=${this.required ? 'true' : nothing} aria-invalid=${message ? 'true' : nothing}
|
|
254
258
|
aria-disabled=${this.disabled ? 'true' : nothing} aria-describedby=${described || nothing} aria-busy=${this.loading ? 'true' : nothing}
|
|
255
259
|
@click=${__classPrivateFieldGet(this, _CmSelect_onBoxClick, "f")} @keydown=${__classPrivateFieldGet(this, _CmSelect_onKeyDown, "f")} @blur=${() => __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_hide).call(this)}>
|
|
256
260
|
<span class="text ${current ? '' : 'placeholder'}" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-v">${current ? __classPrivateFieldGet(this, _CmSelect_instances, "m", _CmSelect_display).call(this, current) : this.placeholder}</span>
|
|
@@ -267,13 +271,13 @@ export class CmSelect extends CmLocalizedElement {
|
|
|
267
271
|
: run.rows.map(({ row, index }) => option(row, index)))}
|
|
268
272
|
</ul>
|
|
269
273
|
</div>
|
|
270
|
-
${
|
|
274
|
+
${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-err" role="alert">${message}</p>` : nothing}
|
|
271
275
|
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
272
276
|
<slot></slot>
|
|
273
277
|
</div>`;
|
|
274
278
|
}
|
|
275
279
|
}
|
|
276
|
-
_CmSelect_internals = new WeakMap(), _CmSelect_id = new WeakMap(), _CmSelect_defaultValue = new WeakMap(), _CmSelect_typed = new WeakMap(), _CmSelect_typedAt = new WeakMap(), _CmSelect_observer = new WeakMap(), _CmSelect_layer = new WeakMap(), _CmSelect_onKeyDown = new WeakMap(), _CmSelect_onOutside = new WeakMap(), _CmSelect_onBoxClick = new WeakMap(), _CmSelect_focusBox = new WeakMap(), _CmSelect_instances = new WeakSet(), _CmSelect_readChildren = function _CmSelect_readChildren() {
|
|
280
|
+
_CmSelect_internals = new WeakMap(), _CmSelect_v = new WeakMap(), _CmSelect_id = new WeakMap(), _CmSelect_defaultValue = new WeakMap(), _CmSelect_typed = new WeakMap(), _CmSelect_typedAt = new WeakMap(), _CmSelect_observer = new WeakMap(), _CmSelect_layer = new WeakMap(), _CmSelect_onKeyDown = new WeakMap(), _CmSelect_onOutside = new WeakMap(), _CmSelect_onBoxClick = new WeakMap(), _CmSelect_focusBox = new WeakMap(), _CmSelect_instances = new WeakSet(), _CmSelect_readChildren = function _CmSelect_readChildren() {
|
|
277
281
|
const opts = [...this.querySelectorAll('option')];
|
|
278
282
|
this._slotted = opts.map((o) => {
|
|
279
283
|
const g = o.parentElement?.localName === 'optgroup' ? o.parentElement : null;
|
|
@@ -375,7 +379,7 @@ CmSelect.styles = [
|
|
|
375
379
|
:host([loading]) .box { cursor: progress; }
|
|
376
380
|
.chev { flex: none; color: var(--cm-icon-selected); transition: transform var(--cm-duration-fast) var(--cm-easing-standard); }
|
|
377
381
|
:host([open]) .chev { transform: rotate(180deg); }
|
|
378
|
-
:host([error]:not([error=''])) .box { border-color: var(--cm-border-critical); }
|
|
382
|
+
:host([error]:not([error=''])) .box, :host([data-cm-invalid]) .box { border-color: var(--cm-border-critical); }
|
|
379
383
|
:host([disabled]) .box { background: var(--cm-bg-input-filled); color: var(--cm-text-secondary); border-color: var(--cm-border-subtle); cursor: not-allowed; }
|
|
380
384
|
[role='listbox'] {
|
|
381
385
|
position: absolute; z-index: 20; top: calc(100% + var(--cm-space-4)); inset-inline: 0; min-width: max-content;
|
|
@@ -9,11 +9,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _CmSignatureField_instances, _CmSignatureField_internals, _CmSignatureField_id, _CmSignatureField_defaultValue, _CmSignatureField_defaultTyped, _CmSignatureField_strokes, _CmSignatureField_active, _CmSignatureField_image, _CmSignatureField_own, _CmSignatureField_frame, _CmSignatureField_typeTimer, _CmSignatureField_typeFrom, _CmSignatureField_resize, _CmSignatureField_width, _CmSignatureField_observe, _CmSignatureField_canvas_get, _CmSignatureField_fit, _CmSignatureField_draw, _CmSignatureField_paint, _CmSignatureField_render, _CmSignatureField_point, _CmSignatureField_onDown, _CmSignatureField_onMove, _CmSignatureField_onUp, _CmSignatureField_fontFamily_get, _CmSignatureField_loadFont, _CmSignatureField_onType, _CmSignatureField_typed, _CmSignatureField_onTypeChange, _CmSignatureField_sync, _CmSignatureField_emit, _CmSignatureField_export, _CmSignatureField_select, _CmSignatureField_onTabKey, _CmSignatureField_say, _CmSignatureField_announce, _CmSignatureField_keepFocus, _CmSignatureField_onUndo, _CmSignatureField_onClear;
|
|
12
|
+
var _CmSignatureField_instances, _CmSignatureField_internals, _CmSignatureField_v, _CmSignatureField_id, _CmSignatureField_defaultValue, _CmSignatureField_defaultTyped, _CmSignatureField_strokes, _CmSignatureField_active, _CmSignatureField_image, _CmSignatureField_own, _CmSignatureField_frame, _CmSignatureField_typeTimer, _CmSignatureField_typeFrom, _CmSignatureField_resize, _CmSignatureField_width, _CmSignatureField_observe, _CmSignatureField_canvas_get, _CmSignatureField_fit, _CmSignatureField_draw, _CmSignatureField_paint, _CmSignatureField_render, _CmSignatureField_point, _CmSignatureField_onDown, _CmSignatureField_onMove, _CmSignatureField_onUp, _CmSignatureField_fontFamily_get, _CmSignatureField_loadFont, _CmSignatureField_onType, _CmSignatureField_typed, _CmSignatureField_onTypeChange, _CmSignatureField_sync, _CmSignatureField_emit, _CmSignatureField_export, _CmSignatureField_select, _CmSignatureField_onTabKey, _CmSignatureField_say, _CmSignatureField_announce, _CmSignatureField_keepFocus, _CmSignatureField_onUndo, _CmSignatureField_onClear;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { live } from 'lit/directives/live.js';
|
|
15
15
|
import { base, define, nextId, logicalKey } from '../base.js';
|
|
16
16
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
17
|
+
import { FieldValidity } from '../validation.js';
|
|
17
18
|
const strings = defineStrings('signatureField', {
|
|
18
19
|
/** Name of the Draw / Type tab list when the field has no label. */
|
|
19
20
|
modes: 'How to sign',
|
|
@@ -110,6 +111,7 @@ export class CmSignatureField extends CmLocalizedElement {
|
|
|
110
111
|
/** @internal Text in the polite status region. */
|
|
111
112
|
this._announce = '';
|
|
112
113
|
_CmSignatureField_internals.set(this, this.attachInternals());
|
|
114
|
+
_CmSignatureField_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmSignatureField_internals, "f")));
|
|
113
115
|
_CmSignatureField_id.set(this, nextId('cm-sig'));
|
|
114
116
|
_CmSignatureField_defaultValue.set(this, '');
|
|
115
117
|
_CmSignatureField_defaultTyped.set(this, '');
|
|
@@ -152,8 +154,9 @@ export class CmSignatureField extends CmLocalizedElement {
|
|
|
152
154
|
get validity() { return __classPrivateFieldGet(this, _CmSignatureField_internals, "f").validity; }
|
|
153
155
|
get validationMessage() { return __classPrivateFieldGet(this, _CmSignatureField_internals, "f").validationMessage; }
|
|
154
156
|
checkValidity() { return __classPrivateFieldGet(this, _CmSignatureField_internals, "f").checkValidity(); }
|
|
155
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmSignatureField_internals, "f").reportValidity(); }
|
|
157
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmSignatureField_v, "f").report(() => __classPrivateFieldGet(this, _CmSignatureField_internals, "f").reportValidity()); }
|
|
156
158
|
formResetCallback() {
|
|
159
|
+
__classPrivateFieldGet(this, _CmSignatureField_v, "f").reset();
|
|
157
160
|
__classPrivateFieldSet(this, _CmSignatureField_strokes, [], "f");
|
|
158
161
|
__classPrivateFieldSet(this, _CmSignatureField_active, undefined, "f");
|
|
159
162
|
__classPrivateFieldSet(this, _CmSignatureField_image, undefined, "f");
|
|
@@ -261,11 +264,12 @@ export class CmSignatureField extends CmLocalizedElement {
|
|
|
261
264
|
__classPrivateFieldGet(this, _CmSignatureField_internals, "f").setValidity({ valueMissing: true }, this.t('required'), anchor);
|
|
262
265
|
else
|
|
263
266
|
__classPrivateFieldGet(this, _CmSignatureField_internals, "f").setValidity({});
|
|
267
|
+
__classPrivateFieldGet(this, _CmSignatureField_v, "f").sync();
|
|
264
268
|
}
|
|
265
269
|
render() {
|
|
266
270
|
const id = __classPrivateFieldGet(this, _CmSignatureField_id, "f");
|
|
267
271
|
const hostLabel = this.getAttribute('aria-label');
|
|
268
|
-
const message = this.
|
|
272
|
+
const message = __classPrivateFieldGet(this, _CmSignatureField_v, "f").message;
|
|
269
273
|
const describedBy = [message && `${id}-err`, this.helpText && `${id}-help`].filter(Boolean).join(' ');
|
|
270
274
|
const empty = this.empty;
|
|
271
275
|
const drawEmpty = !__classPrivateFieldGet(this, _CmSignatureField_strokes, "f").length && !__classPrivateFieldGet(this, _CmSignatureField_image, "f");
|
|
@@ -317,7 +321,7 @@ export class CmSignatureField extends CmLocalizedElement {
|
|
|
317
321
|
</div>`;
|
|
318
322
|
}
|
|
319
323
|
}
|
|
320
|
-
_CmSignatureField_internals = new WeakMap(), _CmSignatureField_id = new WeakMap(), _CmSignatureField_defaultValue = new WeakMap(), _CmSignatureField_defaultTyped = new WeakMap(), _CmSignatureField_strokes = new WeakMap(), _CmSignatureField_active = new WeakMap(), _CmSignatureField_image = new WeakMap(), _CmSignatureField_own = new WeakMap(), _CmSignatureField_frame = new WeakMap(), _CmSignatureField_typeTimer = new WeakMap(), _CmSignatureField_typeFrom = new WeakMap(), _CmSignatureField_resize = new WeakMap(), _CmSignatureField_width = new WeakMap(), _CmSignatureField_instances = new WeakSet(), _CmSignatureField_observe = function _CmSignatureField_observe() {
|
|
324
|
+
_CmSignatureField_internals = new WeakMap(), _CmSignatureField_v = new WeakMap(), _CmSignatureField_id = new WeakMap(), _CmSignatureField_defaultValue = new WeakMap(), _CmSignatureField_defaultTyped = new WeakMap(), _CmSignatureField_strokes = new WeakMap(), _CmSignatureField_active = new WeakMap(), _CmSignatureField_image = new WeakMap(), _CmSignatureField_own = new WeakMap(), _CmSignatureField_frame = new WeakMap(), _CmSignatureField_typeTimer = new WeakMap(), _CmSignatureField_typeFrom = new WeakMap(), _CmSignatureField_resize = new WeakMap(), _CmSignatureField_width = new WeakMap(), _CmSignatureField_instances = new WeakSet(), _CmSignatureField_observe = function _CmSignatureField_observe() {
|
|
321
325
|
const pad = this.renderRoot.querySelector('.panel-draw .pad');
|
|
322
326
|
if (!pad || __classPrivateFieldGet(this, _CmSignatureField_resize, "f"))
|
|
323
327
|
return;
|
|
@@ -625,7 +629,7 @@ CmSignatureField.styles = [
|
|
|
625
629
|
background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm);
|
|
626
630
|
}
|
|
627
631
|
.panel:focus-visible .pad, .pad:focus-within { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
|
|
628
|
-
:host([error]:not([error=''])) .pad { border-color: var(--cm-border-critical); }
|
|
632
|
+
:host([error]:not([error=''])) .pad, :host([data-cm-invalid]) .pad { border-color: var(--cm-border-critical); }
|
|
629
633
|
canvas {
|
|
630
634
|
position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair;
|
|
631
635
|
/* The ink: read in script. The transition makes a theme change fire transitionend, which repaints the ink. */
|
|
@@ -16,6 +16,18 @@ declare const strings: {
|
|
|
16
16
|
badTime: string;
|
|
17
17
|
/** Validation, `type="datetime-local"`: the date and time are only partly filled in. */
|
|
18
18
|
badDateTime: string;
|
|
19
|
+
/** Validation, `type="email"`: the text isn't an email address (1.13.1). */
|
|
20
|
+
badEmail: string;
|
|
21
|
+
/** Validation, `type="url"`: the text isn't a full web address (1.13.1). */
|
|
22
|
+
badUrl: string;
|
|
23
|
+
/** Validation, `type="number"`: the text isn't a number (1.13.1). */
|
|
24
|
+
badNumber: string;
|
|
25
|
+
/** Validation: the value doesn't match `pattern` and there is no `pattern-message` (1.14). */
|
|
26
|
+
pattern: string;
|
|
27
|
+
/** Validation: shorter than `minlength` (1.14). `{min}` is the minimum. */
|
|
28
|
+
tooShort: string;
|
|
29
|
+
/** Validation: longer than `maxlength`, for a value set by code (typing stops at the maximum) (1.14). */
|
|
30
|
+
tooLong: string;
|
|
19
31
|
};
|
|
20
32
|
declare module '../localize.js' {
|
|
21
33
|
interface CmStrings {
|
|
@@ -79,6 +91,18 @@ export declare class CmTextField extends CmLocalizedElement {
|
|
|
79
91
|
min: {};
|
|
80
92
|
max: {};
|
|
81
93
|
step: {};
|
|
94
|
+
pattern: {};
|
|
95
|
+
patternMessage: {
|
|
96
|
+
attribute: string;
|
|
97
|
+
};
|
|
98
|
+
minLength: {
|
|
99
|
+
type: NumberConstructor;
|
|
100
|
+
attribute: string;
|
|
101
|
+
};
|
|
102
|
+
maxLength: {
|
|
103
|
+
type: NumberConstructor;
|
|
104
|
+
attribute: string;
|
|
105
|
+
};
|
|
82
106
|
};
|
|
83
107
|
/** Visible label above the box. Required for accessibility unless the field has an aria-label. */
|
|
84
108
|
label: string;
|
|
@@ -125,6 +149,17 @@ export declare class CmTextField extends CmLocalizedElement {
|
|
|
125
149
|
* `datetime-local` (`900` = 15 minutes; under 60 shows seconds). `any` allows every value.
|
|
126
150
|
*/
|
|
127
151
|
step?: string;
|
|
152
|
+
/**
|
|
153
|
+
* A regular expression the whole value must match, as on a native input (`[0-9]{6}` for a 6-digit PIN). An empty
|
|
154
|
+
* value is left to `required`. Say what's expected in `pattern-message`. Since 1.14.
|
|
155
|
+
*/
|
|
156
|
+
pattern?: string;
|
|
157
|
+
/** The message when the value doesn't match `pattern`, e.g. "Enter the 6-digit PIN.". Since 1.14. */
|
|
158
|
+
patternMessage: string;
|
|
159
|
+
/** Fewest characters allowed (an empty value is left to `required`). Since 1.14. */
|
|
160
|
+
minLength?: number;
|
|
161
|
+
/** Most characters allowed: typing stops there, and a longer value set by code is invalid. Since 1.14. */
|
|
162
|
+
maxLength?: number;
|
|
128
163
|
static styles: import("lit").CSSResult[];
|
|
129
164
|
connectedCallback(): void;
|
|
130
165
|
get form(): HTMLFormElement | null;
|
|
@@ -9,12 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _CmTextField_instances, _CmTextField_internals, _CmTextField_id, _CmTextField_defaultValue, _CmTextField_validate, _CmTextField_show, _CmTextField_nearest, _CmTextField_onInput, _CmTextField_onBlur, _CmTextField_onChange;
|
|
12
|
+
var _CmTextField_instances, _CmTextField_internals, _CmTextField_v, _CmTextField_id, _CmTextField_defaultValue, _CmTextField_matches, _CmTextField_validate, _CmTextField_show, _CmTextField_nearest, _CmTextField_onInput, _CmTextField_onBlur, _CmTextField_onChange;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { live } from 'lit/directives/live.js';
|
|
15
15
|
import { base, define, nextId } from '../base.js';
|
|
16
16
|
import { fieldStyles } from '../field.js';
|
|
17
17
|
import { CmLocalizedElement, defineStrings, formatDate } from '../localize.js';
|
|
18
|
+
import { FieldValidity } from '../validation.js';
|
|
18
19
|
const strings = defineStrings('textField', {
|
|
19
20
|
/** Validation message when `required` and empty. */
|
|
20
21
|
required: 'Please fill in this field.',
|
|
@@ -32,6 +33,18 @@ const strings = defineStrings('textField', {
|
|
|
32
33
|
badTime: 'Enter a complete time.',
|
|
33
34
|
/** Validation, `type="datetime-local"`: the date and time are only partly filled in. */
|
|
34
35
|
badDateTime: 'Enter a complete date and time.',
|
|
36
|
+
/** Validation, `type="email"`: the text isn't an email address (1.13.1). */
|
|
37
|
+
badEmail: 'Enter an email address like name@example.com.',
|
|
38
|
+
/** Validation, `type="url"`: the text isn't a full web address (1.13.1). */
|
|
39
|
+
badUrl: 'Enter a web address like https://example.com.',
|
|
40
|
+
/** Validation, `type="number"`: the text isn't a number (1.13.1). */
|
|
41
|
+
badNumber: 'Enter a number.',
|
|
42
|
+
/** Validation: the value doesn't match `pattern` and there is no `pattern-message` (1.14). */
|
|
43
|
+
pattern: 'Enter a value in the requested format.',
|
|
44
|
+
/** Validation: shorter than `minlength` (1.14). `{min}` is the minimum. */
|
|
45
|
+
tooShort: 'Enter at least {min} characters.',
|
|
46
|
+
/** Validation: longer than `maxlength`, for a value set by code (typing stops at the maximum) (1.14). */
|
|
47
|
+
tooLong: 'Enter {max} characters or fewer.',
|
|
35
48
|
});
|
|
36
49
|
/**
|
|
37
50
|
* Labelled single- or multi-line input. Participates in native forms.
|
|
@@ -76,7 +89,10 @@ export class CmTextField extends CmLocalizedElement {
|
|
|
76
89
|
this.readonly = false;
|
|
77
90
|
/** `small`: a 32px box with a 13px label, for toolbars, filter rows and filter panels. Default: a 40px box (since 1.6, owner standard; was 36px). On touch screens both are 44px. */
|
|
78
91
|
this.size = 'default';
|
|
92
|
+
/** The message when the value doesn't match `pattern`, e.g. "Enter the 6-digit PIN.". Since 1.14. */
|
|
93
|
+
this.patternMessage = '';
|
|
79
94
|
_CmTextField_internals.set(this, this.attachInternals());
|
|
95
|
+
_CmTextField_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmTextField_internals, "f")));
|
|
80
96
|
_CmTextField_id.set(this, nextId('cm-tf'));
|
|
81
97
|
_CmTextField_defaultValue.set(this, '');
|
|
82
98
|
}
|
|
@@ -88,10 +104,11 @@ export class CmTextField extends CmLocalizedElement {
|
|
|
88
104
|
get validity() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").validity; }
|
|
89
105
|
get validationMessage() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").validationMessage; }
|
|
90
106
|
checkValidity() { __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this); return __classPrivateFieldGet(this, _CmTextField_internals, "f").checkValidity(); }
|
|
91
|
-
reportValidity() { __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this); return __classPrivateFieldGet(this, _CmTextField_internals, "f").reportValidity(); }
|
|
107
|
+
reportValidity() { __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this); return __classPrivateFieldGet(this, _CmTextField_v, "f").report(() => __classPrivateFieldGet(this, _CmTextField_internals, "f").reportValidity()); }
|
|
92
108
|
formResetCallback() {
|
|
93
109
|
this.value = __classPrivateFieldGet(this, _CmTextField_defaultValue, "f");
|
|
94
110
|
this.error = '';
|
|
111
|
+
__classPrivateFieldGet(this, _CmTextField_v, "f").reset();
|
|
95
112
|
}
|
|
96
113
|
formDisabledCallback(disabled) { this.disabled = disabled; }
|
|
97
114
|
updated() {
|
|
@@ -99,21 +116,26 @@ export class CmTextField extends CmLocalizedElement {
|
|
|
99
116
|
__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this);
|
|
100
117
|
}
|
|
101
118
|
render() {
|
|
102
|
-
const
|
|
119
|
+
const message = __classPrivateFieldGet(this, _CmTextField_v, "f").message;
|
|
120
|
+
const describedBy = [message && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-help`].filter(Boolean).join(' ') || nothing;
|
|
103
121
|
const common = {
|
|
104
122
|
id: __classPrivateFieldGet(this, _CmTextField_id, "f"),
|
|
105
|
-
invalid:
|
|
123
|
+
invalid: message ? 'true' : nothing,
|
|
106
124
|
};
|
|
125
|
+
const minLength = this.minLength != null && this.minLength > 0 ? this.minLength : nothing;
|
|
126
|
+
const maxLength = this.maxLength != null && this.maxLength >= 0 ? this.maxLength : nothing;
|
|
107
127
|
const control = this.multiline
|
|
108
128
|
? html `<textarea class="input" part="input" id=${common.id} rows=${this.rows}
|
|
109
129
|
.value=${live(this.value)} placeholder=${this.placeholder || nothing}
|
|
130
|
+
minlength=${minLength} maxlength=${maxLength}
|
|
110
131
|
?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
|
|
111
132
|
aria-invalid=${common.invalid} aria-describedby=${describedBy}
|
|
112
|
-
@input=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onInput)} @change=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onChange)}></textarea>`
|
|
133
|
+
@input=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onInput)} @change=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onChange)} @blur=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onBlur)}></textarea>`
|
|
113
134
|
: html `<input class="input" part="input" id=${common.id} type=${this.type}
|
|
114
135
|
.value=${live(this.value)} placeholder=${this.placeholder || nothing}
|
|
115
136
|
autocomplete=${this.autocomplete ?? nothing}
|
|
116
137
|
min=${this.min || nothing} max=${this.max || nothing} step=${this.step || nothing}
|
|
138
|
+
pattern=${this.pattern || nothing} minlength=${minLength} maxlength=${maxLength}
|
|
117
139
|
?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
|
|
118
140
|
aria-invalid=${common.invalid} aria-describedby=${describedBy}
|
|
119
141
|
@input=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onInput)} @change=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onChange)} @blur=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onBlur)} />`;
|
|
@@ -122,12 +144,22 @@ export class CmTextField extends CmLocalizedElement {
|
|
|
122
144
|
? html `<label class="label" for=${__classPrivateFieldGet(this, _CmTextField_id, "f")} part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}${this.hint ? html `<span class="hint">[${this.hint}]</span>` : nothing}</label>`
|
|
123
145
|
: nothing}
|
|
124
146
|
${control}
|
|
125
|
-
${
|
|
147
|
+
${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err" role="alert">${message}</p>` : nothing}
|
|
126
148
|
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmTextField_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
127
149
|
</div>`;
|
|
128
150
|
}
|
|
129
151
|
}
|
|
130
|
-
_CmTextField_internals = new WeakMap(), _CmTextField_id = new WeakMap(), _CmTextField_defaultValue = new WeakMap(), _CmTextField_instances = new WeakSet(),
|
|
152
|
+
_CmTextField_internals = new WeakMap(), _CmTextField_v = new WeakMap(), _CmTextField_id = new WeakMap(), _CmTextField_defaultValue = new WeakMap(), _CmTextField_instances = new WeakSet(), _CmTextField_matches = function _CmTextField_matches(value) {
|
|
153
|
+
if (!this.pattern)
|
|
154
|
+
return true;
|
|
155
|
+
for (const flags of ['v', 'u']) {
|
|
156
|
+
try {
|
|
157
|
+
return new RegExp(`^(?:${this.pattern})$`, flags).test(value);
|
|
158
|
+
}
|
|
159
|
+
catch { /* try the next flag */ }
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}, _CmTextField_validate = function _CmTextField_validate() {
|
|
131
163
|
const control = this.renderRoot.querySelector('.input');
|
|
132
164
|
const native = control instanceof HTMLInputElement ? control.validity : null;
|
|
133
165
|
const dated = this.type === 'time' || this.type === 'datetime-local';
|
|
@@ -136,8 +168,21 @@ _CmTextField_internals = new WeakMap(), _CmTextField_id = new WeakMap(), _CmText
|
|
|
136
168
|
// A half-typed time reads as an empty value; say so instead of "fill in this field".
|
|
137
169
|
else if (dated && native?.badInput)
|
|
138
170
|
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ badInput: true }, this.t(this.type === 'time' ? 'badTime' : 'badDateTime'), control ?? undefined);
|
|
171
|
+
// Text that isn't a number reads as an empty value; say so instead of "fill in this field" or accepting it (1.13.1).
|
|
172
|
+
else if (this.type === 'number' && native?.badInput)
|
|
173
|
+
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ badInput: true }, this.t('badNumber'), control ?? undefined);
|
|
139
174
|
else if (this.required && !this.value)
|
|
140
175
|
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ valueMissing: true }, this.t('required'), control ?? undefined);
|
|
176
|
+
// The browser's own email and web address checks (before 1.13.1 they were ignored and any text was valid).
|
|
177
|
+
else if (!this.multiline && native?.typeMismatch)
|
|
178
|
+
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ typeMismatch: true }, this.t(this.type === 'url' ? 'badUrl' : 'badEmail'), control ?? undefined);
|
|
179
|
+
// Lengths are checked here, not by the browser, which only flags them after the person edits (1.14).
|
|
180
|
+
else if (this.value && this.minLength != null && this.minLength > 0 && this.value.length < this.minLength)
|
|
181
|
+
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ tooShort: true }, this.t('tooShort', { min: this.minLength }), control ?? undefined);
|
|
182
|
+
else if (this.value && this.maxLength != null && this.maxLength >= 0 && this.value.length > this.maxLength)
|
|
183
|
+
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ tooLong: true }, this.t('tooLong', { max: this.maxLength }), control ?? undefined);
|
|
184
|
+
else if (this.value && !__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_matches).call(this, this.value))
|
|
185
|
+
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ patternMismatch: true }, this.patternMessage || this.t('pattern'), control ?? undefined);
|
|
141
186
|
else if (!this.multiline && native?.rangeUnderflow)
|
|
142
187
|
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ rangeUnderflow: true }, this.t(this.type === 'number' ? 'numberUnderflow' : 'rangeUnderflow', { min: __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_show).call(this, this.min ?? '') }), control ?? undefined);
|
|
143
188
|
else if (!this.multiline && native?.rangeOverflow)
|
|
@@ -147,6 +192,7 @@ _CmTextField_internals = new WeakMap(), _CmTextField_id = new WeakMap(), _CmText
|
|
|
147
192
|
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ stepMismatch: true }, this.t('stepMismatch', __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_nearest).call(this, control)), control ?? undefined);
|
|
148
193
|
else
|
|
149
194
|
__classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({});
|
|
195
|
+
__classPrivateFieldGet(this, _CmTextField_v, "f").sync();
|
|
150
196
|
}, _CmTextField_show = function _CmTextField_show(v) {
|
|
151
197
|
const locale = this.locale;
|
|
152
198
|
if (this.type === 'number' && v !== '' && Number.isFinite(Number(v)))
|
|
@@ -209,6 +255,10 @@ CmTextField.properties = {
|
|
|
209
255
|
min: {},
|
|
210
256
|
max: {},
|
|
211
257
|
step: {},
|
|
258
|
+
pattern: {},
|
|
259
|
+
patternMessage: { attribute: 'pattern-message' },
|
|
260
|
+
minLength: { type: Number, attribute: 'minlength' },
|
|
261
|
+
maxLength: { type: Number, attribute: 'maxlength' },
|
|
212
262
|
};
|
|
213
263
|
CmTextField.styles = [
|
|
214
264
|
base,
|
|
@@ -228,7 +278,7 @@ CmTextField.styles = [
|
|
|
228
278
|
.input:focus { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
|
|
229
279
|
.input:read-only, .input:disabled { background: var(--cm-bg-input-filled); }
|
|
230
280
|
.input:disabled { color: var(--cm-text-secondary); border-color: var(--cm-border-subtle); cursor: not-allowed; }
|
|
231
|
-
:host([error]:not([error=''])) .input { border-color: var(--cm-border-critical); }
|
|
281
|
+
:host([error]:not([error=''])) .input, :host([data-cm-invalid]) .input { border-color: var(--cm-border-critical); }
|
|
232
282
|
`,
|
|
233
283
|
];
|
|
234
284
|
define('cm-text-field', CmTextField);
|