@momentum-design/components 0.51.0 → 0.51.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.
Files changed (31) hide show
  1. package/dist/browser/index.js +225 -185
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/select/select.component.d.ts +1 -1
  4. package/dist/components/select/select.component.js +7 -7
  5. package/dist/components/tab/tab.component.d.ts +21 -0
  6. package/dist/components/tab/tab.component.js +28 -1
  7. package/dist/components/tab/tab.styles.js +1 -0
  8. package/dist/components/tablist/index.d.ts +9 -0
  9. package/dist/components/tablist/index.js +6 -0
  10. package/dist/components/tablist/tablist.component.d.ts +230 -0
  11. package/dist/components/tablist/tablist.component.js +517 -0
  12. package/dist/components/tablist/tablist.constants.d.ts +12 -0
  13. package/dist/components/tablist/tablist.constants.js +13 -0
  14. package/dist/components/tablist/tablist.styles.d.ts +2 -0
  15. package/dist/components/tablist/tablist.styles.js +35 -0
  16. package/dist/components/tablist/tablist.types.d.ts +7 -0
  17. package/dist/components/tablist/tablist.types.js +1 -0
  18. package/dist/components/tablist/tablist.utils.d.ts +7 -0
  19. package/dist/components/tablist/tablist.utils.js +12 -0
  20. package/dist/custom-elements.json +265 -117
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +2 -1
  23. package/dist/react/index.d.ts +2 -1
  24. package/dist/react/index.js +2 -1
  25. package/dist/react/tab/index.d.ts +9 -0
  26. package/dist/react/tab/index.js +9 -0
  27. package/dist/react/tablist/index.d.ts +51 -0
  28. package/dist/react/tablist/index.js +59 -0
  29. package/dist/utils/styles/index.d.ts +2 -1
  30. package/dist/utils/styles/index.js +3 -3
  31. package/package.json +1 -1
@@ -47,7 +47,7 @@ declare class Select extends Select_base implements AssociatedFormControl {
47
47
  /** @internal */
48
48
  selectedValue: string;
49
49
  /** @internal */
50
- showPopover: boolean;
50
+ displayPopover: boolean;
51
51
  /** @internal */
52
52
  activeDescendant: string;
53
53
  /**
@@ -58,7 +58,7 @@ class Select extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
58
58
  /** @internal */
59
59
  this.selectedValue = '';
60
60
  /** @internal */
61
- this.showPopover = false;
61
+ this.displayPopover = false;
62
62
  /** @internal */
63
63
  this.activeDescendant = '';
64
64
  }
@@ -197,7 +197,7 @@ class Select extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
197
197
  * @param event - The keyboard event.
198
198
  */
199
199
  handleKeydown(event) {
200
- if (this.showPopover) {
200
+ if (this.displayPopover) {
201
201
  this.handlePopoverOnOpen(event);
202
202
  }
203
203
  else {
@@ -341,11 +341,11 @@ class Select extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
341
341
  });
342
342
  }
343
343
  openPopover() {
344
- this.showPopover = true;
344
+ this.displayPopover = true;
345
345
  this.resetActivedescendant();
346
346
  }
347
347
  closePopover() {
348
- this.showPopover = false;
348
+ this.displayPopover = false;
349
349
  this.resetActivedescendant();
350
350
  }
