@dile/ui 3.22.1 → 3.24.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.
Files changed (44) hide show
  1. package/components/button/src/DileButton.js +3 -0
  2. package/components/checkbox/src/DileCheckbox.js +14 -5
  3. package/components/color-picker/src/DileColorPicker.js +6 -2
  4. package/components/drop-file/src/DileDropFile.js +7 -5
  5. package/components/form-group/form-group.js +5 -0
  6. package/components/form-group/index.js +1 -0
  7. package/components/form-group/src/DileFormGroup.js +188 -0
  8. package/components/input/index.js +1 -1
  9. package/components/input/src/DileInput.js +128 -31
  10. package/components/input/src/DileInputContact.js +38 -40
  11. package/components/input/src/DileInputIcon.js +7 -43
  12. package/components/input/src/DileInputInteger.js +8 -22
  13. package/components/input/src/DileInputMask.js +25 -15
  14. package/components/input/src/DileInputMoney.js +6 -23
  15. package/components/input/src/DileInputNumber.js +6 -12
  16. package/components/input/src/DileInputNumberMask.js +5 -12
  17. package/components/input/src/DileInputPercentage.js +8 -20
  18. package/components/input/src/DileInputSearch.js +7 -1
  19. package/components/input/src/label-styles.js +15 -0
  20. package/components/input-suggestions/src/DileInputSuggestionsBase.js +6 -3
  21. package/components/number-picker/src/DileNumberPicker.js +8 -4
  22. package/components/number-picker/src/DileNumberPickerElement.js +7 -0
  23. package/components/order-switch/src/DileOrderSwitch.js +18 -2
  24. package/components/otp-input/src/DileOtpInput.js +10 -4
  25. package/components/password/src/DilePassword.js +19 -42
  26. package/components/radio-group/src/DileRadioGroup.js +6 -3
  27. package/components/rating-scale-question/src/DileRatingScaleQuestion.js +35 -3
  28. package/components/select/src/DileSelect.js +12 -4
  29. package/components/select/src/DileSelectAjax.js +12 -5
  30. package/components/select/src/DileSelectBoolean.js +9 -2
  31. package/components/select/src/DileSelectOverlay.js +6 -3
  32. package/components/select/src/DileSelectSearchableBase.js +8 -3
  33. package/components/switch/src/DileSwitch.js +3 -1
  34. package/components/textarea/src/DileTextarea.js +7 -3
  35. package/components/time-picker/src/DileTimePicker.js +680 -123
  36. package/components/wheel-picker/src/DileWheelPicker.js +17 -2
  37. package/lib/time/time.js +171 -0
  38. package/lib/time/time.test.js +63 -0
  39. package/mixins/form/index.js +3 -2
  40. package/mixins/form/src/DileFieldMessage.js +4 -1
  41. package/mixins/form/src/DileForm.js +240 -1
  42. package/mixins/form/src/DileNativeValidity.js +195 -0
  43. package/mixins/overlay/src/DileOverlay.js +16 -0
  44. package/package.json +2 -2
@@ -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
  }
@@ -151,6 +145,22 @@ export class DileInputMask extends DileInput {
151
145
  }
152
146
  }
153
147
 
