@momentum-design/components 0.22.5 → 0.22.7

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.
@@ -45,6 +45,8 @@ declare class Checkbox extends Checkbox_base {
45
45
  /** @internal */
46
46
  static formAssociated: boolean;
47
47
  /** @internal */
48
+ static shadowRootOptions: ShadowRootInit;
49
+ /** @internal */
48
50
  get form(): HTMLFormElement | null;
49
51
  constructor();
50
52
  /**
@@ -61,9 +63,15 @@ declare class Checkbox extends Checkbox_base {
61
63
  private toggleState;
62
64
  /**
63
65
  * Toggles the state of the checkbox element.
64
- * and dispatch the new event.
66
+ * and dispatch the new change event.
65
67
  */
66
68
  handleChange(event: Event): void;
69
+ /**
70
+ * Handles the keydown event on the checkbox.
71
+ * When the user presses Enter, the form is submitted.
72
+ * @param event - The keyboard event.
73
+ */
74
+ private handleKeyDown;
67
75
  update(changedProperties: PropertyValues): void;
68
76
  render(): import("lit-html").TemplateResult<1>;
69
77
  static styles: Array<CSSResult>;
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { html, nothing } from 'lit';
10
+ import { html, LitElement, nothing } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
12
  import { ifDefined } from 'lit/directives/if-defined.js';
13
13
  import { DataAriaLabelMixin } from '../../utils/mixins/DataAriaLabelMixin';
@@ -90,11 +90,23 @@ class Checkbox extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)
90
90
  }
91
91
  /**
92
92
  * Toggles the state of the checkbox element.
93
- * and dispatch the new event.
93
+ * and dispatch the new change event.
94
94
  */
95
95
  handleChange(event) {
96
96
  this.toggleState();
97
- this.dispatchEvent(new Event(event.type, event));
97
+ const EventConstructor = event.constructor;
98
+ this.dispatchEvent(new EventConstructor(event.type, event));
99
+ }
100
+ /**
101
+ * Handles the keydown event on the checkbox.
102
+ * When the user presses Enter, the form is submitted.
103
+ * @param event - The keyboard event.
104
+ */
105
+ handleKeyDown(event) {
106
+ var _a;
107
+ if (event.key === 'Enter') {
108
+ (_a = this.form) === null || _a === void 0 ? void 0 : _a.requestSubmit();
109
+ }
98
110
  }
99
111
  update(changedProperties) {
100
112
  super.update(changedProperties);
@@ -126,6 +138,7 @@ class Checkbox extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)
126
138
  .disabled="${this.disabled}"
127
139
  aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
128
140
  @change=${this.handleChange}
141
+ @keydown=${this.handleKeyDown}
129
142
  />
130
143
  <div class="icon-container">${checkboxIconContent}</div>
131
144
  </div>
