@momentum-design/components 0.61.1 → 0.62.0

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.
@@ -1,6 +1,5 @@
1
1
  import Tablist from './tablist.component';
2
2
  import '../button';
3
- import '../tab';
4
3
  declare global {
5
4
  interface HTMLElementTagNameMap {
6
5
  ['mdc-tablist']: Tablist;
@@ -1,6 +1,5 @@
1
1
  import Tablist from './tablist.component';
2
2
  import { TAG_NAME } from './tablist.constants';
3
3
  import '../button';
4
- import '../tab';
5
4
  Tablist.register(TAG_NAME);
6
5
  export default Tablist;
@@ -20,9 +20,7 @@ import { Component } from '../../models';
20
20
  * **Accessibility notes for consuming (have to be explicitly set when you consume the component)**
21
21
  *
22
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`.
23
+ * - The `tablist` element needs to have a label provided by `data-aria-label`.
26
24
  * - Each element with role `tab` has the property `aria-controls`
27
25
  * that should refer to its associated `tabpanel` element.
28
26
  * - Each element with role `tabpanel` has the property `aria-labelledby` referring to its associated `tab` element.
@@ -52,16 +50,8 @@ declare class TabList extends Component {
52
50
  */
53
51
  activeTabId?: string;
54
52
  /**
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.
53
+ * Label for the tablist.
60
54
  * 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
55
  */
66
56
  dataAriaLabel?: string;
67
57
  /**
@@ -120,14 +110,6 @@ declare class TabList extends Component {
120
110
  * @param changedProperties - Map of changed properties with old values.
121
111
  */
122
112
  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
113
  /**
132
114
  * Dispatch the change event.
133
115
  *
@@ -9,6 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  import { html, nothing } from 'lit';
11
11
  import { property, query, queryAssignedElements, state } from 'lit/decorators.js';
12
+ import { ifDefined } from 'lit/directives/if-defined.js';
12
13
  import styles from './tablist.styles';
13
14
  import { Component } from '../../models';
14
15
  import { ARROW_BUTTON_DIRECTION, KEYCODES } from './tablist.constants';
@@ -34,9 +35,7 @@ import { getFirstTab, getLastTab, getNextTab, getPreviousTab, findTab, getActive
34
35
  * **Accessibility notes for consuming (have to be explicitly set when you consume the component)**
35
36
  *
36
37
  * - Each element that contains the `content panel` for a `tab` has role `tabpanel`.
37
- * - If the tab list has a visible label,
38
- * the element with role `tablist` has `aria-labelledby` needs to be a value that refers to the labelling element.
39
- * Otherwise, the `tablist` element needs to have a label provided by `aria-label`.
38
+ * - The `tablist` element needs to have a label provided by `data-aria-label`.
40
39
  * - Each element with role `tab` has the property `aria-controls`
41
40
  * that should refer to its associated `tabpanel` element.
42
41
  * - Each element with role `tabpanel` has the property `aria-labelledby` referring to its associated `tab` element.
@@ -81,24 +80,6 @@ class TabList extends Component {
81
80
  * @internal
82
81
  */
83
82
  this.isRtl = () => { var _a; return ((_a = document.querySelector('html')) === null || _a === void 0 ? void 0 : _a.getAttribute('dir')) === 'rtl' || window.getComputedStyle(this).direction === 'rtl'; };
84
- /**
85
- * Set aria-labelledby attribute on the tablist element.
86
- * If it does not exist, set aria-label attribute.
87
- * As fallback, set aria-label to 'Tab List'.
88
- *
89
- * @internal
90
- */
91
- this.setAriaLabelledByOrAriaLabel = () => {
92
- var _a, _b, _c, _d;
93
- if (this.dataAriaLabelledby) {
94
- (_a = this.tabsContainer) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-labelledby', this.dataAriaLabelledby);
95
- (_b = this.tabsContainer) === null || _b === void 0 ? void 0 : _b.removeAttribute('aria-label');
96
- }
97
- else {
98
- (_c = this.tabsContainer) === null || _c === void 0 ? void 0 : _c.setAttribute('aria-label', this.dataAriaLabel || 'Tab List');
99
- (_d = this.tabsContainer) === null || _d === void 0 ? void 0 : _d.removeAttribute('aria-labelledby');
100
- }
101
- };
102
83
  /**
103
84
  * Dispatch the change event.
104
85
  *
@@ -108,7 +89,7 @@ class TabList extends Component {
108
89
  */
109
90
  this.fireTabChangeEvent = (newTab) => {
110
91
  const event = new CustomEvent('change', {
111
- detail: newTab.tabId,
92
+ detail: { tabId: newTab.tabId },
112
93
  });
113
94
  this.dispatchEvent(event);
114
95
  };
@@ -160,6 +141,7 @@ class TabList extends Component {
160
141
  * @param event - Custom Event fired from the nested tab.
161
142
  */
162
143
  this.handleNestedTabActiveChange = async (event) => {
144
+ event.stopPropagation();
163
145
  const tab = event.target;
164
146
  if (!(tab instanceof Tab)) {
165
147
  return;
@@ -209,11 +191,10 @@ class TabList extends Component {
209
191
  * @param tab - Tab to set focus on.
210
192
  */
211
193
  this.focusTab = async (tab) => {
212
- var _a;
213
194
  if (!(tab instanceof Tab)) {
214
195
  return;
215
196
  }
216
- if (tab !== ((_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.activeElement)) {
197
+ if (tab !== (document === null || document === void 0 ? void 0 : document.activeElement)) {
217
198
  this.resetTabIndexAndSetNewTabIndex(tab);
218
199
  tab.focus();
219
200
  }
@@ -399,10 +380,8 @@ class TabList extends Component {
399
380
  this.onerror('The tabs inside the tab list must have unique tab ids');
400
381
  }
401
382
  }
402
- this.setAriaLabelledByOrAriaLabel();
403
383
  const resizeObserver = new ResizeObserver(async () => {
404
- var _a, _b;
405
- const activeElement = (_b = (_a = this.tabsContainer) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.activeElement;
384
+ const { activeElement } = document;
406
385
  /**
407
386
  * Keep the focused element in view.
408
387
  */
@@ -433,9 +412,6 @@ class TabList extends Component {
433
412
  */
434
413
  async update(changedProperties) {
435
414
  super.update(changedProperties);
436
- if (changedProperties.has('dataAriaLabelledby') || changedProperties.has('dataAriaLabel')) {
437
- this.setAriaLabelledByOrAriaLabel();
438
- }
439
415
  if (changedProperties.has('activeTabId')) {
440
416
  if (!this.tabs || !this.activeTabId) {
441
417
  return;
@@ -446,7 +422,7 @@ class TabList extends Component {
446
422
  }
447
423
  this.setActiveTab(newTab);
448
424
  /**
449
- * If the previous activeTabId was not undefined, fire the change event.
425
+ * If the previous activeTabId was not undefined, focus the new tab.
450
426
  *
451
427
  * Otherwise, reset the tabindex of all tabs and set the new tabindex.
452
428
  */
@@ -475,7 +451,11 @@ class TabList extends Component {
475
451
  ></mdc-button>`
476
452
  : nothing}`;
477
453
  return html ` ${arrowButton('backward')}
478
- <div class="container" role="tablist" tabindex="-1">
454
+ <div
455
+ class="container"
456
+ role="tablist"
457
+ tabindex="-1"
458
+ aria-label="${ifDefined(this.dataAriaLabel)}">
479
459
  <slot></slot>
480
460
  </div>
481
461
  ${arrowButton(ARROW_BUTTON_DIRECTION.FORWARD)}`;
@@ -486,10 +466,6 @@ __decorate([
486
466
  property({ type: String, attribute: 'active-tab-id', reflect: true }),
487
467
  __metadata("design:type", String)
488
468
  ], TabList.prototype, "activeTabId", void 0);
489
- __decorate([
490
- property({ type: String, attribute: 'data-aria-labelledby' }),
491
- __metadata("design:type", String)
492
- ], TabList.prototype, "dataAriaLabelledby", void 0);
493
469
  __decorate([
494
470
  property({ type: String, attribute: 'data-aria-label' }),
495
471
  __metadata("design:type", String)