@dile/ui 3.23.0 → 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 (30) hide show
  1. package/components/checkbox/src/DileCheckbox.js +14 -5
  2. package/components/drop-file/src/DileDropFile.js +5 -3
  3. package/components/input/index.js +1 -1
  4. package/components/input/src/DileInput.js +9 -3
  5. package/components/input/src/DileInputMask.js +16 -0
  6. package/components/input/src/DileInputSearch.js +2 -0
  7. package/components/input/src/label-styles.js +15 -0
  8. package/components/input-suggestions/src/DileInputSuggestionsBase.js +6 -3
  9. package/components/number-picker/src/DileNumberPicker.js +6 -3
  10. package/components/number-picker/src/DileNumberPickerElement.js +2 -0
  11. package/components/order-switch/src/DileOrderSwitch.js +18 -2
  12. package/components/otp-input/src/DileOtpInput.js +6 -3
  13. package/components/radio-group/src/DileRadioGroup.js +6 -3
  14. package/components/rating-scale-question/src/DileRatingScaleQuestion.js +35 -3
  15. package/components/select/src/DileSelect.js +12 -4
  16. package/components/select/src/DileSelectAjax.js +8 -3
  17. package/components/select/src/DileSelectBoolean.js +9 -2
  18. package/components/select/src/DileSelectOverlay.js +6 -3
  19. package/components/select/src/DileSelectSearchableBase.js +8 -3
  20. package/components/switch/src/DileSwitch.js +3 -1
  21. package/components/textarea/src/DileTextarea.js +7 -3
  22. package/components/time-picker/src/DileTimePicker.js +680 -126
  23. package/components/wheel-picker/src/DileWheelPicker.js +17 -2
  24. package/lib/time/time.js +171 -0
  25. package/lib/time/time.test.js +63 -0
  26. package/mixins/form/index.js +2 -1
  27. package/mixins/form/src/DileForm.js +240 -1
  28. package/mixins/form/src/DileNativeValidity.js +195 -0
  29. package/mixins/overlay/src/DileOverlay.js +16 -0
  30. package/package.json +2 -2
@@ -1,15 +1,18 @@
1
1
  import { html, css, LitElement } from "lit";
2
2
  import { ifDefined } from 'lit/directives/if-defined.js';
3
- import { DileEmmitChange } from '../../../mixins/form/index.js';
3
+ import { requiredIndicatorStyles } from '../../input/src/label-styles.js';
4
+ import { DileNativeValidity, DileEmmitChange } from '../../../mixins/form/index.js';
4
5
  import { checkboxBlankIcon, checkboxCheckedIcon } from '@dile/icons';
5
6
  import '../../icon/icon.js';
6
7
  import '../../input/input-message.js';
7
8
 
