@momentum-design/components 0.27.5 → 0.27.6

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.
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { html, nothing } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
+ import { v4 as uuidv4 } from 'uuid';
13
14
  import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
14
15
  import { NameMixin } from '../../utils/mixins/NameMixin';
15
16
  import { ValueMixin } from '../../utils/mixins/ValueMixin';
@@ -70,6 +71,7 @@ class Checkbox extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)
70
71
  this.internals = this.attachInternals();
71
72
  // Checkbox does not contain helpTextType property.
72
73
  this.helpTextType = undefined;
74
+ this.id = `mdc-input-${uuidv4()}`;
73
75
  }
74
76
  /**
75
77
  * Updates the form value to reflect the current state of the checkbox.
@@ -32,7 +32,11 @@ class FormfieldGroup extends DataAriaLabelMixin(FormfieldWrapper) {
32
32
  * This is used to set the role of the component as `radiogroup` if this is true and to 'group' if it is false.
33
33
  */
34
34
  this.isRadio = false;
35
+ /** @internal */
36
+ this.shouldRenderLabel = false;
37
+ this.id = '';
35
38
  this.helpTextType = undefined;
39
+ this.disabled = undefined;
36
40
  }
37
41
  render() {
38
42
  var _a;
@@ -40,7 +44,7 @@ class FormfieldGroup extends DataAriaLabelMixin(FormfieldWrapper) {
40
44
  <div
41
45
  part="container"
42
46
  role="${this.isRadio ? ROLE.RADIOGROUP : ROLE.GROUP}"
43
- aria-labelledby="${FORMFIELD_DEFAULTS.LABEL_ID}"
47
+ aria-labelledby="${FORMFIELD_DEFAULTS.HEADING_ID}"
44
48
  aria-describedby="${FORMFIELD_DEFAULTS.HELPER_TEXT_ID}"
45
49
  aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
46
50
  >
@@ -36,6 +36,8 @@ declare class FormfieldWrapper extends FormfieldWrapper_base {
36
36
  * The help text that is displayed below the input field.
37
37
  */
38
38
  helpText?: string;
39
+ /** @internal */
40
+ protected shouldRenderLabel: Boolean;
39
41
  /**
40
42
  * creates the label element when the label property is set.
41
43
  * id is used to link the label with the input field.
@@ -9,7 +9,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { html, nothing } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
- import { v4 as uuidv4 } from 'uuid';
13
12
  import { Component } from '../../models';
14
13
  import { DisabledMixin } from '../../utils/mixins/DisabledMixin';
15
14
  import { DEFAULTS, MDC_TEXT_OPTIONS } from './formfieldwrapper.constants';
@@ -32,11 +31,13 @@ class FormfieldWrapper extends DisabledMixin(Component) {
32
31
  * The unique id of the input field. It is used to link the input field with the label.
33
32
  * @default `mdc-input-${uuidv4()}`
34
33
  */
35
- this.id = `mdc-input-${uuidv4()}`;
34
+ this.id = '';
36
35
  /**
37
36
  * The type of help text. It can be 'default', 'error', 'warning', 'success', 'priority'.
38
37
  */
39
38
  this.helpTextType = DEFAULTS.VALIDATION;
39
+ /** @internal */
40
+ this.shouldRenderLabel = true;
40
41
  }
41
42
  /**
42
43
  * creates the label element when the label property is set.
@@ -47,18 +48,22 @@ class FormfieldWrapper extends DisabledMixin(Component) {
47
48
  if (!this.label) {
48
49
  return nothing;
49
50
  }
50
- return html `<label id="${DEFAULTS.LABEL_ID}" for="${this.id}" class="mdc-label" part="label">${this.label}</label>`;
51
+ return this.shouldRenderLabel
52
+ ? html `<label for="${this.id}" class="mdc-label" part="label">${this.label}</label>`
53
+ : html ` <mdc-text
54
+ id="${DEFAULTS.HEADING_ID}"
55
+ tagname="${MDC_TEXT_OPTIONS.TAGNAME}"
56
+ type="${MDC_TEXT_OPTIONS.HEADER_TYPE}"
57
+ part="label"
58
+ >${this.label}</mdc-text
59
+ >`;
51
60
  }
52
61
  renderRequiredLabel() {
53
62
  if (!this.requiredLabel) {
54
63
  return nothing;
55
64
  }
56
65
  return html `
57
- <mdc-text
58
- part="required-label"
59
- tagname=${MDC_TEXT_OPTIONS.TAGNAME}
60
- type=${MDC_TEXT_OPTIONS.TYPE}
61
- >
66
+ <mdc-text part="required-label" tagname=${MDC_TEXT_OPTIONS.TAGNAME} type=${MDC_TEXT_OPTIONS.TYPE}>
62
67
  (${this.requiredLabel})
63
68
  </mdc-text>
64
69
  `;
@@ -9,10 +9,11 @@ declare const VALIDATION: {
9
9
  declare const DEFAULTS: {
10
10
  readonly VALIDATION: "default";
11
11
  readonly HELPER_TEXT_ID: "helper-text-id";
12
- readonly LABEL_ID: "label-id";
12
+ readonly HEADING_ID: "heading-id";
13
13
  };
14
14
  declare const MDC_TEXT_OPTIONS: {
15
15
  TAGNAME: "span";
16
16
  TYPE: "body-midsize-regular";
17
+ HEADER_TYPE: "body-midsize-bold";
17
18
  };
18
19
  export { TAG_NAME, VALIDATION, DEFAULTS, MDC_TEXT_OPTIONS };
@@ -11,10 +11,11 @@ const VALIDATION = {
11
11
  const DEFAULTS = {
12
12
  VALIDATION: VALIDATION.DEFAULT,
13
13
  HELPER_TEXT_ID: 'helper-text-id',
14
- LABEL_ID: 'label-id',
14
+ HEADING_ID: 'heading-id',
15
15
  };
16
16
  const MDC_TEXT_OPTIONS = {
17
17
  TAGNAME: VALID_TEXT_TAGS.SPAN,
18
18
  TYPE: TYPE.BODY_MIDSIZE_REGULAR,
19
+ HEADER_TYPE: TYPE.BODY_MIDSIZE_BOLD,
19
20
  };
20
21
  export { TAG_NAME, VALIDATION, DEFAULTS, MDC_TEXT_OPTIONS };
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { html, nothing } from 'lit';
11
11
  import { property, query } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
+ import { v4 as uuidv4 } from 'uuid';
13
14
  import styles from './input.styles';
14
15
  import FormfieldWrapper from '../formfieldwrapper';
15
16
  import { NameMixin } from '../../utils/mixins/NameMixin';
@@ -108,6 +109,7 @@ class Input extends DataAriaLabelMixin(ValueMixin(NameMixin(FormfieldWrapper)))
108
109
  this.clearAriaLabel = '';
109
110
  /** @internal */
110
111
  this.internals = this.attachInternals();
112
+ this.id = `mdc-input-${uuidv4()}`;
111
113
  }
112
114
  connectedCallback() {
113
115
  super.connectedCallback();
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { html, nothing } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
+ import { v4 as uuidv4 } from 'uuid';
13
14
  import { NameMixin } from '../../utils/mixins/NameMixin';
14
15
  import { ValueMixin } from '../../utils/mixins/ValueMixin';
15
16
  import styles from './radio.styles';
@@ -67,6 +68,7 @@ class Radio extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
67
68
  this.readonly = false;
68
69
  /** @internal */
69
70
  this.internals = this.attachInternals();
71
+ this.id = `mdc-input-${uuidv4()}`;
70
72
  }
71
73
  /**
72
74
  * Updates the form value to reflect the current state of the radio.
@@ -74,9 +76,7 @@ class Radio extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
74
76
  * If unchecked, the value is set to null.
75
77
  */
76
78
  setFormValue() {
77
- if (this.checked) {
78
- this.internals.setFormValue(this.value);
79
- }
79
+ this.internals.setFormValue(this.checked ? this.value : null);
80
80
  }
81
81
  firstUpdated() {
82
82
  this.updateTabIndex();
@@ -123,6 +123,7 @@ class Radio extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
123
123
  if (inputElement) {
124
124
  inputElement.checked = true;
125
125
  }
126
+ this.updateTabIndex();
126
127
  this.dispatchChangeEvent(event);
127
128
  }
128
129
  /**
@@ -207,7 +208,7 @@ class Radio extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
207
208
  ?disabled=${this.disabled}
208
209
  class="mdc-radio__input"
209
210
  aria-checked="${this.checked}"
210
- aria-describedby="${FORMFIELD_DEFAULTS.HELPER_TEXT_ID}"
211
+ aria-describedby="${ifDefined(this.helpText ? FORMFIELD_DEFAULTS.HELPER_TEXT_ID : '')}"
211
212
  aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
212
213
  />
213
214
  <span class="mdc-radio__icon"></span>
@@ -0,0 +1,7 @@
1
+ import RadioGroup from './radiogroup.component';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ ['mdc-radiogroup']: RadioGroup;
5
+ }
6
+ }
7
+ export default RadioGroup;
@@ -0,0 +1,4 @@
1
+ import RadioGroup from './radiogroup.component';
2
+ import { TAG_NAME } from './radiogroup.constants';
3
+ RadioGroup.register(TAG_NAME);
4
+ export default RadioGroup;
@@ -0,0 +1,23 @@
1
+ import { CSSResult } from 'lit';
2
+ import FormfieldGroup from '../formfieldgroup';
3
+ declare const RadioGroup_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/NameMixin").NameMixinInterface> & typeof FormfieldGroup;
4
+ /**
5
+ * `mdc-radiogroup` - This is the wrapper component for radio buttons which are grouped together.
6
+ * It can have a header text and a description. It enables users to select a single option from a set of options.
7
+ * It is often used in forms, settings, and selection in lists. It automatically group the radio buttons inside it.
8
+ *
9
+ * @tagname mdc-radiogroup
10
+ *
11
+ * @cssproperty --mdc-radiogroup-description-text-normal - color of the description text
12
+ *
13
+ */
14
+ declare class RadioGroup extends RadioGroup_base {
15
+ constructor();
16
+ /**
17
+ * Using name property to group the radio buttons together.
18
+ * If the name is not set, it will be set to the name of the radio group.
19
+ */
20
+ firstUpdated(): void;
21
+ static styles: Array<CSSResult>;
22
+ }
23
+ export default RadioGroup;
@@ -0,0 +1,31 @@
1
+ import { NameMixin } from '../../utils/mixins/NameMixin';
2
+ import FormfieldGroup from '../formfieldgroup';
3
+ import { TAG_NAME as RADIO_TAGNAME } from '../radio/radio.constants';
4
+ /**
5
+ * `mdc-radiogroup` - This is the wrapper component for radio buttons which are grouped together.
6
+ * It can have a header text and a description. It enables users to select a single option from a set of options.
7
+ * It is often used in forms, settings, and selection in lists. It automatically group the radio buttons inside it.
8
+ *
9
+ * @tagname mdc-radiogroup
10
+ *
11
+ * @cssproperty --mdc-radiogroup-description-text-normal - color of the description text
12
+ *
13
+ */
14
+ class RadioGroup extends NameMixin(FormfieldGroup) {
15
+ constructor() {
16
+ super();
17
+ // This is used to set the role of the component as `radiogroup`.
18
+ /** @internal */
19
+ this.isRadio = true;
20
+ }
21
+ /**
22
+ * Using name property to group the radio buttons together.
23
+ * If the name is not set, it will be set to the name of the radio group.
24
+ */
25
+ firstUpdated() {
26
+ var _a, _b, _c, _d, _e;
27
+ (_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)) === null || _d === void 0 ? void 0 : _d.filter((radio) => !radio.hasAttribute('name'))) === null || _e === void 0 ? void 0 : _e.forEach((radio) => radio.setAttribute('name', this.name));
28
+ }
29
+ }
30
+ RadioGroup.styles = [...FormfieldGroup.styles];
31
+ export default RadioGroup;
@@ -0,0 +1,2 @@
1
+ declare const TAG_NAME: "mdc-radiogroup";
2
+ export { TAG_NAME };
@@ -0,0 +1,3 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('radiogroup');
3
+ export { TAG_NAME };
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  import { html } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
+ import { v4 as uuidv4 } from 'uuid';
13
14
  import styles from './toggle.styles';
14
15
  import FormfieldWrapper from '../formfieldwrapper';
15
16
  import { ValueMixin } from '../../utils/mixins/ValueMixin';
@@ -76,6 +77,7 @@ class Toggle extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)))
76
77
  this.internals = this.attachInternals();
77
78
  // Toggle does not contain helpTextType property.
78
79
  this.helpTextType = undefined;
80
+ this.id = `mdc-input-${uuidv4()}`;
79
81
  }
80
82
  /**
81
83
  * Updates the form value to reflect the current state of the toggle.