148
+ /**
149
+ * Error of the current value, without changing the component state (used by DileForm).
150
+ * A value that breaks the mask or is incomplete is not valid. An empty value is valid.
151
+ * @returns {string} the error message, or '' when the value is valid
152
+ */
153
+ getValidationError() {
154
+ if (!this.maskController || !this.content) {
155
+ return '';
156
+ }
157
+ const validation = this.maskController.validate(this.content);
158
+ if (!validation.valid) {
159
+ return validation.error || this.getInvalidFormatMessage();
160
+ }
161
+ return this.maskController.isComplete(this.content) ? '' : this.getInvalidFormatMessage();
162
+ }
163
+
154
164
  getInvalidFormatMessage() {
155
165
  const messages = {
156
166
  en: `Invalid format. Expected: ${this.maskController.getFormatDescription()}`,
@@ -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
 
@@ -93,6 +94,7 @@ export class DileInputSearch extends LitElement {
93
94
  delay: { type: Number },
94
95
  placeholder: { type: String },
95
96
  value: { type: String },
97
+ required: { type: Boolean, reflect: true },
96
98
  disabled: { type: Boolean },
97
99
  readOnly: { type: Boolean },
98
100
  errored: { type: Boolean },
@@ -102,6 +104,8 @@ export class DileInputSearch extends LitElement {
102
104
  _hasErrorContent: { state: true },
103
105
  /** Accessible name of the input field, read by screen readers. Defaults to name, or to searchButtonLabel. */
104
106
  accessibleLabel: { type: String },
107
+ /** Accessible description of the input, applied as aria-description (e.g. a validation message rendered outside this component) */
108
+ accessibleDescription: { type: String },
105
109
  /** Accessible name of the button when the field is empty */
106
110
  searchButtonLabel: { type: String },
107
111
  /** Accessible name of the button that clears the field */
@@ -145,7 +149,9 @@ export class DileInputSearch extends LitElement {
145
149
  ?disabled="${this.disabled}"
146
150
  ?readonly="${this.readOnly}"
147
151
  aria-label="${this.accessibleLabel || this.name || this.searchButtonLabel}"
148
- ?aria-invalid="${this.errored}"
152
+ aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
153
+ aria-required="${ifDefined(this.required ? 'true' : undefined)}"
154
+ aria-description="${ifDefined(this.accessibleDescription || undefined)}"
149
155
  aria-describedby="${this.showErrorMessage ? 'error-msg' : null}"
150
156
  >
151
157
  <button
@@ -1,5 +1,19 @@
1
1
  import { css } from 'lit';
2
2
 
3
+ /**
4
+ * Required indicator, added after the main label of a field (the element with the
5
+ * `field-label` class) when the host has the `required` attribute.
6
+ * It is decorative: the inner control carries `aria-required="true"`.
7
+ */
8
+ export const requiredIndicatorStyles = css`
9
+ :host([required]) .field-label::after {
10
+ content: var(--dile-required-indicator, "*");
11
+ margin-left: var(--dile-required-indicator-margin, 0.2em);
12
+ color: var(--dile-required-indicator-color, inherit);
13
+ font-weight: var(--dile-required-indicator-font-weight, inherit);
14
+ }
15
+ `;
16
+
3
17
  export const labelStyles = css`
4
18
  label, .label {
5
19
  display: block;
@@ -8,4 +22,5 @@ export const labelStyles = css`
8
22
  color: var(--dile-input-label-color, var(--dile-on-background-color, #59e));
9
23
  font-weight: var(--dile-input-label-font-weight, normal);
10
24
  }
25
+ ${requiredIndicatorStyles}
11
26
  `;
@@ -1,6 +1,6 @@
1
1
  import { LitElement, html, css, nothing } from 'lit';
2
2
  import { ifDefined } from 'lit/directives/if-defined.js';
3
- import { DileEmmitChange } from '../../../mixins/form/index.js';
3
+ import { DileNativeValidity, DileEmmitChange } from '../../../mixins/form/index.js';
4
4
  import { labelStyles, messageStyles } from '../../input/index.js';
5
5
  import '../../select/select-overlay.js';
6
6
  import '../../spinner/spinner-icon.js';
@@ -59,7 +59,7 @@ const OPTION_PARTS = ['option', 'option-highlighted', 'option-selected', 'option
59
59
  * - `element-changed`: when the text changes (`detail: { name, value }`).
60
60
  * - `dile-input-suggestions-selected`: when a suggestion is chosen (`detail: { name, item }`).
61
61
  */
62
- export class DileInputSuggestionsBase extends DileEmmitChange(LitElement) {
62
+ export class DileInputSuggestionsBase extends DileNativeValidity(DileEmmitChange(LitElement)) {
63
63
  static get styles() {
64
64
  return [
65
65
  labelStyles,
@@ -148,6 +148,8 @@ export class DileInputSuggestionsBase extends DileEmmitChange(LitElement) {
148
148
  /** Accessible name when there is no visible `label`. */
149
149
  accessibleLabel: { type: String },
150
150
  placeholder: { type: String },
151
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
152
+ required: { type: Boolean, reflect: true },
151
153
  disabled: { type: Boolean },
152
154
  errored: { type: Boolean },
153
155
  message: { type: String },
@@ -257,7 +259,7 @@ export class DileInputSuggestionsBase extends DileEmmitChange(LitElement) {
257
259
  const messageId = this.message ? `${this.inputId}-message` : undefined;
258
260
  return html`
259
261
  <div>
260
- ${this.label ? html`<label for="input">${this.label}</label>` : nothing} ${this.renderBeforeField()}
262
+ ${this.label ? html`<label for="input" class="field-label">${this.label}</label>` : nothing} ${this.renderBeforeField()}
261
263
  <div
262
264
  class="wrapper ${this.errored ? 'errored' : ''} ${this.disabled ? 'disabled' : ''}"
263
265
  @click=${(e) => e.stopPropagation()}
@@ -272,6 +274,7 @@ export class DileInputSuggestionsBase extends DileEmmitChange(LitElement) {
272
274
  aria-expanded="${this.opened}"
273
275
  aria-label="${ifDefined(this.label ? undefined : this.accessibleLabel || this.placeholder || undefined)}"
274
276
  aria-invalid="${this.errored}"
277
+ aria-required="${ifDefined(this.required ? 'true' : undefined)}"
275
278
  aria-describedby="${ifDefined(messageId)}"
276
279
  placeholder="${this.placeholder}"
277
280
  .value="${this.value ?? ''}"
@@ -1,10 +1,10 @@
1
1
  import { LitElement, html, css } from 'lit';
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { DileNativeValidity, 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';
6
6
 
7
- export class DileNumberPicker extends DileEmmitChange(LitElement) {
7
+ export class DileNumberPicker extends DileNativeValidity(DileEmmitChange(LitElement)) {
8
8
  static styles = [
9
9
  labelStyles,
10
10
  messageStyles,
@@ -34,6 +34,8 @@ export class DileNumberPicker extends DileEmmitChange(LitElement) {
34
34
  label: { type: String },
35
35
 
36
36
  /** Disable the input field */
37
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
38
+ required: { type: Boolean, reflect: true },
37
39
  disabled: { type: Boolean },
38
40
 
39
41
  /** Name for this input field */
@@ -70,7 +72,7 @@ export class DileNumberPicker extends DileEmmitChange(LitElement) {
70
72
 
71
73
  <main>
72
74
  ${this.label
73
- ? html`<label for="textField">${this.label}</label>`
75
+ ? html`<label for="textField" class="field-label">${this.label}</label>`
74
76
  : ""}
75
77
  <section class="for-input">
76
78
  <dile-number-picker-element
@@ -81,6 +83,8 @@ export class DileNumberPicker extends DileEmmitChange(LitElement) {
81
83
  @dile-number-picker-value-changed=${this.valueChanged}
82
84
  ?focusOnStart=${this.focusOnStart}
83
85
  ?errored=${this.errored}
86
+ ?required=${this.required}
87
+ .accessibleDescription=${this.message || undefined}
84
88
  min=${this._numericMin(this.min)}
85
89
  max=${this._numericMax(this.max)}
86
90
  ?disabled=${this.disabled}
@@ -98,7 +102,7 @@ export class DileNumberPicker extends DileEmmitChange(LitElement) {
98
102
  get messageTemplate() {
99
103
  return html`
100
104
  ${this.message
101
- ? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
105
+ ? html`<div id="${FIELD_MESSAGE_ID}" class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
102
106
  : ''
103
107
  }
104
108
  `