@momentum-design/components 0.76.1 → 0.76.2

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.
@@ -53,7 +53,7 @@ declare class Checkbox extends Checkbox_base implements AssociatedFormControl {
53
53
  private setFormValue;
54
54
  /**
55
55
  * Manages the required state of the checkbox.
56
- * If the checkbox is not checked and the requiredLabel property is set, then the checkbox is invalid.
56
+ * If the checkbox is not checked and the required property is set, then the checkbox is invalid.
57
57
  */
58
58
  private manageRequired;
59
59
  /** @internal
@@ -91,10 +91,10 @@ class Checkbox extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
91
91
  }
92
92
  /**
93
93
  * Manages the required state of the checkbox.
94
- * If the checkbox is not checked and the requiredLabel property is set, then the checkbox is invalid.
94
+ * If the checkbox is not checked and the required property is set, then the checkbox is invalid.
95
95
  */
96
96
  manageRequired() {
97
- if (!this.checked && this.requiredLabel) {
97
+ if (!this.checked && this.required) {
98
98
  if (this.validationMessage) {
99
99
  this.inputElement.setCustomValidity(this.validationMessage);
100
100
  }
@@ -173,7 +173,7 @@ class Checkbox extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
173
173
  ?autofocus="${this.autofocus}"
174
174
  name="${ifDefined(this.name)}"
175
175
  value="${ifDefined(this.value)}"
176
- ?required="${!!this.requiredLabel}"
176
+ ?required="${this.required}"
177
177
  .checked="${this.checked}"
178
178
  aria-checked="${this.indeterminate ? 'mixed' : this.checked}"
179
179
  .indeterminate="${this.indeterminate}"
@@ -18,11 +18,11 @@ declare class FormfieldWrapper extends FormfieldWrapper_base {
18
18
  */
19
19
  label?: string;
20
20
  /**
21
- * The required label of the input field.
22
- * When an appropriate string value is set,
23
- * the input field is marked as required and the label is appended with this text.
21
+ * The required attribute to indicate that the input field is required.
22
+ * It is used to append a required indicator (*) to the label.
23
+ * @default false
24
24
  */
25
- requiredLabel?: string;
25
+ required: boolean;
26
26
  /**
27
27
  * The unique id of the input field. It is used to link the input field with the label.
28
28
  * @default `mdc-input-${uuidv4()}`
@@ -44,7 +44,6 @@ declare class FormfieldWrapper extends FormfieldWrapper_base {
44
44
  * @returns void
45
45
  */
46
46
  protected renderLabelElement(): import("lit-html").TemplateResult<1> | typeof nothing;
47
- protected renderRequiredLabel(): import("lit-html").TemplateResult<1> | typeof nothing;
48
47
  /**
49
48
  * creates the helpertext icon based on the helpTextType for validation.
50
49
  * If the helpTextType is not set, it defaults to 'default' and it doesn't display any icon.
@@ -27,6 +27,12 @@ import { getHelperIcon } from './formfieldwrapper.utils';
27
27
  class FormfieldWrapper extends DisabledMixin(Component) {
28
28
  constructor() {
29
29
  super(...arguments);
30
+ /**
31
+ * The required attribute to indicate that the input field is required.
32
+ * It is used to append a required indicator (*) to the label.
33
+ * @default false
34
+ */
35
+ this.required = false;
30
36
  /**
31
37
  * The unique id of the input field. It is used to link the input field with the label.
32
38
  * @default `mdc-input-${uuidv4()}`
@@ -58,16 +64,6 @@ class FormfieldWrapper extends DisabledMixin(Component) {
58
64
  >${this.label}</mdc-text
59
65
  >`;
60
66
  }
61
- renderRequiredLabel() {
62
- if (!this.requiredLabel) {
63
- return nothing;
64
- }
65
- return html `
66
- <mdc-text part="required-label" tagname=${MDC_TEXT_OPTIONS.TAGNAME} type=${MDC_TEXT_OPTIONS.TYPE}>
67
- (${this.requiredLabel})
68
- </mdc-text>
69
- `;
70
- }
71
67
  /**
72
68
  * creates the helpertext icon based on the helpTextType for validation.
73
69
  * If the helpTextType is not set, it defaults to 'default' and it doesn't display any icon.
@@ -112,7 +108,7 @@ class FormfieldWrapper extends DisabledMixin(Component) {
112
108
  return nothing;
113
109
  return html `<div class="mdc-label-text" part="label-text">
114
110
  <slot name="label">${this.renderLabelElement()}</slot>
115
- <slot name="required-label">${this.renderRequiredLabel()}</slot>
111
+ ${this.required ? html `<span part="required-indicator">*</span>` : nothing}
116
112
  <slot name="label-info"></slot>
117
113
  </div>`;
118
114
  }
@@ -124,7 +120,7 @@ class FormfieldWrapper extends DisabledMixin(Component) {
124
120
  if (!this.helpText) {
125
121
  return nothing;
126
122
  }
127
- return html `<div class="mdc-help-text" part="mdc-help-text">
123
+ return html `<div class="mdc-help-text" part="help-text">
128
124
  <slot name="help-icon">${this.renderHelpTextIcon()}</slot>
129
125
  <slot name="help-text">${this.renderHelpText()}</slot>
130
126
  </div>`;
@@ -136,9 +132,9 @@ __decorate([
136
132
  __metadata("design:type", String)
137
133
  ], FormfieldWrapper.prototype, "label", void 0);
138
134
  __decorate([
139
- property({ type: String, reflect: true, attribute: 'required-label' }),
140
- __metadata("design:type", String)
141
- ], FormfieldWrapper.prototype, "requiredLabel", void 0);
135
+ property({ type: Boolean, reflect: true, attribute: 'required' }),
136
+ __metadata("design:type", Object)
137
+ ], FormfieldWrapper.prototype, "required", void 0);
142
138
  __decorate([
143
139
  property({ type: String }),
144
140
  __metadata("design:type", Object)
@@ -18,6 +18,10 @@ const styles = [
18
18
  color: var(--mds-color-theme-text-primary-disabled);
19
19
  }
20
20
 
21
+ :host::part(required-indicator) {
22
+ color: var(--mds-color-theme-text-error-normal);
23
+ }
24
+
21
25
  .mdc-label-text,
22
26
  .mdc-help-text {
23
27
  display: flex;
@@ -138,7 +138,7 @@ class Input extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
138
138
  }
139
139
  }
140
140
  setInputValidity() {
141
- if (this.requiredLabel && this.validationMessage && this.value === '') {
141
+ if (this.required && this.validationMessage && this.value === '') {
142
142
  this.inputElement.setCustomValidity(this.validationMessage);
143
143
  }
144
144
  else {
@@ -305,7 +305,7 @@ class Input extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
305
305
  .value="${this.value}"
306
306
  ?disabled="${this.disabled}"
307
307
  ?readonly="${this.readonly}"
308
- ?required="${!!this.requiredLabel}"
308
+ ?required="${this.required}"
309
309
  type="${type}"
310
310
  aria-describedby="${ifDefined(this.helpText ? FORMFIELD_DEFAULTS.HELPER_TEXT_ID : '')}"
311
311
  aria-invalid="${this.helpTextType === 'error' ? 'true' : 'false'}"
@@ -38,7 +38,7 @@ class Progressspinner extends Progressbar {
38
38
  this.disabled = undefined;
39
39
  this.helpTextType = undefined;
40
40
  this.helpText = undefined;
41
- this.requiredLabel = undefined;
41
+ this.required = undefined;
42
42
  this.variant = undefined;
43
43
  this.label = undefined;
44
44
  }
@@ -118,7 +118,7 @@ class Radio extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
118
118
  if (isValid) {
119
119
  this.internals.setValidity({});
120
120
  }
121
- else if (this.requiredLabel && !this.checked) {
121
+ else if (this.required && !this.checked) {
122
122
  if (this.validationMessage) {
123
123
  this.inputElement.setCustomValidity(this.validationMessage);
124
124
  }
@@ -163,7 +163,7 @@ class Radio extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
163
163
  this.setGroupValidity(radios, true);
164
164
  }
165
165
  else {
166
- const anyRequired = radios.some((r) => r.requiredLabel);
166
+ const anyRequired = radios.some((r) => r.required);
167
167
  const anyChecked = !!radios.find((r) => r.checked);
168
168
  const isInvalid = anyRequired && !anyChecked;
169
169
  this.setGroupValidity(radios, !isInvalid);
@@ -284,7 +284,7 @@ class Radio extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
284
284
  ?autofocus="${this.autofocus}"
285
285
  name="${ifDefined(this.name)}"
286
286
  value="${ifDefined(this.value)}"
287
- ?required="${!!this.requiredLabel}"
287
+ ?required="${this.required}"
288
288
  @change=${this.handleChange}
289
289
  @keydown=${this.handleKeyDown}
290
290
  ?checked=${this.checked}
@@ -83,7 +83,7 @@ const styles = [hostFitContentStyles, css `
83
83
  justify-content: center;
84
84
  gap: 0.25rem;
85
85
  }
86
- :host::part(required-label){
86
+ :host::part(required-indicator){
87
87
  display: none;
88
88
  }
89
89
 
@@ -42,8 +42,8 @@ class RadioGroup extends FormfieldGroup {
42
42
  var _a, _b, _c, _d, _e;
43
43
  (_e = (_d = (_c = (_b = Array.from(((_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('slot')) || [])) === null || _b === void 0 ? void 0 : _b.flatMap((slot) => slot.assignedElements({ flatten: true }))) === null || _c === void 0 ? void 0 : _c.filter((el) => el.tagName.toLowerCase() === RADIO_TAGNAME || el.tagName.toLowerCase() === CARD_RADIO_TAGNAME)) === null || _d === void 0 ? void 0 : _d.filter((radio) => !radio.hasAttribute('name'))) === null || _e === void 0 ? void 0 : _e.forEach((radio) => {
44
44
  radio.setAttribute('name', this.name);
45
- if (this.requiredLabel)
46
- radio.setAttribute('required-label', this.requiredLabel);
45
+ if (this.required)
46
+ radio.setAttribute('required', this.required.toString());
47
47
  });
48
48
  }
49
49
  }
@@ -55,7 +55,7 @@ class Searchfield extends Input {
55
55
  this.trailingButton = DEFAULTS.CLOSE_BTN;
56
56
  this.helpText = undefined;
57
57
  this.helpTextType = undefined;
58
- this.requiredLabel = undefined;
58
+ this.required = undefined;
59
59
  this.validationMessage = undefined;
60
60
  this.prefixText = undefined;
61
61
  }
@@ -92,8 +92,11 @@ declare class Select extends Select_base implements AssociatedFormControl {
92
92
  private setSelectedValue;
93
93
  /**
94
94
  * Manages the required state of the select.
95
- * If the value is not set and the requiredLabel property is set,
96
- * then the select is invalid.
95
+ * If the select is required and no value is selected,
96
+ * it sets a custom validity message based on the validationMessage property.
97
+ * If the select is not required or a value is selected, it clears the custom validity.
98
+ * This method is called to ensure that the select behaves correctly in forms.
99
+ * @internal
97
100
  */
98
101
  private manageRequired;
99
102
  /**
@@ -153,11 +153,14 @@ class Select extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
153
153
  }
154
154
  /**
155
155
  * Manages the required state of the select.
156
- * If the value is not set and the requiredLabel property is set,
157
- * then the select is invalid.
156
+ * If the select is required and no value is selected,
157
+ * it sets a custom validity message based on the validationMessage property.
158
+ * If the select is not required or a value is selected, it clears the custom validity.
159
+ * This method is called to ensure that the select behaves correctly in forms.
160
+ * @internal
158
161
  */
159
162
  manageRequired() {
160
- if (!this.selectedValue && this.requiredLabel) {
163
+ if (!this.selectedValue && this.required) {
161
164
  if (this.validationMessage) {
162
165
  this.inputElement.setCustomValidity(this.validationMessage);
163
166
  }
@@ -402,7 +405,7 @@ class Select extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
402
405
  .value="${this.selectedValue}"
403
406
  ?autofocus="${this.autofocus}"
404
407
  ?disabled="${this.disabled}"
405
- ?required="${!!this.requiredLabel}"
408
+ ?required="${this.required}"
406
409
  @mousedown="${(event) => event.preventDefault()}"
407
410
  >
408
411
  ${this.getOptionsContentFromSlot()}
@@ -7,7 +7,7 @@ declare const Textarea_base: import("../../utils/mixins/index.types").Constructo
7
7
  * mdc-textarea component, which is used to get the multi-line text input from the user.
8
8
  * It contains:
9
9
  * - label: It is the title of the textarea field.
10
- * - required-label: A string depicting that the textarea field is required.
10
+ * - required: A boolean attribute depicting that the textarea field is required.
11
11
  * - Textarea: It is the multi-line text input field.
12
12
  * - helper-text: It is the text that provides additional information about the textarea field.
13
13
  * - max-character-limit: It is the text that shows the character count of the textarea field.
@@ -21,7 +21,7 @@ import { FormInternalsMixin } from '../../utils/mixins/FormInternalsMixin';
21
21
  * mdc-textarea component, which is used to get the multi-line text input from the user.
22
22
  * It contains:
23
23
  * - label: It is the title of the textarea field.
24
- * - required-label: A string depicting that the textarea field is required.
24
+ * - required: A boolean attribute depicting that the textarea field is required.
25
25
  * - Textarea: It is the multi-line text input field.
26
26
  * - helper-text: It is the text that provides additional information about the textarea field.
27
27
  * - max-character-limit: It is the text that shows the character count of the textarea field.
@@ -127,7 +127,7 @@ class Textarea extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
127
127
  });
128
128
  }
129
129
  setTextareaValidity() {
130
- if (this.requiredLabel && this.validationMessage && this.value === '') {
130
+ if (this.required && this.validationMessage && this.value === '') {
131
131
  this.textarea.setCustomValidity(this.validationMessage);
132
132
  }
133
133
  else if (this.maxCharacterLimit
@@ -292,7 +292,7 @@ class Textarea extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper))
292
292
  .value="${this.value}"
293
293
  ?disabled="${this.disabled}"
294
294
  ?readonly="${this.readonly}"
295
- ?required="${!!this.requiredLabel}"
295
+ ?required="${this.required}"
296
296
  placeholder=${ifDefined(this.placeholder)}
297
297
  rows=${ifDefined(this.rows)}
298
298
  cols=${ifDefined(this.cols)}
@@ -64,7 +64,9 @@ declare class Toggle extends Toggle_base implements AssociatedFormControl {
64
64
  formStateRestoreCallback(state: string): void;
65
65
  /**
66
66
  * Manages the required state of the checkbox.
67
- * If the checkbox is not checked and the requiredLabel property is set, then the checkbox is invalid.
67
+ * If the checkbox is not checked and the required property is set, then the checkbox is invalid.
68
+ * If the validationMessage is set, it will be used as the custom validity message.
69
+ * If the validationMessage is not set, it will clear the custom validity message.
68
70
  */
69
71
  private manageRequired;
70
72
  /**
@@ -90,10 +90,12 @@ class Toggle extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
90
90
  }
91
91
  /**
92
92
  * Manages the required state of the checkbox.
93
- * If the checkbox is not checked and the requiredLabel property is set, then the checkbox is invalid.
93
+ * If the checkbox is not checked and the required property is set, then the checkbox is invalid.
94
+ * If the validationMessage is set, it will be used as the custom validity message.
95
+ * If the validationMessage is not set, it will clear the custom validity message.
94
96
  */
95
97
  manageRequired() {
96
- if (!this.checked && this.requiredLabel) {
98
+ if (!this.checked && this.required) {
97
99
  if (this.validationMessage) {
98
100
  this.inputElement.setCustomValidity(this.validationMessage);
99
101
  }
@@ -186,7 +188,7 @@ class Toggle extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
186
188
  part="toggle-input"
187
189
  role="switch"
188
190
  ?autofocus="${this.autofocus}"
189
- ?required="${!!this.requiredLabel}"
191
+ ?required="${this.required}"
190
192
  name="${ifDefined(this.name)}"
191
193
  value="${ifDefined(this.value)}"
192
194
  .checked="${this.checked}"