@momentum-design/components 0.92.2 → 0.92.3

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 (37) hide show
  1. package/dist/browser/index.js +303 -297
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/menubar/menubar.component.d.ts +2 -1
  4. package/dist/components/menubar/menubar.component.js +23 -2
  5. package/dist/components/menusection/menusection.component.d.ts +9 -0
  6. package/dist/components/menusection/menusection.component.js +15 -1
  7. package/dist/components/menusection/menusection.constants.d.ts +4 -1
  8. package/dist/components/menusection/menusection.constants.js +4 -1
  9. package/dist/components/popover/popover.component.d.ts +1 -1
  10. package/dist/components/popover/popover.component.js +9 -0
  11. package/dist/components/popover/popover.events.d.ts +12 -0
  12. package/dist/components/popover/popover.events.js +16 -0
  13. package/dist/components/popover/popover.utils.js +1 -1
  14. package/dist/components/select/select.component.d.ts +32 -37
  15. package/dist/components/select/select.component.js +132 -148
  16. package/dist/components/select/select.constants.d.ts +2 -1
  17. package/dist/components/select/select.constants.js +2 -1
  18. package/dist/components/select/select.styles.js +20 -17
  19. package/dist/components/select/select.types.d.ts +3 -1
  20. package/dist/components/selectlistbox/index.d.ts +7 -0
  21. package/dist/components/selectlistbox/index.js +4 -0
  22. package/dist/components/selectlistbox/selectlistbox.component.d.ts +18 -0
  23. package/dist/components/selectlistbox/selectlistbox.component.js +24 -0
  24. package/dist/components/selectlistbox/selectlistbox.constants.d.ts +2 -0
  25. package/dist/components/selectlistbox/selectlistbox.constants.js +3 -0
  26. package/dist/components/selectlistbox/selectlistbox.types.d.ts +3 -0
  27. package/dist/components/selectlistbox/selectlistbox.types.js +1 -0
  28. package/dist/custom-elements.json +1273 -1223
  29. package/dist/index.d.ts +2 -1
  30. package/dist/index.js +2 -1
  31. package/dist/react/index.d.ts +3 -2
  32. package/dist/react/index.js +3 -2
  33. package/dist/react/select/index.d.ts +2 -0
  34. package/dist/react/select/index.js +2 -0
  35. package/dist/react/selectlistbox/index.d.ts +15 -0
  36. package/dist/react/selectlistbox/index.js +24 -0
  37. package/package.json +1 -1
@@ -24,8 +24,9 @@ import { Component } from '../../models';
24
24
  * @slot default - Contains the menu items and their associated popovers
25
25
  */
26
26
  declare class MenuBar extends Component {
27
+ menusections: Array<HTMLElement>;
27
28
  constructor();
28
- connectedCallback(): void;
29
+ connectedCallback(): Promise<void>;
29
30
  /**
30
31
  * Returns all menuitem elements, including those nested inside menusection.
31
32
  */
@@ -1,4 +1,14 @@
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
+ };
1
10
  import { html } from 'lit';
11
+ import { queryAssignedElements } from 'lit/decorators.js';
2
12
  import { Component } from '../../models';
3
13
  import { ROLE } from '../../utils/roles';
4
14
  import { POPOVER_PLACEMENT } from '../popover/popover.constants';
@@ -37,10 +47,16 @@ class MenuBar extends Component {
37
47
  super();
38
48
  this.addEventListener('keydown', this.handleKeyDown);
39
49
  }
