@commmerce/ui 1.13.1 → 1.15.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.
@@ -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
  ];
@@ -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 described = [this.error && `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-help`].filter(Boolean).join(' ');
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=${this.error ? 'true' : nothing}
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
- ${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmRadioGroup_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
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 described = [this.error && `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmSelect_id, "f")}-help`].filter(Boolean).join(' ');
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=${this.error ? 'true' : nothing}
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
- ${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmSelect_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
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.error;
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. */
@@ -22,6 +22,12 @@ declare const strings: {
22
22
  badUrl: string;
23
23
  /** Validation, `type="number"`: the text isn't a number (1.13.1). */
24
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;
25
31
  };
26
32
  declare module '../localize.js' {
27
33
  interface CmStrings {
@@ -79,12 +85,27 @@ export declare class CmTextField extends CmLocalizedElement {
79
85
  reflect: boolean;
80
86
  };
81
87
  autocomplete: {};
88
+ inputMode: {
89
+ attribute: string;
90
+ };
82
91
  size: {
83
92
  reflect: boolean;
84
93
  };
85
94
  min: {};
86
95
  max: {};
87
96
  step: {};
97
+ pattern: {};
98
+ patternMessage: {
99
+ attribute: string;
100
+ };
101
+ minLength: {
102
+ type: NumberConstructor;
103
+ attribute: string;
104
+ };
105
+ maxLength: {
106
+ type: NumberConstructor;
107
+ attribute: string;
108
+ };
88
109
  };
89
110
  /** Visible label above the box. Required for accessibility unless the field has an aria-label. */
90
111
  label: string;
@@ -117,6 +138,12 @@ export declare class CmTextField extends CmLocalizedElement {
117
138
  readonly: boolean;
118
139
  /** Native autocomplete hint, e.g. `email`, `postal-code`. */
119
140
  autocomplete?: string;
141
+ /**
142
+ * Which on-screen keyboard phones open: `email`, `url`, `tel`, `numeric`, `decimal`, `search` or `text`, passed to the
143
+ * inner input. Use it with `type="text"` when your own check replaces the browser's (for example an email rule that
144
+ * matches your server), so the box still opens the right keyboard. Since 1.15.
145
+ */
146
+ inputMode: string;
120
147
  /** `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. */
121
148
  size: 'default' | 'medium' | 'small';
122
149
  /**
@@ -131,6 +158,17 @@ export declare class CmTextField extends CmLocalizedElement {
131
158
  * `datetime-local` (`900` = 15 minutes; under 60 shows seconds). `any` allows every value.
132
159
  */
133
160
  step?: string;
161
+ /**
162
+ * A regular expression the whole value must match, as on a native input (`[0-9]{6}` for a 6-digit PIN). An empty
163
+ * value is left to `required`. Say what's expected in `pattern-message`. Since 1.14.
164
+ */
165
+ pattern?: string;
166
+ /** The message when the value doesn't match `pattern`, e.g. "Enter the 6-digit PIN.". Since 1.14. */
167
+ patternMessage: string;
168
+ /** Fewest characters allowed (an empty value is left to `required`). Since 1.14. */
169
+ minLength?: number;
170
+ /** Most characters allowed: typing stops there, and a longer value set by code is invalid. Since 1.14. */
171
+ maxLength?: number;
134
172
  static styles: import("lit").CSSResult[];
135
173
  connectedCallback(): void;
136
174
  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.',
@@ -38,6 +39,12 @@ const strings = defineStrings('textField', {
38
39
  badUrl: 'Enter a web address like https://example.com.',
39
40
  /** Validation, `type="number"`: the text isn't a number (1.13.1). */
40
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.',
41
48
  });
42
49
  /**
43
50
  * Labelled single- or multi-line input. Participates in native forms.
@@ -80,9 +87,18 @@ export class CmTextField extends CmLocalizedElement {
80
87
  this.disabled = false;
81
88
  /** Shows the value on the filled background; the value is still submitted. */
82
89
  this.readonly = false;
90
+ /**
91
+ * Which on-screen keyboard phones open: `email`, `url`, `tel`, `numeric`, `decimal`, `search` or `text`, passed to the
92
+ * inner input. Use it with `type="text"` when your own check replaces the browser's (for example an email rule that
93
+ * matches your server), so the box still opens the right keyboard. Since 1.15.
94
+ */
95
+ this.inputMode = '';
83
96
  /** `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. */
84
97
  this.size = 'default';
98
+ /** The message when the value doesn't match `pattern`, e.g. "Enter the 6-digit PIN.". Since 1.14. */
99
+ this.patternMessage = '';
85
100
  _CmTextField_internals.set(this, this.attachInternals());
101
+ _CmTextField_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmTextField_internals, "f")));
86
102
  _CmTextField_id.set(this, nextId('cm-tf'));
87
103
  _CmTextField_defaultValue.set(this, '');
88
104
  }
