@dile/ui 3.22.1 → 3.23.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.
@@ -27,6 +27,8 @@ export class DileButton extends LitElement {
27
27
  noWrap: { type: Boolean, reflect: true, attribute: 'no-wrap' },
28
28
  /** Accessible name for the button. Required when the button only shows an icon. */
29
29
  label: { type: String },
30
+ /** Accessible description of the button, applied as aria-description (e.g. a related validation message). */
31
+ accessibleDescription: { type: String },
30
32
  _hasText: { type: Boolean, state: true },
31
33
  };
32
34
  }
@@ -175,6 +177,7 @@ export class DileButton extends LitElement {
175
177
  type=${this.type || "button"}
176
178
  aria-label=${ifDefined(this._computedAriaLabel)}
177
179
  aria-busy=${ifDefined(this.loading ? 'true' : undefined)}
180
+ aria-description=${ifDefined(this.accessibleDescription || undefined)}
178
181
  >
179
182
  ${showIcon && this.iconPosition !== 'right' ? this.iconTemplate : ''}
180
183
  <slot @slotchange=${this._onSlotChange}></slot>
@@ -1,5 +1,6 @@
1
1
  import { LitElement, html, css } from 'lit';
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
+ import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
3
4
  import { DileOverlay } from '../../../mixins/overlay/index.js';
4
5
  import { DileCloseDocumentClick } from '../../../mixins/close-document-click/index.js';
5
6
  import { DileCloseOnEscPressed } from '../../../mixins/close-on-esc-pressed/index.js';
@@ -308,6 +309,7 @@ export class DileColorPicker extends DileOverlay(
308
309
  aria-haspopup="dialog"
309
310
  aria-expanded="${this.opened}"
310
311
  aria-label="${this.label || 'Color picker'}"
312
+ aria-describedby="${ifDefined(this.message ? FIELD_MESSAGE_ID : undefined)}"
311
313
  @click="${this.toggle}"
312
314
  ></button>
313
315
  </div>
@@ -361,6 +363,8 @@ export class DileColorPicker extends DileOverlay(
361
363
  type="text"
362
364
  class="hex-input ${this.errored ? 'errored' : ''}"
363
365
  aria-label="Hex color"
366
+ aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
367
+ aria-describedby="${ifDefined(this.message ? FIELD_MESSAGE_ID : undefined)}"
364
368
  maxlength="7"
365
369
  spellcheck="false"
366
370
  autocomplete="off"
@@ -379,7 +383,7 @@ export class DileColorPicker extends DileOverlay(
379
383
  get messageTemplate() {
380
384
  return html`
381
385
  ${this.message
382
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
386
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
383
387
  : ''
384
388
  }
385
389
  `;
@@ -4,7 +4,7 @@ import '../file-preview.js';
4
4
  import '../../button/button.js';
5
5
  import { labelStyles } from '../../input/src/label-styles.js';
6
6
  import { messageStyles } from '../../input/src/message-styles.js';
7
- import { DileEmmitChange } from '../../../mixins/form/index.js';
7
+ import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
8
8
 
9
9
  export class DileDropFile extends DileEmmitChange(LitElement) {
10
10
  static styles = [
@@ -136,7 +136,7 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
136
136
  get messageTemplate() {
137
137
  return html`
138
138
  ${this.message
139
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
139
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
140
140
  : ''
141
141
  }
142
142
  `
@@ -145,7 +145,7 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
145
145
  get dropLabelTemplate() {
146
146
  return html`
147
147
  <p>${this.dropLabel}</p>
148
- <p><dile-button>${this.buttonLabel}</dile-button></p>
148
+ <p><dile-button .accessibleDescription=${this.message || undefined}>${this.buttonLabel}</dile-button></p>
149
149
  `
150
150
  }
151
151
 
@@ -0,0 +1,5 @@
1
+ import { DileFormGroup } from "./src/DileFormGroup.js";
2
+
3
+ if (!customElements.get("dile-form-group")) {
4
+ window.customElements.define("dile-form-group", DileFormGroup);
5
+ }
@@ -0,0 +1 @@
1
+ export { DileFormGroup } from './src/DileFormGroup.js';
@@ -0,0 +1,188 @@
1
+ import { LitElement, html, css, nothing } from 'lit';
2
+
3
+ export class DileFormGroup extends LitElement {
4
+ static styles = [
5
+ css`
6
+ * {
7
+ box-sizing: border-box;
8
+ }
9
+ :host {
10
+ display: block;
11
+ margin: var(--dile-form-group-margin, 0 0 1.5rem);
12
+ }
13
+ :host([hidden]) {
14
+ display: none;
15
+ }
16
+
17
+ .group {
18
+ padding: var(--dile-form-group-padding, 1rem 0 0);
19
+ border-top: var(--dile-form-group-border-top, 1px solid var(--dile-form-group-line-color, var(--dile-secondary-dark-color, #888)));
20
+ }
21
+ :host([variant="box"]) .group {
22
+ padding: var(--dile-form-group-padding, 1rem);
23
+ border: var(--dile-form-group-border, 1px solid var(--dile-form-group-line-color, #ccc));
24
+ border-radius: var(--dile-form-group-border-radius, 0.5rem);
25
+ background-color: var(--dile-form-group-background-color, transparent);
26
+ }
27
+ :host([variant="plain"]) .group {
28
+ padding: var(--dile-form-group-padding, 0);
29
+ border: none;
30
+ }
31
+
32
+ header {
33
+ margin-bottom: var(--dile-form-group-header-margin-bottom, 0.75rem);
34
+ }
35
+ .label {
36
+ margin: 0;
37
+ color: var(--dile-form-group-label-color, var(--dile-secondary-dark-color, #888));
38
+ font-size: var(--dile-form-group-label-font-size, 1.1rem);
39
+ font-weight: var(--dile-form-group-label-font-weight, 300);
40
+ }
41
+ .description {
42
+ margin: 0.25rem 0 0;
43
+ color: var(--dile-form-group-description-color, var(--dile-on-background-color, #303030));
44
+ font-size: var(--dile-form-group-description-font-size, 0.875rem);
45
+ opacity: 0.8;
46
+ }
47
+
48
+ .grid {
49
+ display: grid;
50
+ grid-template-columns: minmax(0, 1fr);
51
+ gap: var(--dile-form-group-gap, 0 1rem);
52
+ align-items: start;
53
+ }
54
+ :host([columns="2"]) .grid {
55
+ grid-template-columns: repeat(2, minmax(0, 1fr));
56
+ }
57
+ :host([columns="3"]) .grid {
58
+ grid-template-columns: repeat(3, minmax(0, 1fr));
59
+ }
60
+ .grid ::slotted([data-span="2"]) {
61
+ grid-column: span 2;
62
+ }
63
+ .grid ::slotted([data-span="full"]) {
64
+ grid-column: 1 / -1;
65
+ }
66
+
67
+ .split {
68
+ display: grid;
69
+ grid-template-columns: var(--dile-form-group-split-columns, 1fr 1fr);
70
+ gap: var(--dile-form-group-gap, 0 1rem);
71
+ align-items: start;
72
+ }
73
+ .split-column {
74
+ display: flex;
75
+ flex-direction: column;
76
+ min-width: 0;
77
+ }
78
+ .split:not(.has-content) {
79
+ display: none;
80
+ }
81
+
82
+ :host([collapsed]) .grid,
83
+ :host([collapsed]) .split {
84
+ grid-template-columns: minmax(0, 1fr);
85
+ }
86
+ :host([collapsed]) .grid ::slotted([data-span]) {
87
+ grid-column: auto;
88
+ }
89
+ `
90
+ ];
91
+
92
+ static get properties() {
93
+ return {
94
+ label: { type: String },
95
+ description: { type: String },
96
+ labelLevel: { type: Number, attribute: 'label-level' },
97
+ columns: { type: Number, reflect: true },
98
+ breakpoint: { type: Number },
99
+ variant: { type: String, reflect: true },
100
+ collapsed: { type: Boolean, reflect: true },
101
+ _hasSplitContent: { state: true },
102
+ _hasLabelSlot: { state: true },
103
+ };
104
+ }
105
+
106
+ constructor() {
107
+ super();
108
+ this.columns = 1;
109
+ this.breakpoint = 600;
110
+ this.variant = 'line';
111
+ this.collapsed = false;
112
+ this._hasSplitContent = false;
113
+ this._hasLabelSlot = false;
114
+ this._width = null;
115
+ this._resizeObserver = new ResizeObserver((entries) => {
116
+ this._width = entries[0].contentRect.width;
117
+ this._updateCollapsed();
118
+ });
119
+ }
120
+
121
+ connectedCallback() {
122
+ super.connectedCallback();
123
+ this._resizeObserver.observe(this);
124
+ }
125
+
126
+ disconnectedCallback() {
127
+ super.disconnectedCallback();
128
+ this._resizeObserver.disconnect();
129
+ }
130
+
131
+ updated(changedProperties) {
132
+ if (changedProperties.has('breakpoint')) {
133
+ this._updateCollapsed();
134
+ }
135
+ }
136
+
137
+ _updateCollapsed() {
138
+ if (this._width === null) return;
139
+ this.collapsed = this.breakpoint > 0 && this._width < this.breakpoint;
140
+ }
141
+
142
+ render() {
143
+ const hasHeader = this.label || this.description || this._hasLabelSlot;
144
+ return html`
145
+ <div
146
+ class="group"
147
+ role="group"
148
+ aria-labelledby=${this.label || this._hasLabelSlot ? 'label' : nothing}
149
+ aria-describedby=${this.description ? 'description' : nothing}
150
+ >
151
+ <header ?hidden=${!hasHeader}>
152
+ ${this.labelTemplate}
153
+ ${this.description ? html`<p id="description" class="description">${this.description}</p>` : ''}
154
+ </header>
155
+ <div class="split ${this._hasSplitContent ? 'has-content' : ''}">
156
+ <div class="split-column"><slot name="left" @slotchange=${this._onSplitSlotChange}></slot></div>
157
+ <div class="split-column"><slot name="right" @slotchange=${this._onSplitSlotChange}></slot></div>
158
+ </div>
159
+ <div class="grid">
160
+ <slot></slot>
161
+ </div>
162
+ </div>
163
+ `;
164
+ }
165
+
166
+ get labelTemplate() {
167
+ const useHeadingRole = this.labelLevel && !this._hasLabelSlot;
168
+ return html`
169
+ <div
170
+ id="label"
171
+ class="label"
172
+ role=${useHeadingRole ? 'heading' : nothing}
173
+ aria-level=${useHeadingRole ? this.labelLevel : nothing}
174
+ >
175
+ <slot name="label" @slotchange=${this._onLabelSlotChange}>${this.label}</slot>
176
+ </div>
177
+ `;
178
+ }
179
+
180
+ _onSplitSlotChange() {
181
+ const slots = this.shadowRoot.querySelectorAll('slot[name="left"], slot[name="right"]');
182
+ this._hasSplitContent = [...slots].some((slot) => slot.assignedNodes().length > 0);
183
+ }
184
+
185
+ _onLabelSlotChange(e) {
186
+ this._hasLabelSlot = e.target.assignedNodes().length > 0;
187
+ }
188
+ }
@@ -1,6 +1,6 @@
1
1
  import { LitElement, html, css } from 'lit';
2
2
  import { ifDefined } from 'lit/directives/if-defined.js';
3
- import { DileEmmitChange, DileFieldMessage } from '../../../mixins/form/index.js';
3
+ import { DileEmmitChange, DileFieldMessage, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
4
4
  import { labelStyles } from './label-styles.js';
5
5
  import { messageStyles } from './message-styles.js';
6
6
 
@@ -44,6 +44,9 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
44
44
  /** Disable the autocomplete of the input field */
45
45
  disableAutocomplete: { type: Boolean },
46
46
 
47
+ /** Value of the autocomplete attribute of the input field (e.g. "email", "new-password"). Defaults to "on". Ignored when disableAutocomplete is set */
48
+ autocomplete: { type: String },
49
+
47
50
  /** ReadOnly attribute */
48
51
  readonly: { type: Boolean },
49
52
 
@@ -58,6 +61,9 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
58
61
 
59
62
  /** Set the application focus to this the input component after the initialization */
60
63
  focusOnStart: { type: Boolean },
64
+
65
+ /** Disabled state inherited from an ancestor fieldset or form */
66
+ _formDisabled: { state: true },
61
67
  };
62
68
  }
63
69
 
@@ -76,9 +82,21 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
76
82
  this.name = '';
77
83
  this.type = 'text';
78
84
  this.types = ['text', 'password', 'email', 'number', 'tel', 'url', 'search', 'date', 'time', 'datetime', 'datetime-local', 'month', 'week'];
85
+ this._formDisabled = false;
79
86
  this.internals = this.attachInternals();
80
87
  }
81
88
 
89
+ /** Called by the browser when the owner form is reset: restores the value of the value attribute */
90
+ formResetCallback() {
91
+ this.value = this.getAttribute('value') ?? '';
92
+ this.clearError();
93
+ }
94
+
95
+ /** Called by the browser when an ancestor fieldset or form is disabled or enabled */
96
+ formDisabledCallback(disabled) {
97
+ this._formDisabled = disabled;
98
+ }
99
+
82
100
  firstUpdated() {
83
101
  if(this.focusOnStart) {
84
102
  this.focus();
@@ -88,7 +106,7 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
88
106
  updated(changedProperties) {
89
107
  if(changedProperties.has('value')) {
90
108
  this.emmitChange();
91
- this.internals.setFormValue(this.value);
109
+ this.internals.setFormValue(this.value ?? '');
92
110
  }
93
111
  }
94
112
 
@@ -156,36 +174,99 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
156
174
  render() {
157
175
  return html`
158
176
  <main>
159
- ${this.label
160
- ? html`<label for="textField">${this.label}</label>`
161
- : ""}
162
- <section class="for-input">
163
- <input
164
- type="${this.availableType(this.type)}"
165
- id="textField"
166
- name="${this.name}"
167
- aria-label="${ifDefined(this.inputAriaLabel)}"
168
- placeholder="${this.placeholder}"
169
- ?disabled="${this.disabled}"
170
- ?readonly="${this.readonly}"
171
- autocomplete="${this.disableAutocomplete ? "off" : "on"}"
172
- .value="${this.computeValue(this.value)}"
173
- class="${this.errored ? 'errored' : ''}"
174
- @keypress="${this._lookForEnter}"
175
- @input="${this._input}"
176
- @blur="${this.doBlur}"
177
- @focus="${this.doFocus}"
178
- />
179
- ${this.labelRight
180
- ? html`<span class="labelright">${this.labelRight}</span>`
181
- : ''
182
- }
177
+ ${this.labelTemplate}
178
+ <section class="for-input">
179
+ ${this.fieldStartTemplate}
180
+ ${this.inputTemplate}
181
+ ${this.fieldEndTemplate}
182
+ ${this.labelRightTemplate}
183
183
  </section>
184
184
  ${this.messageTemplate}
185
185
  </main>
186
186
  `;
187
187
  }
188
188
 
189
+ /** Template of the visible label. Override to customize it. */
190
+ get labelTemplate() {
191
+ return this.label
192
+ ? html`<label for="textField">${this.label}</label>`
193
+ : '';
194
+ }
195
+
196
+ /**
197
+ * Template of the native input. Subclasses should reuse it instead of copying it,
198
+ * customizing it through `inputType`, `computeValue()`, `computeAutocomplete()`,
199
+ * `inputModeValue` and the event handlers (`_input`, `doKeydown`, `doBlur`, `doFocus`).
200
+ */
201
+ get inputTemplate() {
202
+ return html`
203
+ <input
204
+ type="${this.inputType}"
205
+ id="textField"
206
+ name="${this.name}"
207
+ inputmode="${ifDefined(this.inputModeValue)}"
208
+ aria-label="${ifDefined(this.inputAriaLabel)}"
209
+ aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
210
+ aria-describedby="${ifDefined(this.messageDescribedBy)}"
211
+ placeholder="${this.placeholder}"
212
+ ?disabled="${this.isDisabled}"
213
+ ?readonly="${this.readonly}"
214
+ autocomplete="${this.computeAutocomplete()}"
215
+ .value="${this.computeValue(this.value)}"
216
+ class="${this.errored ? 'errored' : ''}"
217
+ @keypress="${this._lookForEnter}"
218
+ @keydown="${this.doKeydown}"
219
+ @input="${this._input}"
220
+ @blur="${this.doBlur}"
221
+ @focus="${this.doFocus}"
222
+ />
223
+ `;
224
+ }
225
+
226
+ /** Content placed inside the field row, before the input (e.g. a prefix selector) */
227
+ get fieldStartTemplate() {
228
+ return '';
229
+ }
230
+
231
+ /** Content placed inside the field row, after the input (e.g. an action button) */
232
+ get fieldEndTemplate() {
233
+ return '';
234
+ }
235
+
236
+ get labelRightTemplate() {
237
+ return this.labelRight
238
+ ? html`<span class="labelright">${this.labelRight}</span>`
239
+ : '';
240
+ }
241
+
242
+ /** Type applied to the native input */
243
+ get inputType() {
244
+ return this.availableType(this.type);
245
+ }
246
+
247
+ /** inputmode applied to the native input. Undefined means no attribute. */
248
+ get inputModeValue() {
249
+ return undefined;
250
+ }
251
+
252
+ /** Value of the autocomplete attribute of the native input */
253
+ computeAutocomplete() {
254
+ if (this.disableAutocomplete) {
255
+ return 'off';
256
+ }
257
+ return this.autocomplete || 'on';
258
+ }
259
+
260
+ /** True when the field is disabled by its own property or by a disabled ancestor fieldset/form */
261
+ get isDisabled() {
262
+ return this.disabled || this._formDisabled;
263
+ }
264
+
265
+ /** Id of the element describing the input (the message), if any */
266
+ get messageDescribedBy() {
267
+ return this.message ? FIELD_MESSAGE_ID : undefined;
268
+ }
269
+
189
270
  /** aria-label for the inner input: accessibleLabel, only when there is no visible label */
190
271
  get inputAriaLabel() {
191
272
  return !this.label && this.accessibleLabel ? this.accessibleLabel : undefined;
@@ -215,7 +296,12 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
215
296
  }
216
297
 
217
298
  get el() {
218
- return this.shadowRoot.querySelector('input');
299
+ return this.shadowRoot?.querySelector('input') ?? null;
300
+ }
301
+
302
+ /** Hook for the keydown event of the native input */
303
+ doKeydown() {
304
+ //
219
305
  }
220
306
 
221
307
  doBlur() {
@@ -229,10 +315,15 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
229
315
  }
230
316
 
231
317
  computeValue(value) {
232
- return value;
318
+ return value ?? '';
233
319
  }
234
320
 
235
- focus() {
236
- this.el.focus();
321
+ /** Moves the focus to the native input. Waits for the first render if needed. */
322
+ focus(options) {
323
+ if (this.el) {
324
+ this.el.focus(options);
325
+ } else {
326
+ this.updateComplete.then(() => this.el?.focus(options));
327
+ }
237
328
  }
238
329
  }
@@ -1,7 +1,16 @@
1
- import { LitElement, html, css } from 'lit';
2
- import { ifDefined } from 'lit/directives/if-defined.js';
3
- import { DileInput } from '../../input/index.js';
1
+ import { html } from 'lit';
2
+ import { DileInput } from './DileInput.js';
3
+ import { FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
4
4
 
5
+ let deprecationWarned = false;
6
+
7
+ /**
8
+ * Input that validates Spanish phone / mobile / fax numbers or an email on blur.
9
+ *
10
+ * @deprecated Not maintained and not documented publicly. It will be removed in a future
11
+ * major version. Use `dile-input-phone` (from `@dile/utils`) for phone numbers and
12
+ * `dile-input` with `type="email"` plus form validation for emails.
13
+ */
5
14
  export class DileInputContact extends DileInput {
6
15
 
7
16
  static get properties() {
@@ -20,6 +29,14 @@ export class DileInputContact extends DileInput {
20
29
  this.valid = true;
21
30
  }
22
31
 
32
+ connectedCallback() {
33
+ super.connectedCallback();
34
+ if (!deprecationWarned) {
35
+ deprecationWarned = true;
36
+ console.warn('dile-input-contact is deprecated and will be removed in a future major version. Use dile-input-phone (@dile/utils) for phone numbers or dile-input type="email" for emails.');
37
+ }
38
+ }
39
+
23
40
  firstUpdated() {
24
41
  super.firstUpdated();
25
42
  if(this.value !== '' && this.value !== undefined) {
@@ -27,48 +44,26 @@ export class DileInputContact extends DileInput {
27
44
  }
28
45
  }
29
46
 
30
- render() {
31
- return html`
32
- <div>
33
- ${this.label ? this.renderLabel : ''}
34
- ${this.renderInput}
35
- ${this.errored && this.messageError != '' ? this.renderMsgError : ''}
36
- </div>
37
- `;
47
+ /** Shows messageError while the value is not valid, otherwise the regular message */
48
+ get messageTemplate() {
49
+ if (this.showMessageError) {
50
+ return html`
51
+ <div id="${FIELD_MESSAGE_ID}" class="message errored-msg"><span>${this.messageError}</span></div>
52
+ `;
53
+ }
54
+ return super.messageTemplate;
38
55
  }
39
56
 
40
- get renderLabel() {
41
- return html`
42
- <label for="textField">${this.label}</label>
43
- `;
57
+ get showMessageError() {
58
+ return this.errored && !!this.messageError;
44
59
  }
45
60
 
46
- get renderInput() {
47
- return html`
48
- <input
49
- type="${this.availableType(this.type)}"
50
- id="textField"
51
- name="${this.name}"
52
- aria-label="${ifDefined(this.inputAriaLabel)}"
53
- placeholder="${this.placeholder}"
54
- ?disabled="${this.disabled}"
55
- ?readonly="${this.readonly}"
56
- autocomplete="${this.disableAutocomplete ? "off" : "on"}"
57
- .value="${this.computeValue(this.value)}"
58
- class="${this.errored ? 'errored' : ''}"
59
- @keypress="${this._lookForEnter}"
60
- @input="${this._input}"
61
- @blur="${this._isValidInput}"
62
- @focus="${this.doFocus}"
63
- >
64
- </input>
65
- `;
61
+ get messageDescribedBy() {
62
+ return this.showMessageError ? FIELD_MESSAGE_ID : super.messageDescribedBy;
66
63
  }
67
64
 
68
- get renderMsgError() {
69
- return html`
70
- <div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.messageError}</span></div>
71
- `;
65
+ doBlur() {
66
+ this._isValidInput();
72
67
  }
73
68
 
74
69
  _input(ev) {
@@ -80,6 +75,9 @@ export class DileInputContact extends DileInput {
80
75
  value: this.value
81
76
  }
82
77
  }));
78
+ if (this.hideErrorOnInput && this.errored) {
79
+ this.clearError();
80
+ }
83
81
  }
84
82
 
85
83
  _isValidInput() {
@@ -105,6 +103,7 @@ export class DileInputContact extends DileInput {
105
103
  this.valid = false;
106
104
  }
107
105
  } else if(this.email) {
106
+ this._isMail = true;
108
107
  if(reMail.test(this.value) || this.value === ""){
109
108
  this.valid = true;
110
109
  }else{
@@ -113,7 +112,6 @@ export class DileInputContact extends DileInput {
113
112
  }
114
113
  }
115
114
  this.errored = !this.valid;
116
- console.log("Válido: " + this.valid);
117
115
  this.dispatchEvent(
118
116
  new CustomEvent('dile-input-contact-blur', {
119
117
  bubbles: true,
@@ -1,5 +1,4 @@
1
1
  import { LitElement, html, css } from 'lit';
2
- import { ifDefined } from 'lit/directives/if-defined.js';
3
2
  import { DileInput } from '../../input/index.js';
4
3
  import '@dile/iconlib/dile-iconlib.js';
5
4
  import '@dile/ui/components/tooltip/tooltip.js';
@@ -13,6 +12,8 @@ export class DileInputIcon extends DileInput {
13
12
  icon: { type: String },
14
13
  /** Callback function that receives the component instance when icon button is clicked */
15
14
  onIconClick: { type: Function },
15
+ /** Accessible name of the icon button. Defaults to the tooltip text */
16
+ iconLabel: { type: String },
16
17
  /** Tooltip text to show on icon hover */
17
18
  tooltip: { type: String },
18
19
  /** Tooltip position: "top", "bottom", "left", "right" */
@@ -69,52 +70,15 @@ export class DileInputIcon extends DileInput {
69
70
  super();
70
71
  this.icon = '';
71
72
  this.onIconClick = null;
73
+ this.iconLabel = '';
72
74
  this.tooltip = '';
73
75
  this.tooltipPosition = 'top';
74
76
  this.tooltipFadeIn = false;
75
77
  this.tooltipArrow = false;
76
78
  }
77
79
 
78
- render() {
79
- return html`
80
- <main>
81
- ${this.labelTemplate}
82
- <section class="for-input">
83
- ${this.inputTemplate}
84
- ${this.icon ? this.renderIconButton() : ''}
85
- ${this.labelRight ? html`<span class="labelright">${this.labelRight}</span>` : ''}
86
- </section>
87
- ${this.messageTemplate}
88
- </main>
89
- `;
90
- }
91
-
92
- get labelTemplate() {
93
- return this.label
94
- ? html`<label for="textField">${this.label}</label>`
95
- : '';
96
- }
97
-
98
- get inputTemplate() {
99
- return html`
100
- <input
101
- type="${this.availableType(this.type)}"
102
- id="textField"
103
- name="${this.name}"
104
- aria-label="${ifDefined(this.inputAriaLabel)}"
105
- placeholder="${this.placeholder}"
106
- ?disabled="${this.disabled}"
107
- ?readonly="${this.readonly}"
108
- autocomplete="${this.disableAutocomplete ? 'off' : 'on'}"
109
- .value="${this.computeValue(this.value)}"
110
- class="${this.errored ? 'errored' : ''}"
111
- @keypress="${this._lookForEnter}"
112
- @input="${this._input}"
113
- @blur="${this.doBlur}"
114
- @focus="${this.doFocus}"
115
- ?selectonfocus="${this.selectOnFocus}"
116
- >
117
- `;
80
+ get fieldEndTemplate() {
81
+ return this.icon ? this.renderIconButton() : '';
118
82
  }
119
83
 
120
84
  get iconTemplate() {
@@ -126,8 +90,8 @@ export class DileInputIcon extends DileInput {
126
90
  class="input-icon-btn"
127
91
  type="button"
128
92
  @click="${this._handleIconClick}"
129
- ?disabled="${this.disabled}"
130
- aria-label="Icon action button"
93
+ ?disabled="${this.isDisabled}"
94
+ aria-label="${this.iconLabel || this.tooltip || 'Icon action button'}"
131
95
  >
132
96
  ${this.iconTemplate}
133
97
  </button>`;
@@ -14,33 +14,19 @@ export class DileInputInteger extends DileInput {
14
14
  `
15
15
  ];
16
16
 
17
- constructor() {
18
- super();
19
- this.changed = false;
20
- }
21
-
17
+ /** Normalizes the typed text on blur. The element-changed event is dispatched by DileInput when the value changes */
22
18
  doBlur(e) {
23
- let num = e.target.value;
24
- if(num.length > 0) {
25
- num = this.formatInteger(num);
26
- }
27
- if(num != e.target.value || this.changed) {
19
+ const typed = e.target.value;
20
+ const num = typed.length > 0 ? this.formatInteger(typed) : typed;
21
+ if (num !== typed) {
28
22
  this.el.value = num;
29
- this.value = num;
30
- this.emmitChange();
31
- this.changed = false;
32
23
  }
24
+ this.value = num;
33
25
  }
34
26
 
27
+ /** Returns the integer as a string, or '0' when the text is not a number */
35
28
  formatInteger(num) {
36
- num = parseInt(num);
37
- return isNaN(num) ? '0' : num;
38
- }
39
-
40
- updated(changedProperties) {
41
- super.updated(changedProperties);
42
- if(changedProperties.has('value') && this.value) {
43
- this.changed = true;
44
- }
29
+ num = parseInt(num, 10);
30
+ return isNaN(num) ? '0' : String(num);
45
31
  }
46
32
  }
@@ -20,17 +20,19 @@ export class DileInputMask extends DileInput {
20
20
  this.content = '';
21
21
  this.language = 'en';
22
22
  this.lazySeparators = false;
23
- this._keyDownHandler = this.handleKeyDown.bind(this);
24
- this._blurHandler = this.handleBlur.bind(this);
25
23
  }
26
24
 
27
25
  firstUpdated() {
28
26
  super.firstUpdated();
29
27
  this.createMaskController(this.mask);
30
- if (this.el) {
31
- this.el.addEventListener('keydown', this._keyDownHandler);
32
- this.el.addEventListener('blur', this._blurHandler);
33
- }
28
+ }
29
+
30
+ doKeydown(e) {
31
+ this.handleKeyDown(e);
32
+ }
33
+
34
+ doBlur(e) {
35
+ this.handleBlur(e);
34
36
  }
35
37
 
36
38
  createMaskController(mask) {
@@ -53,20 +55,12 @@ export class DileInputMask extends DileInput {
53
55
  this.updateMaskedValue();
54
56
  }
55
57
  if (changedProperties.has('value')) {
56
- const transformedValue = this.maskController.transformValue(this.value.slice(0, this.maxChars));
58
+ const transformedValue = this.maskController.transformValue(String(this.value ?? '').slice(0, this.maxChars));
57
59
  this.content = transformedValue;
58
60
  this.updateMaskedValue();
59
61
  }
60
62
  }
61
63
 
62
- disconnectedCallback() {
63
- if (this.el) {
64
- this.el.removeEventListener('keydown', this._keyDownHandler);
65
- this.el.removeEventListener('blur', this._blurHandler);
66
- }
67
- super.disconnectedCallback();
68
- }
69
-
70
64
  updateMaskedValue() {
71
65
  this.maskedValue = this.maskController.maskIt(this.content);
72
66
  }
@@ -25,16 +25,10 @@ export class DileInputMoney extends DileInput {
25
25
  this.decimalSeparator = '.';
26
26
  }
27
27
 
28
+ /** Normalizes the typed text on blur. The element-changed event is dispatched by DileInput when the value changes */
28
29
  doBlur(e) {
29
- let num = e.target.value;
30
- if(num.length > 0) {
31
- num = this.formatMoney(num);
32
- }
33
- if(num != e.target.value || this.changed) {
34
- this.value = num;
35
- this.emmitChange();
36
- this.changed = false;
37
- }
30
+ const typed = e.target.value;
31
+ this.value = typed.length > 0 ? this.formatMoney(typed) : typed;
38
32
  }
39
33
 
40
34
  set(value) {
@@ -43,11 +37,11 @@ export class DileInputMoney extends DileInput {
43
37
  }
44
38
 
45
39
  doFormat() {
46
- this.value = this.formatMoney(this.value.toString());
40
+ this.value = this.formatMoney(this.value);
47
41
  }
48
42
 
49
43
  formatMoney(num) {
50
- num = num.replace(this.decimalSeparator, '.');
44
+ num = String(num ?? '').replace(this.decimalSeparator, '.');
51
45
  num = parseFloat(num);
52
46
  if(isNaN(num)) {
53
47
  return '0.00';
@@ -56,18 +50,7 @@ export class DileInputMoney extends DileInput {
56
50
  }
57
51
  }
58
52
 
59
- updated(changedProperties) {
60
- super.updated(changedProperties);
61
- if(changedProperties.has('value') && this.value) {
62
- this.changed = true;
63
- }
64
- }
65
-
66
53
  computeValue(value) {
67
- if(value) {
68
- value = value.toString();
69
- return value.replace('.', this.decimalSeparator);
70
- }
71
- return '';
54
+ return String(value ?? '').replace('.', this.decimalSeparator);
72
55
  }
73
56
  }
@@ -36,7 +36,6 @@ export class DileInputNumber extends DileInput {
36
36
  this.step = 'any';
37
37
  this.decimals = null;
38
38
  this.normalizeOn = 'input';
39
- this.changed = false;
40
39
  this.viewValueOnFocus = null;
41
40
  this.isInputFocused = false;
42
41
  }
@@ -46,6 +45,10 @@ export class DileInputNumber extends DileInput {
46
45
  this.syncNativeInputConstraints();
47
46
  }
48
47
 
48
+ get inputModeValue() {
49
+ return 'decimal';
50
+ }
51
+
49
52
  get safeDecimalSeparator() {
50
53
  return this.decimalSeparator === ',' ? ',' : '.';
51
54
  }
@@ -243,13 +246,8 @@ export class DileInputNumber extends DileInput {
243
246
  doBlur(e) {
244
247
  this.isInputFocused = false;
245
248
  this.viewValueOnFocus = null;
246
- const num = this.normalizeAndConstrain(e.target.value);
247
-
248
- if (num !== e.target.value || this.changed) {
249
- this.value = num;
250
- this.emmitChange();
251
- this.changed = false;
252
- }
249
+ // element-changed is dispatched by DileInput when the value changes
250
+ this.value = this.normalizeAndConstrain(e.target.value);
253
251
 
254
252
  if (this.normalizeOnBlur) {
255
253
  this.el.value = this.computeValue(this.value);
@@ -269,10 +267,6 @@ export class DileInputNumber extends DileInput {
269
267
  return;
270
268
  }
271
269
 
272
- if (changedProperties.has('value') && this.value) {
273
- this.changed = true;
274
- }
275
-
276
270
  if (changedProperties.has('min') || changedProperties.has('max') || changedProperties.has('step') || changedProperties.has('decimals')) {
277
271
  if (this.value) {
278
272
  const normalized = this.normalizeAndConstrain(this.value);
@@ -16,15 +16,15 @@ export class DileInputNumberMask extends DileInput {
16
16
  this.mask = '';
17
17
  this.maskedValue = '';
18
18
  this.content = '';
19
- this._keyDownHandler = this.handleKeyDown.bind(this);
20
19
  }
21
20
 
22
21
  firstUpdated() {
23
22
  super.firstUpdated();
24
23
  this.createMaskController(this.mask);
25
- if (this.el) {
26
- this.el.addEventListener('keydown', this._keyDownHandler);
27
- }
24
+ }
25
+
26
+ doKeydown(e) {
27
+ this.handleKeyDown(e);
28
28
  }
29
29
 
30
30
  createMaskController(mask) {
@@ -39,18 +39,11 @@ export class DileInputNumberMask extends DileInput {
39
39
  this.updateMaskedValue();
40
40
  }
41
41
  if (changedProperties.has('value')) {
42
- this.content = this.value.slice(0, this.maxChars);
42
+ this.content = String(this.value ?? '').slice(0, this.maxChars);
43
43
  this.updateMaskedValue();
44
44
  }
45
45
  }
46
46
 
47
- disconnectedCallback() {
48
- if (this.el) {
49
- this.el.removeEventListener('keydown', this._keyDownHandler);
50
- }
51
- super.disconnectedCallback();
52
- }
53
-
54
47
  updateMaskedValue() {
55
48
  this.maskedValue = this.maskController.maskIt(this.content);
56
49
  }
@@ -23,36 +23,24 @@ export class DileInputPercentage extends DileInput {
23
23
  this.decimalSeparator = '.';
24
24
  }
25
25
 
26
+ /** Normalizes the typed text on blur. The element-changed event is dispatched by DileInput when the value changes */
26
27
  doBlur(e) {
27
- let num = e.target.value;
28
- if(num.length > 0) {
29
- num = this.formatFloat(num);
30
- }
31
- if(num != e.target.value || this.changed) {
32
- this.value = num;
33
- this.emmitChange();
34
- this.changed = false;
35
- }
28
+ const typed = e.target.value;
29
+ this.value = typed.length > 0 ? this.formatFloat(typed) : typed;
36
30
  }
37
31
 
38
32
  doFormat() {
39
33
  this.value = this.formatFloat(this.value);
40
34
  }
41
35
 
36
+ /** Returns the number as a string with "." as decimal separator, or '0' when the text is not a number */
42
37
  formatFloat(num) {
43
- num = num.replace(this.decimalSeparator, '.');
44
- num = parseFloat(num);
45
- return isNaN(num) ? '0' : num;
46
- }
47
-
48
- updated(changedProperties) {
49
- super.updated(changedProperties);
50
- if(changedProperties.has('value') && this.value) {
51
- this.changed = true;
52
- }
38
+ const text = String(num ?? '').replace(this.decimalSeparator, '.');
39
+ const parsed = parseFloat(text);
40
+ return isNaN(parsed) ? '0' : String(parsed);
53
41
  }
54
42
 
55
43
  computeValue(value) {
56
- return value.toString().replace('.', this.decimalSeparator);
44
+ return String(value ?? '').replace('.', this.decimalSeparator);
57
45
  }
58
46
  }
@@ -1,4 +1,5 @@
1
1
  import { LitElement, html, css } from 'lit';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
2
3
  import '../../icon/icon.js';
3
4
  import { searchIcon, clearIcon } from '@dile/icons/index.js';
4
5
 
@@ -102,6 +103,8 @@ export class DileInputSearch extends LitElement {
102
103
  _hasErrorContent: { state: true },
103
104
  /** Accessible name of the input field, read by screen readers. Defaults to name, or to searchButtonLabel. */
104
105
  accessibleLabel: { type: String },
106
+ /** Accessible description of the input, applied as aria-description (e.g. a validation message rendered outside this component) */
107
+ accessibleDescription: { type: String },
105
108
  /** Accessible name of the button when the field is empty */
106
109
  searchButtonLabel: { type: String },
107
110
  /** Accessible name of the button that clears the field */
@@ -145,7 +148,8 @@ export class DileInputSearch extends LitElement {
145
148
  ?disabled="${this.disabled}"
146
149
  ?readonly="${this.readOnly}"
147
150
  aria-label="${this.accessibleLabel || this.name || this.searchButtonLabel}"
148
- ?aria-invalid="${this.errored}"
151
+ aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
152
+ aria-description="${ifDefined(this.accessibleDescription || undefined)}"
149
153
  aria-describedby="${this.showErrorMessage ? 'error-msg' : null}"
150
154
  >
151
155
  <button
@@ -1,5 +1,5 @@
1
1
  import { LitElement, html, css } from 'lit';
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
3
3
  import '../number-picker-element.js';
4
4
  import { labelStyles } from '../../input/src/label-styles.js';
5
5
  import { messageStyles } from '../../input/src/message-styles.js';
@@ -81,6 +81,7 @@ export class DileNumberPicker extends DileEmmitChange(LitElement) {
81
81
  @dile-number-picker-value-changed=${this.valueChanged}
82
82
  ?focusOnStart=${this.focusOnStart}
83
83
  ?errored=${this.errored}
84
+ .accessibleDescription=${this.message || undefined}
84
85
  min=${this._numericMin(this.min)}
85
86
  max=${this._numericMax(this.max)}
86
87
  ?disabled=${this.disabled}
@@ -98,7 +99,7 @@ export class DileNumberPicker extends DileEmmitChange(LitElement) {
98
99
  get messageTemplate() {
99
100
  return html`
100
101
  ${this.message
101
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
102
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
102
103
  : ''
103
104
  }
104
105
  `
@@ -1,4 +1,5 @@
1
1
  import { html, css, LitElement } from "lit";
2
+ import { ifDefined } from "lit/directives/if-defined.js";
2
3
  import { arrowDropUpLargeIcon, arrowDropDownLargeIcon } from '@dile/icons';
3
4
  import '../../icon/icon.js'
4
5
 
@@ -81,6 +82,8 @@ export class DileNumberPickerElement extends LitElement {
81
82
  }
82
83
  },
83
84
  disabled: { type: Boolean },
85
+ /** Accessible description of the input, applied as aria-description (e.g. the validation message of the parent field) */
86
+ accessibleDescription: { type: String },
84
87
  };
85
88
  }
86
89
 
@@ -118,6 +121,8 @@ export class DileNumberPickerElement extends LitElement {
118
121
  id="elinput"
119
122
  @input=${this._onInput}
120
123
  ?disabled=${this.disabled}
124
+ aria-invalid=${ifDefined(this.errored ? 'true' : undefined)}
125
+ aria-description=${ifDefined(this.accessibleDescription || undefined)}
121
126
  >
122
127
  <div class="controls">
123
128
  <dile-icon .icon=${arrowDropUpLargeIcon} @click=${this.increment}></dile-icon>
@@ -1,5 +1,6 @@
1
1
  import { LitElement, html, css } from 'lit';
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
+ import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
3
4
  import { labelStyles, messageStyles } from '../../input/index.js';
4
5
  import { sanitizeOtpValue } from '../../../lib/otp/sanitizeOtpValue.js';
5
6
 
@@ -169,6 +170,8 @@ export class DileOtpInput extends DileEmmitChange(LitElement) {
169
170
  ?readonly="${this.readonly}"
170
171
  .value="${char}"
171
172
  class="${this.errored ? 'errored' : ''}"
173
+ aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
174
+ aria-describedby="${ifDefined(this.message ? FIELD_MESSAGE_ID : undefined)}"
172
175
  @input="${(e) => this._onInput(e, index)}"
173
176
  @keydown="${(e) => this._onKeydown(e, index)}"
174
177
  @keypress="${this._lookForEnter}"
@@ -185,7 +188,7 @@ export class DileOtpInput extends DileEmmitChange(LitElement) {
185
188
  get messageTemplate() {
186
189
  return html`
187
190
  ${this.message
188
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
191
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
189
192
  : ''
190
193
  }
191
194
  `;
@@ -59,49 +59,26 @@ export class DilePassword extends DileInput {
59
59
  this.passwordVisible = false;
60
60
  }
61
61
 
62
- render() {
63
- const inputType = this.passwordVisible ? 'text' : 'password';
64
-
65
- return html`
66
- <div>
67
- ${this.label
68
- ? html`<label for="textField">${this.label}</label>`
69
- : ''
70
- }
71
- <section class="for-input">
72
- <input
73
- type="${inputType}"
74
- id="textField"
75
- name="${this.name}"
76
- placeholder="${this.placeholder}"
77
- ?disabled="${this.disabled}"
78
- @keypress="${this._lookForEnter}"
79
- @input="${this._input}"
80
- .value="${this.value}"
81
- class="${ this.errored ? 'errored' : '' }"
82
- >
83
- ${this.showPasswordToggle
84
- ? html`<button
85
- class="password-toggle-btn"
86
- type="button"
87
- @click="${this._togglePasswordVisibility}"
88
- ?disabled="${this.disabled}"
89
- aria-label="${this.passwordVisible ? 'Hide password' : 'Show password'}"
90
- >
91
- ${this.passwordVisible
92
- ? html`<dile-lucide-icon-eye></dile-lucide-icon-eye>`
93
- : html`<dile-lucide-icon-eye-off></dile-lucide-icon-eye-off>`
94
- }
95
- </button>`
96
- : ''
97
- }
98
- </section>
99
- ${this.message
100
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
101
- : ''
62
+ get inputType() {
63
+ return this.passwordVisible ? 'text' : 'password';
64
+ }
65
+
66
+ get fieldEndTemplate() {
67
+ if (!this.showPasswordToggle) {
68
+ return '';
69
+ }
70
+ return html`<button
71
+ class="password-toggle-btn"
72
+ type="button"
73
+ @click="${this._togglePasswordVisibility}"
74
+ ?disabled="${this.isDisabled}"
75
+ aria-label="${this.passwordVisible ? 'Hide password' : 'Show password'}"
76
+ >
77
+ ${this.passwordVisible
78
+ ? html`<dile-lucide-icon-eye></dile-lucide-icon-eye>`
79
+ : html`<dile-lucide-icon-eye-off></dile-lucide-icon-eye-off>`
102
80
  }
103
- </div>
104
- `;
81
+ </button>`;
105
82
  }
106
83
 
107
84
  _togglePasswordVisibility() {
@@ -1,7 +1,7 @@
1
1
  import { LitElement, html, css } from 'lit';
2
2
  import '../../input/input-search.js';
3
3
  import '../../spinner/spinner-horizontal.js';
4
- import { DileEmmitChange } from '../../../mixins/form/index.js';
4
+ import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
5
5
  import '../select.js';
6
6
  import { labelStyles } from '../../input/src/label-styles.js';
7
7
  import { messageStyles } from '../../input/src/message-styles.js';
@@ -201,6 +201,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
201
201
  id="result"
202
202
  ?errored=${this.errored}
203
203
  ?disabled=${this.disabled}
204
+ .accessibleDescription=${this.message || undefined}
204
205
  value="${this.selectedText}"
205
206
  readOnly
206
207
  @dile-input-search-cleared=${this.onClearSelected}
@@ -217,6 +218,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
217
218
  label="${this.label}"
218
219
  ?errored=${this.errored}
219
220
  ?disabled=${this.disabled}
221
+ .accessibleDescription=${this.message || undefined}
220
222
  @focus=${this.onFocus}
221
223
  @dile-input-search=${this.onTextInput}
222
224
  delay="${this.delay}"
@@ -272,7 +274,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
272
274
  name="generated-select-field"
273
275
  ?errored=${this.errored}
274
276
  >
275
- <select slot="select">
277
+ <select slot="select" aria-description=${this.message || ''}>
276
278
  <option value="">${this.selectDefaultPlaceholder}</option>
277
279
  ${this.data.map(item => html`
278
280
  <option value="${item[this.idProperty]}">${item[this.displayProperty]}</option>
@@ -285,7 +287,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
285
287
  get messageTemplate() {
286
288
  return html`
287
289
  ${this.message
288
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
290
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
289
291
  : ''
290
292
  }
291
293
  `
@@ -1,5 +1,5 @@
1
1
  import { LitElement, html, css } from 'lit';
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
3
3
  import '../../number-picker/number-picker-element.js';
4
4
  import { labelStyles } from '../../input/src/label-styles.js';
5
5
  import { messageStyles } from '../../input/src/message-styles.js';
@@ -62,6 +62,7 @@ export class DileTimePicker extends DileEmmitChange(LitElement) {
62
62
  .value=${this._hours}
63
63
  ?disabled=${this.disabled}
64
64
  ?errored=${this.errored}
65
+ .accessibleDescription=${this.message || undefined}
65
66
  ?focusOnStart=${this.focusOnStart}
66
67
  @dile-number-picker-value-changed=${this._changeHours}
67
68
  ></dile-number-picker-element>
@@ -74,6 +75,7 @@ export class DileTimePicker extends DileEmmitChange(LitElement) {
74
75
  .value=${this._minutes}
75
76
  ?disabled=${this.disabled}
76
77
  ?errored=${this.errored}
78
+ .accessibleDescription=${this.message || undefined}
77
79
  @dile-number-picker-value-changed=${this._changeMinutes}
78
80
  ></dile-number-picker-element>
79
81
  <dile-number-picker-element
@@ -85,6 +87,7 @@ export class DileTimePicker extends DileEmmitChange(LitElement) {
85
87
  .value=${this._seconds}
86
88
  ?disabled=${this.disabled}
87
89
  ?errored=${this.errored}
90
+ .accessibleDescription=${this.message || undefined}
88
91
  @dile-number-picker-value-changed=${this._changeSeconds}
89
92
  ></dile-number-picker-element>
90
93
  </section>
@@ -96,7 +99,7 @@ export class DileTimePicker extends DileEmmitChange(LitElement) {
96
99
  get messageTemplate() {
97
100
  return html`
98
101
  ${this.message
99
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
102
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
100
103
  : ''
101
104
  }
102
105
  `
@@ -1,4 +1,4 @@
1
1
  export { DileForm } from "./src/DileForm.js";
2
2
  export { DileFormChangeDetect } from "./src/DileFormChangeDetect.js";
3
3
  export { DileEmmitChange } from "./src/DileEmmitChange.js";
4
- export { DileFieldMessage } from "./src/DileFieldMessage.js";
4
+ export { DileFieldMessage, FIELD_MESSAGE_ID } from "./src/DileFieldMessage.js";
@@ -13,6 +13,9 @@ import { html } from 'lit';
13
13
  *
14
14
  */
15
15
 
16
+ /** Id of the element rendered by `messageTemplate`, to link it with aria-describedby */
17
+ export const FIELD_MESSAGE_ID = 'field-message';
18
+
16
19
  export const DileFieldMessage = (superclass) => class extends superclass {
17
20
 
18
21
  static get properties() {
@@ -28,7 +31,7 @@ export const DileFieldMessage = (superclass) => class extends superclass {
28
31
  get messageTemplate() {
29
32
  return html`
30
33
  ${this.message
31
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
34
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
32
35
  : ''
33
36
  }
34
37
  `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/ui",
3
- "version": "3.22.1",
3
+ "version": "3.23.0",
4
4
  "description": "UI Core components from dile-components.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -28,5 +28,5 @@
28
28
  "publishConfig": {
29
29
  "access": "public"
30
30
  },
31
- "gitHead": "cef9349e18ff89a24a206a541f8129fd30ccb553"
31
+ "gitHead": "828a98ebe286539d42d66f8acf6d5efcdb463136"
32
32
  }