40
- connectedCallback() {
50
+ async connectedCallback() {
51
+ var _a;
41
52
  super.connectedCallback();
42
53
  this.role = ROLE.MENUBAR;
43
54
  this.ariaOrientation = DEFAULTS.ORIENTATION;
55
+ await this.updateComplete;
56
+ // to make sure menusection dividers have the correct divider variant
57
+ (_a = this.menusections) === null || _a === void 0 ? void 0 : _a.forEach(section => {
58
+ section.setAttribute('divider-variant', 'gradient');
59
+ });
44
60
  }
45
61
  /**
46
62
  * Returns all menuitem elements, including those nested inside menusection.
@@ -178,7 +194,8 @@ class MenuBar extends Component {
178
194
  const grandParentTag = (_a = parent.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase();
179
195
  if (parentTag === MENUBAR_TAGNAME || parentTag === SIDENAV_TAGNAME)
180
196
  return true;
181
- if (parentTag === MENUSECTION_TAGNAME && (grandParentTag === MENUBAR_TAGNAME || grandParentTag === SIDENAV_TAGNAME)) {
197
+ if (parentTag === MENUSECTION_TAGNAME &&
198
+ (grandParentTag === MENUBAR_TAGNAME || grandParentTag === SIDENAV_TAGNAME)) {
182
199
  return true;
183
200
  }
184
201
  return false;
@@ -280,4 +297,8 @@ class MenuBar extends Component {
280
297
  }
281
298
  }
282
299
  MenuBar.styles = [...Component.styles, ...styles];
300
+ __decorate([
301
+ queryAssignedElements({ selector: 'mdc-menusection', flatten: true }),
302
+ __metadata("design:type", Array)
303
+ ], MenuBar.prototype, "menusections", void 0);
283
304
  export default MenuBar;
@@ -39,6 +39,15 @@ declare class MenuSection extends Component {
39
39
  * This is useful for visually separating sections in the menu.
40
40
  */
41
41
  showDivider: boolean;
42
+ /**
43
+ * The variant of the divider.
44
+ * Can be set to 'solid' or 'gradient'.
45
+ *
46
+ * Keep 'solid' if used in MenuPopovers, as it is the default style.
47
+ *
48
+ * @default 'solid'
49
+ */
50
+ dividerVariant: "solid";
42
51
  /**
43
52
  * Shows or hides the section headers based on the expanded state of the side navigation.
44
53
  *
@@ -15,6 +15,7 @@ import providerUtils from '../../utils/provider';
15
15
  import { ROLE } from '../../utils/roles';
16
16
  import SideNavigation from '../sidenavigation/sidenavigation.component';
17
17
  import styles from './menusection.styles';
18
+ import { DEFAULTS } from './menusection.constants';
18
19
  /**
19
20
  * `mdc-menusection` is a container element used to group a set of menu items.
20
21
  *
@@ -49,6 +50,15 @@ class MenuSection extends Component {
49
50
  * This is useful for visually separating sections in the menu.
50
51
  */
51
52
  this.showDivider = false;
53
+ /**
54
+ * The variant of the divider.
55
+ * Can be set to 'solid' or 'gradient'.
56
+ *
57
+ * Keep 'solid' if used in MenuPopovers, as it is the default style.
58
+ *
59
+ * @default 'solid'
60
+ */
61
+ this.dividerVariant = DEFAULTS.DIVIDER_VARIANT;
52
62
  /**
53
63
  * Shows or hides the section headers based on the expanded state of the side navigation.
54
64
  *
@@ -97,7 +107,7 @@ class MenuSection extends Component {
97
107
  return html `
98
108
  ${!this.hideHeaderText ? this.renderHeader() : null}
99
109
  <slot></slot>
100
- ${this.showDivider ? html `<mdc-divider variant="gradient" part="divider"></mdc-divider>` : null}
110
+ ${this.showDivider ? html `<mdc-divider variant="${this.dividerVariant}" part="divider"></mdc-divider>` : null}
101
111
  `;
102
112
  }
103
113
  }
@@ -118,6 +128,10 @@ __decorate([
118
128
  property({ type: Boolean, reflect: true, attribute: 'show-divider' }),
119
129
  __metadata("design:type", Object)
120
130
  ], MenuSection.prototype, "showDivider", void 0);
131
+ __decorate([
132
+ property({ type: String, reflect: true, attribute: 'divider-variant' }),
133
+ __metadata("design:type", Object)
134
+ ], MenuSection.prototype, "dividerVariant", void 0);
121
135
  __decorate([
122
136
  property({ type: Boolean, reflect: true, attribute: 'hide-header-text' }),
123
137
  __metadata("design:type", Object)
@@ -1,2 +1,5 @@
1
1
  declare const TAG_NAME: "mdc-menusection";
2
- export { TAG_NAME };
2
+ declare const DEFAULTS: {
3
+ readonly DIVIDER_VARIANT: "solid";
4
+ };
5
+ export { TAG_NAME, DEFAULTS };
@@ -1,3 +1,6 @@
1
1
  import utils from '../../utils/tag-name';
2
2
  const TAG_NAME = utils.constructTagName('menusection');
3
- export { TAG_NAME };
3
+ const DEFAULTS = {
4
+ DIVIDER_VARIANT: 'solid',
5
+ };
6
+ export { TAG_NAME, DEFAULTS };
@@ -1,6 +1,6 @@
1
1
  import { CSSResult, PropertyValues } from 'lit';
2
2
  import { Component } from '../../models';
3
- import { PopoverColor, PopoverPlacement, PopoverTrigger } from './popover.types';
3
+ import type { PopoverColor, PopoverPlacement, PopoverTrigger } from './popover.types';
4
4
  declare const Popover_base: import("../../utils/mixins/index.types").Constructor<Component & import("../../utils/mixins/PreventScrollMixin").PreventScrollMixinInterface> & import("../../utils/mixins/index.types").Constructor<Component & import("../../utils/mixins/FocusTrapMixin").FocusTrapClassInterface> & typeof Component;
5
5
  /**
6
6
  * Popover component is a lightweight floating UI element that displays additional content when triggered.
@@ -282,6 +282,7 @@ class Popover extends PreventScrollMixin(FocusTrapMixin(Component)) {
282
282
  const clickedOnBackdrop = this.backdropElement ? path.includes(this.backdropElement) : false;
283
283
  if (!insidePopoverClick || clickedOnBackdrop) {
284
284
  this.hidePopover();
285
+ PopoverEventManager.onClickOutside(this);
285
286
  }
286
287
  };
287
288
  /**
@@ -301,6 +302,7 @@ class Popover extends PreventScrollMixin(FocusTrapMixin(Component)) {
301
302
  }
302
303
  event.preventDefault();
303
304
  this.hidePopover();
305
+ PopoverEventManager.onEscapeKeyPressed(this);
304
306
  };
305
307
  /**
306
308
  * Handles the popover focus out event.
@@ -492,6 +494,13 @@ class Popover extends PreventScrollMixin(FocusTrapMixin(Component)) {
492
494
  }
493
495
  async updated(changedProperties) {
494
496
  super.updated(changedProperties);
497
+ // If the role is changed to an empty string, set it to null
498
+ // to avoid setting an invalid role on the popover element.
499
+ if (changedProperties.has('role')) {
500
+ if (this.role === '') {
501
+ this.role = null;
502
+ }
503
+ }
495
504
  if (changedProperties.has('visible')) {
496
505
  const oldValue = changedProperties.get('visible') || false;
497
506
  await this.isOpenUpdated(oldValue, this.visible);
@@ -31,4 +31,16 @@ export declare class PopoverEventManager {
31
31
  * @param instance - The popover instance.
32
32
  */
33
33
  static onDestroyedPopover(instance: Popover): void;
34
+ /**
35
+ * Custom event that is fired when the popover is closed by pressing the Escape key.
36
+ *
37
+ * @param instance - The popover instance.
38
+ */
39
+ static onEscapeKeyPressed(instance: Popover): void;
40
+ /**
41
+ * Custom event that is fired when the popover is closed by clicking outside of it.
42
+ *
43
+ * @param instance - The popover instance.
44
+ */
45
+ static onClickOutside(instance: Popover): void;
34
46
  }