351
351
  /**
@@ -392,7 +392,7 @@ class Select extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
392
392
  ?disabled="${this.disabled}"
393
393
  ?required="${!!this.requiredLabel}"
394
394
  aria-activedescendant="${this.activeDescendant}"
395
- aria-expanded="${this.showPopover}"
395
+ aria-expanded="${this.displayPopover}"
396
396
  aria-haspopup="listbox"
397
397
  aria-label="${(_a = this.dataAriaLabel) !== null && _a !== void 0 ? _a : ''}"
398
398
  aria-labelledby="${this.label ? FORMFIELD_DEFAULTS.HEADING_ID : ''}"
@@ -443,7 +443,7 @@ class Select extends FormInternalsMixin(DataAriaLabelMixin(FormfieldWrapper)) {
443
443
  id="options-popover"
444
444
  triggerid="select-base-triggerid"
445
445
  interactive
446
- ?visible="${this.showPopover}"
446
+ ?visible="${this.displayPopover}"
447
447
  hide-on-outside-click
448
448
  focus-back-to-trigger
449
449
  focus-trap
@@ -532,7 +532,7 @@ __decorate([
532
532
  __decorate([
533
533
  state(),
534
534
  __metadata("design:type", Object)
535
- ], Select.prototype, "showPopover", void 0);
535
+ ], Select.prototype, "displayPopover", void 0);
536
536
  __decorate([
537
537
  state(),
538
538
  __metadata("design:type", Object)
@@ -7,6 +7,8 @@ declare const Tab_base: import("../../utils/mixins/index.types").Constructor<imp
7
7
  *
8
8
  * Passing in the attribute `text` to the tab component is changing the text displayed in the tab.
9
9
  *
10
+ * Pass attribute `tabid` when using inside of `tablist` component.
11
+ *
10
12
  * The `slot="badge"` can be used to add a badge to the tab.
11
13
  *
12
14
  * The `slot="chip"` can be used to add a chip to the tab.
@@ -23,6 +25,12 @@ declare const Tab_base: import("../../utils/mixins/index.types").Constructor<imp
23
25
  * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the tab.
24
26
  * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the tab.
25
27
  * @event focus - (React: onFocus) This event is dispatched when the tab receives focus.
28
+ * @event activechange - (React: onActiveChange) This event is dispatched when the active state of the tab changes
29
+ * <br />
30
+ * Event Data: `detail: { tabId: this.tabId, active }`
31
+ * <br />
32
+ * Note: the activechange event is used by the tab list component to react to the change in state of the tab,
33
+ * so this event won't be needed if the tab list is used.
26
34
  *
27
35
  * @tagname mdc-tab
28
36
  *
@@ -108,6 +116,13 @@ declare class Tab extends Tab_base {
108
116
  * @default pill
109
117
  */
110
118
  variant: Variant;
119
+ /**
120
+ * Id of the tab (used as a identificator when used in the tablist)
121
+ * Note: has to be unique!
122
+ *
123
+ * @default undefined
124
+ */
125
+ tabId?: string;
111
126
  /**
112
127
  * @internal
113
128
  */
@@ -130,6 +145,12 @@ declare class Tab extends Tab_base {
130
145
  * @param variant - The variant to set.
131
146
  */
132
147
  private setVariant;
148
+ /**
149
+ * Dispatch the activechange event.
150
+ *
151
+ * @param active - The active state of the tab.
152
+ */
153
+ private handleTabActiveChange;
133
154
  /**
134
155
  * Sets the aria-selected attribute based on the active state of the Tab.
135
156
  * If the tab is active, the filled version of the icon is displayed,
@@ -20,6 +20,8 @@ import { IconNameMixin } from '../../utils/mixins/IconNameMixin';
20
20
  *
21
21
  * Passing in the attribute `text` to the tab component is changing the text displayed in the tab.
22
22
  *
23
+ * Pass attribute `tabid` when using inside of `tablist` component.
24
+ *
23
25
  * The `slot="badge"` can be used to add a badge to the tab.
24
26
  *
25
27
  * The `slot="chip"` can be used to add a chip to the tab.
@@ -36,6 +38,12 @@ import { IconNameMixin } from '../../utils/mixins/IconNameMixin';
36
38
  * @event keydown - (React: onKeyDown) This event is dispatched when a key is pressed down on the tab.
37
39
  * @event keyup - (React: onKeyUp) This event is dispatched when a key is released on the tab.
38
40
  * @event focus - (React: onFocus) This event is dispatched when the tab receives focus.
41
+ * @event activechange - (React: onActiveChange) This event is dispatched when the active state of the tab changes
42
+ * <br />
43
+ * Event Data: `detail: { tabId: this.tabId, active }`
44
+ * <br />
45
+ * Note: the activechange event is used by the tab list component to react to the change in state of the tab,
46
+ * so this event won't be needed if the tab list is used.
39
47
  *
40
48
  * @tagname mdc-tab
41
49
  *
@@ -117,6 +125,18 @@ class Tab extends IconNameMixin(Buttonsimple) {
117
125
  * @default pill
118
126
  */
119
127
  this.variant = DEFAULTS.VARIANT;
128
+ /**
129
+ * Dispatch the activechange event.
130
+ *
131
+ * @param active - The active state of the tab.
132
+ */
133
+ this.handleTabActiveChange = (active) => {
134
+ const event = new CustomEvent('activechange', {
135
+ detail: { tabId: this.tabId, active },
136
+ bubbles: true,
137
+ });
138
+ this.dispatchEvent(event);
139
+ };
120
140
  }