@@ -94,10 +110,11 @@ export class CmTextField extends CmLocalizedElement {
94
110
  get validity() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").validity; }
95
111
  get validationMessage() { return __classPrivateFieldGet(this, _CmTextField_internals, "f").validationMessage; }
96
112
  checkValidity() { __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this); return __classPrivateFieldGet(this, _CmTextField_internals, "f").checkValidity(); }
97
- reportValidity() { __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this); return __classPrivateFieldGet(this, _CmTextField_internals, "f").reportValidity(); }
113
+ reportValidity() { __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this); return __classPrivateFieldGet(this, _CmTextField_v, "f").report(() => __classPrivateFieldGet(this, _CmTextField_internals, "f").reportValidity()); }
98
114
  formResetCallback() {
99
115
  this.value = __classPrivateFieldGet(this, _CmTextField_defaultValue, "f");
100
116
  this.error = '';
117
+ __classPrivateFieldGet(this, _CmTextField_v, "f").reset();
101
118
  }
102
119
  formDisabledCallback(disabled) { this.disabled = disabled; }
103
120
  updated() {
@@ -105,21 +122,27 @@ export class CmTextField extends CmLocalizedElement {
105
122
  __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_validate).call(this);
106
123
  }
107
124
  render() {
108
- const describedBy = [this.error && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-help`].filter(Boolean).join(' ') || nothing;
125
+ const message = __classPrivateFieldGet(this, _CmTextField_v, "f").message;
126
+ const describedBy = [message && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmTextField_id, "f")}-help`].filter(Boolean).join(' ') || nothing;
109
127
  const common = {
110
128
  id: __classPrivateFieldGet(this, _CmTextField_id, "f"),
111
- invalid: this.error ? 'true' : nothing,
129
+ invalid: message ? 'true' : nothing,
112
130
  };
131
+ const minLength = this.minLength != null && this.minLength > 0 ? this.minLength : nothing;
132
+ const maxLength = this.maxLength != null && this.maxLength >= 0 ? this.maxLength : nothing;
113
133
  const control = this.multiline
114
134
  ? html `<textarea class="input" part="input" id=${common.id} rows=${this.rows}
115
135
  .value=${live(this.value)} placeholder=${this.placeholder || nothing}
136
+ inputmode=${this.inputMode || nothing}
137
+ minlength=${minLength} maxlength=${maxLength}
116
138
  ?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
117
139
  aria-invalid=${common.invalid} aria-describedby=${describedBy}
118
- @input=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onInput)} @change=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onChange)}></textarea>`
140
+ @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>`
119
141
  : html `<input class="input" part="input" id=${common.id} type=${this.type}
120
142
  .value=${live(this.value)} placeholder=${this.placeholder || nothing}
121
- autocomplete=${this.autocomplete ?? nothing}
143
+ autocomplete=${this.autocomplete ?? nothing} inputmode=${this.inputMode || nothing}
122
144
  min=${this.min || nothing} max=${this.max || nothing} step=${this.step || nothing}
145
+ pattern=${this.pattern || nothing} minlength=${minLength} maxlength=${maxLength}
123
146
  ?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
124
147
  aria-invalid=${common.invalid} aria-describedby=${describedBy}
125
148
  @input=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onInput)} @change=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onChange)} @blur=${__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_onBlur)} />`;
@@ -128,12 +151,22 @@ export class CmTextField extends CmLocalizedElement {
128
151
  ? 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>`
129
152
  : nothing}
130
153
  ${control}
131
- ${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
154
+ ${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmTextField_id, "f")}-err" role="alert">${message}</p>` : nothing}
132
155
  ${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmTextField_id, "f")}-help">${this.helpText}</p>` : nothing}