@@ -44,4 +44,20 @@ export class PopoverEventManager {
44
44
  static onDestroyedPopover(instance) {
45
45
  this.dispatchPopoverEvent('destroyed', instance);
46
46
  }
47
+ /**
48
+ * Custom event that is fired when the popover is closed by pressing the Escape key.
49
+ *
50
+ * @param instance - The popover instance.
51
+ */
52
+ static onEscapeKeyPressed(instance) {
53
+ this.dispatchPopoverEvent('closebyescape', instance);
54
+ }
55
+ /**
56
+ * Custom event that is fired when the popover is closed by clicking outside of it.
57
+ *
58
+ * @param instance - The popover instance.
59
+ */
60
+ static onClickOutside(instance) {
61
+ this.dispatchPopoverEvent('closebyoutsideclick', instance);
62
+ }
47
63
  }
@@ -96,7 +96,7 @@ export class PopoverUtils {
96
96
  else {
97
97
  this.popover.removeAttribute('aria-modal');
98
98
  }
99
- if (this.popover.interactive) {
99
+ if (this.popover.interactive && this.popover.role) {
100
100
  if (!this.popover.ariaLabel) {
101
101
  this.popover.ariaLabel =
102
102
  ((_a = this.popover.triggerElement) === null || _a === void 0 ? void 0 : _a.ariaLabel) || ((_b = this.popover.triggerElement) === null || _b === void 0 ? void 0 : _b.textContent) || '';
@@ -1,8 +1,9 @@
1
- import type { PropertyValues, TemplateResult } from 'lit';
1
+ import type { PropertyValues } from 'lit';
2
2
  import { CSSResult } from 'lit';
3
3
  import { AssociatedFormControl } from '../../utils/mixins/FormInternalsMixin';
4
4
  import FormfieldWrapper from '../formfieldwrapper/formfieldwrapper.component';
5
5
  import type { IconNames } from '../icon/icon.types';
6
+ import type { Placement } from './select.types';
6
7
  declare const Select_base: import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/FormInternalsMixin").FormInternalsMixinInterface> & import("../../utils/mixins/index.types").Constructor<import("../../utils/mixins/DataAriaLabelMixin").DataAriaLabelMixinInterface> & typeof FormfieldWrapper;
7
8
  /**
8
9
  * The mdc-select component is a dropdown selection control that allows users to pick an option from a predefined list.
@@ -12,6 +13,8 @@ declare const Select_base: import("../../utils/mixins/index.types").Constructor<
12
13
  *
13
14
  * To set a default option, use the `selected` attribute on the `mdc-option` element.
14
15
  *
16
+ * **Note:** Make sure to add `mdc-selectlistbox` as a child of `mdc-select` and wrap options/optgroup in it to ensure proper accessibility functionality. Read more about it in SelectListBox documentation.
17
+ *
15
18
  * @dependency mdc-button
16
19
  * @dependency mdc-icon
17
20
  * @dependency mdc-popover
@@ -44,8 +47,20 @@ declare class Select extends Select_base implements AssociatedFormControl {
44
47
  * @default auto
45
48
  */
46
49
  height: string;
50
+ /**
51
+ * The placeholder text which will be shown on the text if provided.
52
+ */
53
+ placement: Placement;
54
+ /**
55
+ * Indicates whether the select is soft disabled.
56
+ * When set to `true`, the select appears visually disabled but still allows
57
+ * focus.
58
+ *
59
+ * @default undefined
60
+ */
61
+ softDisabled?: boolean;
47
62
  /** @internal */
48
- optionsList: Array<HTMLElement>;
63
+ slottedListboxes: Array<HTMLElement>;
49
64
  /** @internal */
50
65
  private baseIconName;
51
66
  /** @internal */
@@ -56,21 +71,26 @@ declare class Select extends Select_base implements AssociatedFormControl {
56
71
  selectedValue: string;
57
72
  /** @internal */
58
73
  displayPopover: boolean;
59
- /** @internal */
60
- activeDescendant: string;
61
74
  /**
62
75
  * @internal
63
76
  * The native select element
64
77
  */
65
78
  inputElement: HTMLInputElement;
66
79
  /**
67
- * A helper function which returns a flattened array of all valid options from the assigned slot.
80
+ * Modifies the listbox wrapper to ensure it has the correct attributes
81
+ * and IDs for accessibility.
82
+ *
83
+ * Once [ariaOwnsElements](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/ariaOwnsElements) is supported in browsers,
84
+ * this an be removed and mdc-option can be used directly in the select component with a listbox in a different
85
+ * shadow root and aria-owns attribute to connect them.
86
+ */
87
+ private modifyListBoxWrapper;
88
+ /**
89
+ * A helper function which returns a flattened array of all valid options from within the slotted listbox.
68
90
  * It takes care of the edge cases where the option is either a direct child or a
69
91
  * child of an option group.
70
92
  */
71
93
  private getAllValidOptions;
72
- private handlePopoverOpen;
73
- private handlePopoverClose;
74
94
  /**
75
95
  * Updates the tabindex and selected attribute of the options.
76
96
  * If selectedOption is provided, it will be set as the selected option.
@@ -119,6 +139,7 @@ declare class Select extends Select_base implements AssociatedFormControl {
119
139
  * @param event - The keyboard event.
120
140
  */
121
141
  private handlePopoverOnOpen;
142
+ private handleClickCombobox;
122
143
  /**
123
144
  * Handles the keydown event on the select element when the popover is closed.
124
145
  * The options are as follows:
@@ -128,7 +149,7 @@ declare class Select extends Select_base implements AssociatedFormControl {
128
149
  * - END: Opens the popover and sets focus and tabindex on the last option.
129
150
  * @param event - The keyboard event.
130
151
  */
131
- private handlePopoverOnClose;
152
+ private handleKeydownCombobox;
132
153
  /**
133
154
  * Handles the navigation of options when the user presses
134
155
  * ArrowUp, ArrowDown, PageUp, or PageDown keys.
@@ -149,8 +170,6 @@ declare class Select extends Select_base implements AssociatedFormControl {
149
170
  * @returns The new index to focus on, or -1 if no movement is possible.
150
171
  */
151
172
  private getNewIndexBasedOnKey;
152
- private updateActivedescendant;
153
- private resetActivedescendant;
154
173
  private setFocusAndTabIndex;
155
174
  private openPopover;
156
175
  private closePopover;
@@ -159,34 +178,10 @@ declare class Select extends Select_base implements AssociatedFormControl {
159
178
  * If an option is selected, use that as the value.
160
179
  * If not, use the placeholder if it exists, otherwise use the first option.
161
180
  */
162
- firstUpdated(): void;
163
- /**
164
- * Generates the native select element.
165
- * The native select element is not rendered directly and is not visible on the UI.
166
- * It's rendered only on the DOM for accessibility purposes.
167
- * Instead, the overlay uses the native select element to generate the list of options.
168
- * @returns A TemplateResult representing the native select element.
169
- */
170
- private getNativeSelect;
171
- /**
172
- * This method maps over all valid options and constructs their corresponding
173
- * HTML `<option>` elements. The attributes such as `value`, `label`, `disabled`,
174
- * and `selected` are extracted from the respective option elements.
175
- * If the attribute is not present, a default value or fallback is used.
176
- * The content of each `<option>` is set to the text content of the option element.
177
- * @returns An array of `TemplateResult` representing the option elements.
178
- */
179
- private getOptionsContentFromSlot;
180
- /**
181
- * Generates the content for the popover associated with the select component.
182
- * If the component is disabled or readonly, returns `nothing`.
183
- * Otherwise, returns a `TemplateResult` that renders a popover with various configurations
184
- * such as visibility, interaction, and event handlers.
185
- * The popover acts as a dropdown list with options, allowing user interaction.
186
- */
187
- private getPopoverContent;
181
+ firstUpdated(): Promise<void>;
188
182
  updated(changedProperties: PropertyValues): void;
189
- render(): TemplateResult<1>;
183
+ private handleOnChange;
184
+ render(): import("lit-html").TemplateResult<1>;
190
185
  static styles: Array<CSSResult>;
191
186
  }
192
187
  export default Select;