121
141
  connectedCallback() {
122
142
  super.connectedCallback();
@@ -124,6 +144,9 @@ class Tab extends IconNameMixin(Buttonsimple) {
124
144
  this.softDisabled = undefined;
125
145
  this.size = undefined;
126
146
  this.type = undefined;
147
+ if (!this.tabId && this.onerror) {
148
+ this.onerror('tab id is required');
149
+ }
127
150
  }
128
151
  /**
129
152
  * Modifies the icon name based on the active state.
@@ -168,7 +191,7 @@ class Tab extends IconNameMixin(Buttonsimple) {
168
191
  }
169
192
  executeAction() {
170
193
  // Toggle the active state of the tab.
171
- this.active = !this.active;
194
+ this.handleTabActiveChange(this.active);
172
195
  }
173
196
  update(changedProperties) {
174
197
  super.update(changedProperties);
@@ -207,4 +230,8 @@ __decorate([
207
230
  property({ type: String, reflect: true }),
208
231
  __metadata("design:type", String)
209
232
  ], Tab.prototype, "variant", void 0);
233
+ __decorate([
234
+ property({ type: String, reflect: true, attribute: 'tab-id' }),
235
+ __metadata("design:type", String)
236
+ ], Tab.prototype, "tabId", void 0);
210
237
  export default Tab;
@@ -72,6 +72,7 @@ const styles = [hostFitContentStyles, css `
72
72
  --mdc-tab-pill-inactive-color-disabled: var(--mds-color-theme-text-primary-disabled);
73
73
 
74
74
  flex-direction: column;
75
+ flex-shrink: 0;
75
76
  height: var(--mdc-tab-height);
76
77
  padding-left: var(--mdc-tab-padding-left);
77
78
  padding-right: var(--mdc-tab-padding-right);
@@ -0,0 +1,9 @@
1
+ import Tablist from './tablist.component';
2
+ import '../button';
3
+ import '../tab';
4
+ declare global {
5
+ interface HTMLElementTagNameMap {
6
+ ['mdc-tablist']: Tablist;
7
+ }
8
+ }
9
+ export default Tablist;
@@ -0,0 +1,6 @@
1
+ import Tablist from './tablist.component';
2
+ import { TAG_NAME } from './tablist.constants';
3
+ import '../button';
4
+ import '../tab';
5
+ Tablist.register(TAG_NAME);
6
+ export default Tablist;
@@ -0,0 +1,230 @@
1
+ import { CSSResult } from 'lit';
2
+ import type { PropertyValues } from 'lit';
3
+ import { Component } from '../../models';
4
+ /**
5
+ * Tab list organizes tabs into a container.
6
+ *
7
+ * Children of the tab list are `mdc-tab` elements, sent to the default slot.
8
+ *
9
+ * The tabs can be navigated using the left/right arrow keys, and selected by clicking,
10
+ * or pressing the Enter and Space keys.
11
+ *
12
+ * **Implicit accessibility rules**
13
+ *
14
+ * - The element that serves as the container for the set of tabs has role `tablist`.
15
+ * - Each element that serves as a tab has role `tab` and is contained within the element with role `tablist`.
16
+ * - The active tab element has the state `aria-selected` set to `true`
17
+ * and all other tab elements have it set to `false`.
18
+ *
19
+ *
20
+ * **Accessibility notes for consuming (have to be explicitly set when you consume the component)**
21
+ *
22
+ * - Each element that contains the `content panel` for a `tab` has role `tabpanel`.
23
+ * - If the tab list has a visible label,
24
+ * the element with role `tablist` has `aria-labelledby` needs to be a value that refers to the labelling element.
25
+ * Otherwise, the `tablist` element needs to have a label provided by `aria-label`.
26
+ * - Each element with role `tab` has the property `aria-controls`
27
+ * that should refer to its associated `tabpanel` element.
28
+ * - Each element with role `tabpanel` has the property `aria-labelledby` referring to its associated `tab` element.
29
+ * - If a `tab` element has a popup menu, it needs to have the property `aria-haspopup` set to either `menu` or `true`.
30
+ *
31
+ * @tagname mdc-tablist
32
+ *
33
+ * @dependency mdc-tab
34
+ * @dependency mdc-button
35
+ *
36
+ * @event change - (React: onChange) This event is dispatched when the tab is selected.
37
+ * Event that fires when user changes the active tab.
38
+ * The function sent as the argument will receive the fired event
39
+ * and the new tab id can be fetched from event.detail.tabId.
40
+ *
41
+ * `(event: CustomEvent) => handleTabChange(event.detail.tabId);`
42
+ *
43
+ * @slot Default slot for mdc-tab elements.
44
+ *
45
+ * @cssproperty --mdc-tablist-gap - Gap between tabs
46
+ * @cssproperty --mdc-tablist-width - Width of the tablist
47
+ * @cssproperty --mdc-tablist-arrow-button-margin - Margin value for the arrow button
48
+ */
49
+ declare class TabList extends Component {
50
+ /**
51
+ * ID of the active tab, defaults to the first tab if not provided
52
+ */
53
+ activeTabId?: string;
54
+ /**
55
+ * Selector for the element that provides a label for the tablist.
56
+ */
57
+ dataAriaLabelledby?: string;
58
+ /**
59
+ * Label for the tablist in case aria-labelledby is not provided.
60
+ * This is used when the tablist does not have a visible label.
61
+ * Defaults to 'Tab List'.
62
+ * <br/>
63
+ * Note: If both `data-aria-labelledby` and `data-aria-label` are provided,
64
+ * the `data-aria-labelledby` will be used.
65
+ */
66
+ dataAriaLabel?: string;
67
+ /**
68
+ * The tab container element.
69
+ * Has the role of `tablist`.
70
+ * @internal
71
+ */
72
+ private tabsContainer?;
73
+ /**
74
+ * Arrow button that is not focused.
75
+ * @internal
76
+ */
77
+ private notFocusedArrowButton?;
78
+ /**
79
+ * Children of the tablist, elements of type `mdc-tab`.
80
+ * @internal
81
+ */
82
+ private tabs?;
83
+ /**
84
+ * Instead of using 'left' and 'right' for notation of the arrow buttons, we use 'forward' and 'backward'.
85
+ * Since the elements of the tablist gets flipped in RTL layouts, the arrow buttons also flip.
86
+ * For both RTL and LTR layouts, the forward arrow button moves the tabs in the forward direction.
87
+ * i.e. the forward arrow button moves the tabs to the right in LTR layouts and to the left in RTL layouts.
88
+ */
89
+ /**
90
+ * @internal
91
+ */
92
+ private showForwardArrowButton;
93
+ /**
94
+ * @internal
95
+ */
96
+ private showBackwardArrowButton;
97
+ /**
98
+ * @internal
99
+ */
100
+ private isRtl;
101
+ constructor();
102
+ /**
103
+ * Set the initial active tab after firstUpdated,
104
+ * since this.tabs (=slot) are only available after
105
+ * the first update
106
+ *
107
+ * Also set up the event listeners.
108
+ */
109
+ protected firstUpdated(): Promise<void>;
110
+ /**
111
+ * Observe the tablist element for changes in the activeTabId attribute.
112
+ * Find the new tab with the new activeTabId.
113
+ * If the new tab is not found, then do nothing.
114
+ *
115
+ * If the new tab exists:
116
+ * Set the new tab as active.
117
+ *
118
+ * Fire the tab change event.
119
+ *
120
+ * @param changedProperties - Map of changed properties with old values.
121
+ */
122
+ update(changedProperties: PropertyValues<this>): Promise<void>;
123
+ /**
124
+ * Set aria-labelledby attribute on the tablist element.
125
+ * If it does not exist, set aria-label attribute.
126
+ * As fallback, set aria-label to 'Tab List'.
127
+ *
128
+ * @internal
129
+ */
130
+ private setAriaLabelledByOrAriaLabel;
131
+ /**
132
+ * Dispatch the change event.
133
+ *
134
+ * @internal
135
+ *
136
+ * @param newTab - the new tab that is active.
137
+ */
138
+ private fireTabChangeEvent;
139
+ /**
140
+ * When the tablist receives focus, then focus the active tab.
141
+ *
142
+ * @internal
143
+ *
144
+ * @param event - Focus event.
145
+ */
146
+ private handleFocus;
147
+ /**
148
+ * Prevent the mousedown event from triggering a focus event before the click event.
149
+ *
150
+ * @internal
151
+ *
152
+ * @param event - Mouse event.
153
+ */
154
+ private handleMousedown;
155
+ /**
156
+ * Handle the tab active change event fired from the nested tab.
157
+ *
158
+ * @internal
159
+ *
160
+ * @param event - Custom Event fired from the nested tab.
161
+ */
162
+ private handleNestedTabActiveChange;
163
+ /**
164
+ * Resets all tabs' tabindex to -1 and sets the tabindex of the
165
+ * given tab to 0.
166
+ * This is used when navigating the tabs via keyboard.
167
+ *
168
+ * @internal
169
+ *
170
+ * @param tabId - The id of the new active tab in the tabs.
171
+ */
172
+ private resetTabIndexAndSetNewTabIndex;
173
+ /**
174
+ * Removes active attribute from all tabs and sets active on the new tab.
175
+ *
176
+ * @internal
177
+ *
178
+ * @param tabId - The id of the new active tab.
179
+ */
180
+ private setActiveTab;
181
+ /**
182
+ * Set focus on the new tab, then scroll it into view.
183
+ *
184
+ * @internal
185
+ *
186
+ * @param tab - Tab to set focus on.
187
+ */
188
+ private focusTab;
189
+ /**
190
+ * Handle the keydown event. The arrow keys, Home, End, Enter, and Space keys are supported.
191
+ *
192
+ * @internal
193
+ *
194
+ * @param event - HTML Keyboard Event.
195
+ */
196
+ private handleKeydown;
197
+ /**
198
+ * Should the arrow button be shown.
199
+ *
200
+ * @internal
201
+ *
202
+ * @param direction - The direction of the arrow button.
203
+ */
204
+ private shouldShowArrowButton;
205
+ /**
206
+ * If an arrow button is in focus and it gets removed, switch focus to the opposite arrow button.
207
+ * If both arrow buttons are removed, switch focus to the active tab.
208
+ *
209
+ * @internal
210
+ */
211
+ private switchFocus;
212
+ /**
213
+ * Show or hide the arrow buttons based on the position of the tabs
214
+ * corresponding to the tab list.
215
+ *
216
+ * @internal
217
+ */
218
+ private handleArrowButtonVisibility;
219
+ /**
220
+ * Scroll tabs forward or backward.
221
+ *
222
+ * @internal
223
+ *
224
+ * @param direction - The direction to scroll the tabs in.
225
+ */
226
+ private scrollTabs;
227
+ render(): import("lit-html").TemplateResult<1>;
228
+ static styles: Array<CSSResult>;
229
+ }
230
+ export default TabList;