8
- export class DileCheckbox extends DileEmmitChange(LitElement) {
9
+ export class DileCheckbox extends DileNativeValidity(DileEmmitChange(LitElement)) {
9
10
  static get properties() {
10
11
  return {
11
12
  checked: { type: Boolean, reflect: true, },
12
13
  disabled: { type: Boolean, reflect: true, },
14
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
15
+ required: { type: Boolean, reflect: true },
13
16
  _hasInner: { type: Boolean },
14
17
  name: { type: String, reflect: true, },
15
18
  message: { type: String },
@@ -33,7 +36,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
33
36
  }
34
37
 
35
38
  static get styles() {
36
- return css`
39
+ return [requiredIndicatorStyles, css`
37
40
  :host {
38
41
  display: inline-block;
39
42
  --dile-icon-size: var(--dile-checkbox-size, 20px);
@@ -68,7 +71,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
68
71
  .disabled .label {
69
72
  color: var(--dile-checkbox-label-disabled-color, #777);
70
73
  }
71
- `;
74
+ `];
72
75
  }
73
76
 
74
77
  firstUpdated() {
@@ -83,6 +86,11 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
83
86
  this.checked = value;
84
87
  }
85
88
 
89
+ /** Used by the required check of DileForm: as in HTML, a required checkbox must be checked */
90
+ isEmpty() {
91
+ return !this.checked;
92
+ }
93
+
86
94
  updated(changedProperties) {
87
95
  if (changedProperties.has('checked')) {
88
96
  this.emmitChange();
@@ -97,6 +105,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
97
105
  role="checkbox"
98
106
  aria-checked="${this.checked}"
99
107
  aria-disabled="${this.disabled ? "true" : "false"}"
108
+ aria-required="${ifDefined(this.required ? "true" : undefined)}"
100
109
  aria-labelledby="${ifDefined(this._hasInner ? `${this._id}-label` : undefined)}"
101
110
  aria-describedby="${ifDefined(this.message ? `${this._id}-message` : undefined)}"
102
111
  tabindex="${this.disabled ? "-1" : "0"}"
@@ -117,7 +126,7 @@ export class DileCheckbox extends DileEmmitChange(LitElement) {
117
126
  get innerTemplate() {
118
127
  return html`
119
128
  ${this._hasInner
120
- ? html` <label id="${this._id}-label" class="label">
129
+ ? html` <label id="${this._id}-label" class="label field-label">
121
130
  <slot></slot>
122
131
  </label>`
123
132
  : ""
@@ -4,9 +4,9 @@ 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, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
7
+ import { DileNativeValidity, DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
8
8
 
9
- export class DileDropFile extends DileEmmitChange(LitElement) {
9
+ export class DileDropFile extends DileNativeValidity(DileEmmitChange(LitElement)) {
10
10
  static styles = [
11
11
  labelStyles,
12
12
  messageStyles,
@@ -53,6 +53,8 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
53
53
  static get properties() {
54
54
  return {
55
55
  label: { type: String },
56
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
57
+ required: { type: Boolean, reflect: true },
56
58
  message: { type: String },
57
59
  errored: { type: Boolean },
58
60
  dropLabel: { type: String },
@@ -98,7 +100,7 @@ export class DileDropFile extends DileEmmitChange(LitElement) {
98
100
  return html`
99
101
  <main>
100
102
  ${this.label
101
- ? html`<label for="fileInput">${this.label}</label>`
103
+ ? html`<label for="fileInput" class="field-label">${this.label}</label>`
102
104
  : ""
103
105
  }
104
106
  </main>
@@ -8,7 +8,7 @@ export { DileInputNumber } from './src/DileInputNumber.js';
8
8
  export { DileInputNumberMask } from './src/DileInputNumberMask.js';
9
9
  export { DileInputPercentage } from './src/DileInputPercentage.js';
10
10
  export { DileInputSearch } from './src/DileInputSearch.js';
11
- export { labelStyles } from './src/label-styles.js';
11
+ export { labelStyles, requiredIndicatorStyles } from './src/label-styles.js';
12
12
  export { messageStyles } from './src/message-styles.js';
13
13
  export { Mask } from './src/Mask.js';
14
14
  export { MaskPattern } from './src/MaskPattern.js';
@@ -1,10 +1,10 @@
1
1
  import { LitElement, html, css } from 'lit';
2
2
  import { ifDefined } from 'lit/directives/if-defined.js';
3
- import { DileEmmitChange, DileFieldMessage, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
3
+ import { DileNativeValidity, 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
 
7
- export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
7
+ export class DileInput extends DileFieldMessage(DileNativeValidity(DileEmmitChange(LitElement))) {
8
8
 
9
9
  /**
10
10
  * Fired when user press enter key.
@@ -35,6 +35,9 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
35
35
  /** Disable the input field */
36
36
  disabled: { type: Boolean },
37
37
 
38
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
39
+ required: { type: Boolean, reflect: true },
40
+
38
41
  /** Set initial value to the input. This property syncs to the input field value property */
39
42
  value: { type: String },
40
43
 
@@ -78,6 +81,7 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
78
81
  this.labelRight = '';
79
82
  this.value = '';
80
83
  this.disabled = false;
84
+ this.required = false;
81
85
  this.disableAutocomplete = false;
82
86
  this.name = '';
83
87
  this.type = 'text';
@@ -88,6 +92,7 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
88
92
 
89
93
  /** Called by the browser when the owner form is reset: restores the value of the value attribute */
90
94
  formResetCallback() {
95
+ super.formResetCallback?.();
91
96
  this.value = this.getAttribute('value') ?? '';
92
97
  this.clearError();
93
98
  }
@@ -189,7 +194,7 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
189
194
  /** Template of the visible label. Override to customize it. */
190
195
  get labelTemplate() {
191
196
  return this.label
192
- ? html`<label for="textField">${this.label}</label>`
197
+ ? html`<label for="textField" class="field-label">${this.label}</label>`
193
198
  : '';
194
199
  }
195
200
 
@@ -207,6 +212,7 @@ export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
207
212
  inputmode="${ifDefined(this.inputModeValue)}"
208
213
  aria-label="${ifDefined(this.inputAriaLabel)}"
209
214
  aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
215
+ aria-required="${ifDefined(this.required ? 'true' : undefined)}"
210
216
  aria-describedby="${ifDefined(this.messageDescribedBy)}"
211
217
  placeholder="${this.placeholder}"
212
218
  ?disabled="${this.isDisabled}"
@@ -145,6 +145,22 @@ export class DileInputMask extends DileInput {
145
145
  }
146
146
  }
147
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
+
148
164
  getInvalidFormatMessage() {
149
165
  const messages = {
150
166
  en: `Invalid format. Expected: ${this.maskController.getFormatDescription()}`,
@@ -94,6 +94,7 @@ export class DileInputSearch extends LitElement {
94
94
  delay: { type: Number },
95
95
  placeholder: { type: String },
96
96
  value: { type: String },
97
+ required: { type: Boolean, reflect: true },
97
98
  disabled: { type: Boolean },
98
99
  readOnly: { type: Boolean },
99
100
  errored: { type: Boolean },
@@ -149,6 +150,7 @@ export class DileInputSearch extends LitElement {
149
150
  ?readonly="${this.readOnly}"
150
151
  aria-label="${this.accessibleLabel || this.name || this.searchButtonLabel}"
151
152
  aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
153
+ aria-required="${ifDefined(this.required ? 'true' : undefined)}"
152
154
  aria-description="${ifDefined(this.accessibleDescription || undefined)}"
153
155
  aria-describedby="${this.showErrorMessage ? 'error-msg' : null}"
154
156
  >
@@ -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, FIELD_MESSAGE_ID } 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,7 @@ 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}
84
87
  .accessibleDescription=${this.message || undefined}
85
88
  min=${this._numericMin(this.min)}
86
89
  max=${this._numericMax(this.max)}
@@ -81,6 +81,7 @@ export class DileNumberPickerElement extends LitElement {
81
81
  }
82
82
  }
83
83
  },
84
+ required: { type: Boolean, reflect: true },
84
85
  disabled: { type: Boolean },
85
86
  /** Accessible description of the input, applied as aria-description (e.g. the validation message of the parent field) */
86
87
  accessibleDescription: { type: String },
@@ -122,6 +123,7 @@ export class DileNumberPickerElement extends LitElement {
122
123
  @input=${this._onInput}
123
124
  ?disabled=${this.disabled}
124
125
  aria-invalid=${ifDefined(this.errored ? 'true' : undefined)}
126
+ aria-required=${ifDefined(this.required ? 'true' : undefined)}
125
127
  aria-description=${ifDefined(this.accessibleDescription || undefined)}
126
128
  >
127
129
  <div class="controls">
@@ -1,10 +1,14 @@
1
1
  import { html, css, LitElement } from "lit";
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { DileEmmitChange, DileNativeValidity } from '../../../mixins/form/index.js';
3
3
  import { switchLeftIcon } from '@dile/icons/index.js';
4
4
  import '../../button/button-icon.js'
5
5
 
6
6
 
7
- export class DileOrderSwitch extends DileEmmitChange(LitElement) {
7
+ export class DileOrderSwitch extends DileNativeValidity(DileEmmitChange(LitElement)) {
8
+ static get formAssociated() {
9
+ return true;
10
+ }
11
+
8
12
  static get properties() {
9
13
  return {
10
14
  value: { type: String },
@@ -22,6 +26,17 @@ export class DileOrderSwitch extends DileEmmitChange(LitElement) {
22
26
  super();
23
27
  this.value = "asc";
24
28
  this.selected = false;
29
+ this.internals = this.attachInternals();
30
+ }
31
+
32
+ firstUpdated() {
33
+ this._defaultValue = this.value;
34
+ }
35
+
36
+ /** Called by the browser when the owner form is reset: restores the initial value */
37
+ formResetCallback() {
38
+ super.formResetCallback?.();
39
+ this.value = this._defaultValue;
25
40
  }
26
41
 
27
42
  static get styles() {
@@ -77,6 +92,7 @@ export class DileOrderSwitch extends DileEmmitChange(LitElement) {
77
92
 
78
93
  updated(changedProperties) {
79
94
  if(changedProperties.has('value')) {
95
+ this.internals.setFormValue(this.value ?? null);
80
96
  if(this.value != "asc" && this.value != "desc") {
81
97
  this.value = "asc";
82
98
  } else if(changedProperties.get('value')) {
@@ -1,10 +1,10 @@
1
1
  import { LitElement, html, css } from 'lit';
2
2
  import { ifDefined } from 'lit/directives/if-defined.js';
3
- import { DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
3
+ import { DileNativeValidity, DileEmmitChange, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
4
4
  import { labelStyles, messageStyles } from '../../input/index.js';
5
5
  import { sanitizeOtpValue } from '../../../lib/otp/sanitizeOtpValue.js';
6
6
 
7
- export class DileOtpInput extends DileEmmitChange(LitElement) {
7
+ export class DileOtpInput extends DileNativeValidity(DileEmmitChange(LitElement)) {
8
8
 
9
9
  /**
10
10
  * Fired when user press enter key.
@@ -39,6 +39,8 @@ export class DileOtpInput extends DileEmmitChange(LitElement) {
39
39
  name: { type: String, reflect: true },
40
40
 
41
41
  /** Disable the input field */
42
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
43
+ required: { type: Boolean, reflect: true },
42
44
  disabled: { type: Boolean },
43
45
 
44
46
  /** ReadOnly attribute */
@@ -156,7 +158,7 @@ export class DileOtpInput extends DileEmmitChange(LitElement) {
156
158
  return html`
157
159
  <main>
158
160
  ${this.label
159
- ? html`<label>${this.label}</label>`
161
+ ? html`<label class="field-label">${this.label}</label>`
160
162
  : ''}
161
163
  <section class="for-input">
162
164
  ${this.boxesChars.map((char, index) => html`
@@ -171,6 +173,7 @@ export class DileOtpInput extends DileEmmitChange(LitElement) {
171
173
  .value="${char}"
172
174
  class="${this.errored ? 'errored' : ''}"
173
175
  aria-invalid="${ifDefined(this.errored ? 'true' : undefined)}"
176
+ aria-required="${ifDefined(this.required ? 'true' : undefined)}"
174
177
  aria-describedby="${ifDefined(this.message ? FIELD_MESSAGE_ID : undefined)}"
175
178
  @input="${(e) => this._onInput(e, index)}"
176
179
  @keydown="${(e) => this._onKeydown(e, index)}"
@@ -1,13 +1,13 @@
1
1
  import { LitElement, html, css } 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 '../radio.js';
5
5
  import '../../input/input-message.js';
6
6
  import { labelStyles } from '../../input/index.js';
7
7
 
8
8
  const NAVIGATION_KEYS = ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft', 'Home', 'End'];
9
9
 
10
- export class DileRadioGroup extends DileEmmitChange(LitElement) {
10
+ export class DileRadioGroup extends DileNativeValidity(DileEmmitChange(LitElement)) {
11
11
  static styles = [
12
12
  labelStyles,
13
13
  css`
@@ -33,6 +33,8 @@ export class DileRadioGroup extends DileEmmitChange(LitElement) {
33
33
  message: { type: String },
34
34
  errored: { type: Boolean },
35
35
  hideErrorOnInput: { type: Boolean },
36
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
37
+ required: { type: Boolean, reflect: true },
36
38
  disabled: {
37
39
  type: Boolean,
38
40
  reflect: true
@@ -79,12 +81,13 @@ export class DileRadioGroup extends DileEmmitChange(LitElement) {
79
81
  aria-labelledby="${ifDefined(this.label ? `${this._id}-label` : undefined)}"
80
82
  aria-describedby="${ifDefined(this.message ? `${this._id}-message` : undefined)}"
81
83
  aria-invalid="${this.errored ? 'true' : 'false'}"
84
+ aria-required="${ifDefined(this.required ? 'true' : undefined)}"
82
85
  aria-disabled="${this.disabled ? 'true' : 'false'}"
83
86
  @dile-radio-selected=${this.changeValue}
84
87
  @keydown=${this.handleKeydown}
85
88
  >
86
89
  ${this.label
87
- ? html`<span class="label" id="${this._id}-label">${this.label}</span>`
90
+ ? html`<span class="label field-label" id="${this._id}-label">${this.label}</span>`
88
91
  : ""
89
92
  }
90
93
  <slot></slot>
@@ -1,8 +1,16 @@
1
1
  import { LitElement, html, css } from 'lit';
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { DileEmmitChange, DileFieldMessage, DileNativeValidity } from '../../../mixins/form/index.js';
3
+ import { messageStyles } from '../../input/src/message-styles.js';
4
+ import { requiredIndicatorStyles } from '../../input/src/label-styles.js';
5
+
6
+ export class DileRatingScaleQuestion extends DileFieldMessage(DileNativeValidity(DileEmmitChange(LitElement))) {
7
+ static get formAssociated() {
8
+ return true;
9
+ }
3
10
 
4
- export class DileRatingScaleQuestion extends DileEmmitChange(LitElement) {
5
11
  static styles = [
12
+ messageStyles,
13
+ requiredIndicatorStyles,
6
14
  css`
7
15
  :host {
8
16
  display: block;
@@ -130,6 +138,10 @@ export class DileRatingScaleQuestion extends DileEmmitChange(LitElement) {
130
138
  type: Boolean,
131
139
  reflect: true
132
140
  },
141
+ /** Marks the field as required: shows the required indicator in the label. In a form, an answer is needed */
142
+ required: { type: Boolean, reflect: true },
143
+ /** Clears the error message when the user selects an option */
144
+ hideErrorOnInput: { type: Boolean },
133
145
  };
134
146
  }
135
147
 
@@ -141,9 +153,13 @@ export class DileRatingScaleQuestion extends DileEmmitChange(LitElement) {
141
153
  this.scale_neutral_label = "Neutral";
142
154
  this.scale_right_label="Disagree";
143
155
  this.scale_point=7; //7, 5, 3
156
+ this.internals = this.attachInternals();
144
157
  }
145
158
 
146
159
  updated(changedProperties) {
160
+ if (changedProperties.has('value')) {
161
+ this.internals.setFormValue(this.value === undefined || this.value === null ? null : String(this.value));
162
+ }
147
163
  if(changedProperties.has('value') && this.init) {
148
164
  this.doSelection(this.value);
149
165
  this.emmitChange();
@@ -152,6 +168,7 @@ export class DileRatingScaleQuestion extends DileEmmitChange(LitElement) {
152
168
  }
153
169
 
154
170
  firstUpdated() {
171
+ this._defaultValue = this.value;
155
172
  this.init = true;
156
173
  if(this.value !== undefined) {
157
174
  setTimeout(() => {
@@ -163,7 +180,7 @@ export class DileRatingScaleQuestion extends DileEmmitChange(LitElement) {
163
180
  render() {
164
181
  this.getOptions();
165
182
  return html`<fieldset @dile-rating-scale-option-selected=${this.changeValue}>
166
- <legend><span>${this.label}</span></legend>
183
+ <legend><span class="field-label">${this.label}</span></legend>
167
184
  <div class="group_options">
168
185
  <div class="caption-desktop text-leftColor">${this.scale_left_label}</div>
169
186
  <div class="radios">
@@ -178,6 +195,7 @@ export class DileRatingScaleQuestion extends DileEmmitChange(LitElement) {
178
195
  </div>
179
196
  </div>
180
197
  </fieldset>
198
+ ${this.messageTemplate}
181
199
  `;
182
200
  }
183
201
 
@@ -226,9 +244,23 @@ export class DileRatingScaleQuestion extends DileEmmitChange(LitElement) {
226
244
  changeValue(e) {
227
245
  if(!this.disabled) {
228
246
  this.value = e.detail.value;
247
+ if (this.hideErrorOnInput && this.errored) {
248
+ this.clearError();
249
+ }
229
250
  }
230
251
  }
231
252
 
253
+ /** Inner control the browser points to when it reports a validation error */
254
+ get el() {
255
+ return this.shadowRoot?.querySelector('dile-rating-scale-option')?.shadowRoot?.querySelector('input') ?? null;
256
+ }
257
+
258
+ /** Called by the browser when the owner form is reset: restores the initial value */
259
+ formResetCallback() {
260
+ super.formResetCallback?.();
261
+ this.value = this._defaultValue;
262
+ }
263
+
232
264
  doSelection(newValue) {
233
265
  this.shadowRoot.querySelectorAll('dile-rating-scale-option').forEach(option => {
234
266
  if (option.value === newValue) {
@@ -1,8 +1,8 @@
1
1
  import { html, css, LitElement } from "lit";
2
- import { DileEmmitChange } from '../../../mixins/form/index.js';
2
+ import { DileNativeValidity, DileEmmitChange } from '../../../mixins/form/index.js';
3
3
  import { labelStyles, messageStyles } from '../../input/index.js';
4
4
 
5
- export class DileSelect extends DileEmmitChange(LitElement) {
5
+ export class DileSelect extends DileNativeValidity(DileEmmitChange(LitElement)) {
6
6
  static get styles() {
7
7
  return [
8
8
  labelStyles,
@@ -101,6 +101,8 @@ export class DileSelect extends DileEmmitChange(LitElement) {
101
101
  accessibleLabel: { type: String },
102
102
  value: { type: String },
103
103
  name: { type: String, reflect: true },
104
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
105
+ required: { type: Boolean, reflect: true },
104
106
  disabled: { type: Boolean },
105
107
  errored: { type: Boolean },
106
108
  message: { type: String },
@@ -116,7 +118,7 @@ export class DileSelect extends DileEmmitChange(LitElement) {
116
118
  return html`
117
119
  <div>
118
120
  ${this.label
119
- ? html`<label for="${this.selectId}" @click="${this._focusSelect}">${this.label}</label>`
121
+ ? html`<label for="${this.selectId}" class="field-label" @click="${this._focusSelect}">${this.label}</label>`
120
122
  : ""
121
123
  }
122
124
  <div class="select-wrapper">
@@ -202,7 +204,7 @@ export class DileSelect extends DileEmmitChange(LitElement) {
202
204
  this.elselect.classList.toggle("disabled", this.disabled);
203
205
  this.elselect.setAttribute("aria-disabled", this.disabled);
204
206
  }
205
- if(changedProperties.has("errored") || changedProperties.has("message")
207
+ if(changedProperties.has("errored") || changedProperties.has("message") || changedProperties.has("required")
206
208
  || changedProperties.has("label") || changedProperties.has("accessibleLabel")) {
207
209
  this.updateSelectA11y();
208
210
  }
@@ -213,6 +215,12 @@ export class DileSelect extends DileEmmitChange(LitElement) {
213
215
 
214
216
  // Set aria-invalid when errored
215
217
  this.elselect.setAttribute("aria-invalid", this.errored);
218
+
219
+ if (this.required) {
220
+ this.elselect.setAttribute("aria-required", "true");
221
+ } else {
222
+ this.elselect.removeAttribute("aria-required");
223
+ }
216
224
 
217
225
  // The message lives in the shadow DOM and the select in the light DOM, so an
218
226
  // aria-describedby id reference cannot cross the boundary: use aria-description.
@@ -1,13 +1,13 @@
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, FIELD_MESSAGE_ID } from '../../../mixins/form/index.js';
4
+ import { DileNativeValidity, 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';
8
8
 
9
9
 
10
- export class DileSelectAjax extends DileEmmitChange(LitElement) {
10
+ export class DileSelectAjax extends DileNativeValidity(DileEmmitChange(LitElement)) {
11
11
 
12
12
  static get styles() {
13
13
  return [
@@ -68,6 +68,8 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
68
68
  label: { type: String },
69
69
  value: { type: String },
70
70
  name: { type: String, reflect: true },
71
+ /** Marks the field as required: shows the required indicator in the label and sets aria-required */
72
+ required: { type: Boolean, reflect: true },
71
73
  disabled: { type: Boolean },
72
74
  errored: { type: Boolean },
73
75
  data: { type: Array },
@@ -184,7 +186,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
184
186
  return html`
185
187
  <div>
186
188
  ${this.label
187
- ? html`<label for="textField">${this.label}</label>`
189
+ ? html`<label for="textField" class="field-label">${this.label}</label>`
188
190
  : ""}
189
191
  ${this.isSelected
190
192
  ? this.selectedTemplate
@@ -200,6 +202,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
200
202
  <dile-input-search
201
203
  id="result"
202
204
  ?errored=${this.errored}
205
+ ?required=${this.required}
203
206
  ?disabled=${this.disabled}
204
207
  .accessibleDescription=${this.message || undefined}
205
208
  value="${this.selectedText}"
@@ -217,6 +220,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
217
220
  placeholder="${this.placeholder}"
218
221
  label="${this.label}"
219
222
  ?errored=${this.errored}
223
+ ?required=${this.required}
220
224
  ?disabled=${this.disabled}
221
225
  .accessibleDescription=${this.message || undefined}
222
226
  @focus=${this.onFocus}
@@ -273,6 +277,7 @@ export class DileSelectAjax extends DileEmmitChange(LitElement) {
273
277
  @element-changed=${this.doSelected}
274
278
  name="generated-select-field"
275
279
  ?errored=${this.errored}
280
+ ?required=${this.required}
276
281
  >
277
282
  <select slot="select" aria-description=${this.message || ''}>
278
283
  <option value="">${this.selectDefaultPlaceholder}</option>