133
156
  </div>`;
134
157
  }
135
158
  }
136
- _CmTextField_internals = new WeakMap(), _CmTextField_id = new WeakMap(), _CmTextField_defaultValue = new WeakMap(), _CmTextField_instances = new WeakSet(), _CmTextField_validate = function _CmTextField_validate() {
159
+ _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) {
160
+ if (!this.pattern)
161
+ return true;
162
+ for (const flags of ['v', 'u']) {
163
+ try {
164
+ return new RegExp(`^(?:${this.pattern})$`, flags).test(value);
165
+ }
166
+ catch { /* try the next flag */ }
167
+ }
168
+ return true;
169
+ }, _CmTextField_validate = function _CmTextField_validate() {
137
170
  const control = this.renderRoot.querySelector('.input');
138
171
  const native = control instanceof HTMLInputElement ? control.validity : null;
139
172
  const dated = this.type === 'time' || this.type === 'datetime-local';
@@ -150,6 +183,13 @@ _CmTextField_internals = new WeakMap(), _CmTextField_id = new WeakMap(), _CmText
150
183
  // The browser's own email and web address checks (before 1.13.1 they were ignored and any text was valid).
151
184
  else if (!this.multiline && native?.typeMismatch)
152
185
  __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ typeMismatch: true }, this.t(this.type === 'url' ? 'badUrl' : 'badEmail'), control ?? undefined);
186
+ // Lengths are checked here, not by the browser, which only flags them after the person edits (1.14).
187
+ else if (this.value && this.minLength != null && this.minLength > 0 && this.value.length < this.minLength)
188
+ __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ tooShort: true }, this.t('tooShort', { min: this.minLength }), control ?? undefined);
189
+ else if (this.value && this.maxLength != null && this.maxLength >= 0 && this.value.length > this.maxLength)
190
+ __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ tooLong: true }, this.t('tooLong', { max: this.maxLength }), control ?? undefined);
191
+ else if (this.value && !__classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_matches).call(this, this.value))
192
+ __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ patternMismatch: true }, this.patternMessage || this.t('pattern'), control ?? undefined);
153
193
  else if (!this.multiline && native?.rangeUnderflow)
154
194
  __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);
155
195
  else if (!this.multiline && native?.rangeOverflow)
@@ -159,6 +199,7 @@ _CmTextField_internals = new WeakMap(), _CmTextField_id = new WeakMap(), _CmText
159
199
  __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({ stepMismatch: true }, this.t('stepMismatch', __classPrivateFieldGet(this, _CmTextField_instances, "m", _CmTextField_nearest).call(this, control)), control ?? undefined);
160
200
  else
161
201
  __classPrivateFieldGet(this, _CmTextField_internals, "f").setValidity({});
202
+ __classPrivateFieldGet(this, _CmTextField_v, "f").sync();
162
203
  }, _CmTextField_show = function _CmTextField_show(v) {
163
204
  const locale = this.locale;
164
205
  if (this.type === 'number' && v !== '' && Number.isFinite(Number(v)))
@@ -217,10 +258,15 @@ CmTextField.properties = {
217
258
  disabled: { type: Boolean, reflect: true },
218
259
  readonly: { type: Boolean, reflect: true },
219
260
  autocomplete: {},
261
+ inputMode: { attribute: 'inputmode' },
220
262
  size: { reflect: true },
221
263
  min: {},
222
264
  max: {},
223
265
  step: {},
266
+ pattern: {},
267
+ patternMessage: { attribute: 'pattern-message' },
268
+ minLength: { type: Number, attribute: 'minlength' },
269
+ maxLength: { type: Number, attribute: 'maxlength' },
224
270
  };
225
271
  CmTextField.styles = [
226
272
  base,
@@ -240,7 +286,7 @@ CmTextField.styles = [
240
286
  .input:focus { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
241
287
  .input:read-only, .input:disabled { background: var(--cm-bg-input-filled); }
242
288
  .input:disabled { color: var(--cm-text-secondary); border-color: var(--cm-border-subtle); cursor: not-allowed; }
243
- :host([error]:not([error=''])) .input { border-color: var(--cm-border-critical); }
289
+ :host([error]:not([error=''])) .input, :host([data-cm-invalid]) .input { border-color: var(--cm-border-critical); }
244
290
  `,
245
291
  ];
246
292
  define('cm-text-field', CmTextField);