@@ -138,6 +151,11 @@ class Checkbox extends NameMixin(ValueMixin(DataAriaLabelMixin(FormfieldWrapper)
138
151
  }
139
152
  /** @internal */
140
153
  Checkbox.formAssociated = true;
154
+ /** @internal */
155
+ Checkbox.shadowRootOptions = {
156
+ ...LitElement.shadowRootOptions,
157
+ delegatesFocus: true,
158
+ };
141
159
  Checkbox.styles = [...FormfieldWrapper.styles, ...styles];
142
160
  __decorate([
143
161
  property({ type: Boolean, reflect: true }),
@@ -0,0 +1,43 @@
1
+ import { CSSResult } from 'lit';
2
+ import { Component } from '../../models';
3
+ /**
4
+ * `mdc-checkboxgroup` component allows you to select multiple options from a predefined list.
5
+ * It is commonly used in forms where multiple selections are required, such as preferences, filters, or categories.
6
+ *
7
+ * A checkbox group typically consists of multiple checkboxes grouped together,
8
+ * each representing a selectable option. You can check or uncheck options based on their preferences.
9
+ *
10
+ * @dependency mdc-text
11
+ *
12
+ * @tagname mdc-checkboxgroup
13
+ *
14
+ * @slot help-text - This is a help text slot.
15
+ * @slot default - This is a default slot for children.
16
+ */
17
+ declare class Checkboxgroup extends Component {
18
+ /**
19
+ * The header text of the checkboxgroup.
20
+ */
21
+ headerText?: string;
22
+ /** @internal */
23
+ role: string;
24
+ /** @internal */
25
+ private get checkboxList();
26
+ constructor();
27
+ /**
28
+ * Handles the keydown event on the parent checkbox in the checkboxgroup.
29
+ * When the user presses the down arrow key, the focus is moved to the next checkbox in the checkboxgroup.
30
+ * When the user presses the up arrow key, the focus is moved to the previous checkbox in the checkboxgroup.
31
+ * @param event - The KeyboardEvent
32
+ */
33
+ private handleKeyDown;
34
+ /**
35
+ * Navigate to the next or previous checkbox in the checkboxgroup based on the given origin and direction.
36
+ * @param origin - The element that triggered the event.
37
+ * @param direction - The direction of navigation, either -1 or 1.
38
+ */
39
+ private navigate;
40
+ render(): import("lit-html").TemplateResult<1>;
41
+ static styles: Array<CSSResult>;
42
+ }
43
+ export default Checkboxgroup;
@@ -0,0 +1,94 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { html, nothing } from 'lit';
11
+ import { property } from 'lit/decorators.js';
12
+ import { Component } from '../../models';
13
+ import { TAG_NAME as CHECKBOX_TAGNAME } from '../checkbox/checkbox.constants';
14
+ import { TYPE as TEXT_TYPE, VALID_TEXT_TAGS as TEXT_TAGS } from '../text/text.constants';
15
+ import styles from './checkboxgroup.styles';
16
+ /**
17
+ * `mdc-checkboxgroup` component allows you to select multiple options from a predefined list.
18
+ * It is commonly used in forms where multiple selections are required, such as preferences, filters, or categories.
19
+ *
20
+ * A checkbox group typically consists of multiple checkboxes grouped together,
21
+ * each representing a selectable option. You can check or uncheck options based on their preferences.
22
+ *
23
+ * @dependency mdc-text
24
+ *
25
+ * @tagname mdc-checkboxgroup
26
+ *
27
+ * @slot help-text - This is a help text slot.
28
+ * @slot default - This is a default slot for children.
29
+ */
30
+ class Checkboxgroup extends Component {
31
+ /** @internal */
32
+ get checkboxList() {
33
+ var _a, _b, _c;
34
+ const allSlots = Array.from((_b = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('slot')) !== null && _b !== void 0 ? _b : []);
35
+ const assignedElements = ((_c = allSlots === null || allSlots === void 0 ? void 0 : allSlots.filter((eachSlot) => eachSlot.name !== 'help-text')[0]) === null || _c === void 0 ? void 0 : _c.assignedElements()) || [];
36
+ return assignedElements.filter((element) => element.tagName.toLowerCase() === CHECKBOX_TAGNAME);
37
+ }
38
+ constructor() {
39
+ super();
40
+ /** @internal */
41
+ this.role = 'group';
42
+ this.addEventListener('keydown', this.handleKeyDown);
43
+ }
44
+ /**
45
+ * Handles the keydown event on the parent checkbox in the checkboxgroup.
46
+ * When the user presses the down arrow key, the focus is moved to the next checkbox in the checkboxgroup.
47
+ * When the user presses the up arrow key, the focus is moved to the previous checkbox in the checkboxgroup.
48
+ * @param event - The KeyboardEvent
49
+ */
50
+ handleKeyDown(event) {
51
+ if (event.key === 'ArrowDown') {
52
+ this.navigate(event.target, 1);
53
+ }
54
+ if (event.key === 'ArrowUp') {
55
+ this.navigate(event.target, -1);
56
+ }
57
+ }
58
+ /**
59
+ * Navigate to the next or previous checkbox in the checkboxgroup based on the given origin and direction.
60
+ * @param origin - The element that triggered the event.
61
+ * @param direction - The direction of navigation, either -1 or 1.
62
+ */
63
+ navigate(origin, direction) {
64
+ const getAllCheckboxIds = this.checkboxList.map((checkbox) => checkbox.id);
65
+ const currentIdIndex = getAllCheckboxIds.indexOf(origin.id);
66
+ // Negative modulo doesn't work directly with JS.
67
+ // https://stackoverflow.com/a/71167019/4745480
68
+ const futureIndex = (((currentIdIndex + direction) % getAllCheckboxIds.length)
69
+ + getAllCheckboxIds.length) % getAllCheckboxIds.length;
70
+ this.children[futureIndex].focus();
71
+ }
72
+ render() {
73
+ const header = this.headerText
74
+ ? html `<mdc-text class="header-text" tagname="${TEXT_TAGS.SPAN}" type="${TEXT_TYPE.BODY_LARGE_BOLD}">
75
+ ${this.headerText}
76
+ </mdc-text>`
77
+ : nothing;
78
+ return html `
79
+ ${header}
80
+ <slot name="help-text"></slot>
81
+ <slot></slot>
82
+ `;
83
+ }
84
+ }
85
+ Checkboxgroup.styles = [...Component.styles, ...styles];
86
+ __decorate([
87
+ property({ type: String, attribute: 'header-text' }),
88
+ __metadata("design:type", String)
89
+ ], Checkboxgroup.prototype, "headerText", void 0);
90
+ __decorate([
91
+ property({ type: String, reflect: true }),
92
+ __metadata("design:type", Object)
93
+ ], Checkboxgroup.prototype, "role", void 0);
94
+ export default Checkboxgroup;
@@ -0,0 +1,2 @@
1
+ declare const TAG_NAME: "mdc-checkboxgroup";
2
+ export { TAG_NAME };
@@ -0,0 +1,3 @@
1
+ import utils from '../../utils/tag-name';
2
+ const TAG_NAME = utils.constructTagName('checkboxgroup');
3
+ export { TAG_NAME };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("lit").CSSResult[];
2
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import { css } from 'lit';
2
+ const styles = css `
3
+ :host {
4
+ display: flex;
5
+ flex-direction: column;
6
+ gap: 0.75rem;
7
+ }
8
+ `;
9
+ export default [styles];
@@ -0,0 +1,8 @@
1
+ import CheckboxGroup from './checkboxgroup.component';
2
+ import '../text';
3
+ declare global {
4
+ interface HTMLElementTagNameMap {
5
+ ['mdc-checkboxgroup']: CheckboxGroup;
6
+ }
7
+ }
8
+ export default CheckboxGroup;
@@ -0,0 +1,5 @@
1
+ import CheckboxGroup from './checkboxgroup.component';
2
+ import { TAG_NAME } from './checkboxgroup.constants';
3
+ import '../text';
4
+ CheckboxGroup.register(TAG_NAME);
5
+ export default CheckboxGroup;