@scania/tegel 1.26.0 → 1.27.0-toast-aria-live.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.
Files changed (184) hide show
  1. package/dist/cjs/index-ca8040ad.js +4 -4
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/tds-banner.cjs.entry.js +1 -1
  4. package/dist/cjs/tds-checkbox.cjs.entry.js +10 -3
  5. package/dist/cjs/tds-chip.cjs.entry.js +7 -2
  6. package/dist/cjs/tds-dropdown_2.cjs.entry.js +71 -42
  7. package/dist/cjs/tds-folder-tab.cjs.entry.js +21 -2
  8. package/dist/cjs/tds-folder-tabs.cjs.entry.js +4 -2
  9. package/dist/cjs/tds-icon.cjs.entry.js +1 -1
  10. package/dist/cjs/tds-inline-tab.cjs.entry.js +21 -2
  11. package/dist/cjs/tds-inline-tabs.cjs.entry.js +4 -2
  12. package/dist/cjs/tds-link.cjs.entry.js +17 -3
  13. package/dist/cjs/tds-message.cjs.entry.js +15 -3
  14. package/dist/cjs/tds-modal.cjs.entry.js +74 -2
  15. package/dist/cjs/tds-navigation-tab.cjs.entry.js +21 -2
  16. package/dist/cjs/tds-navigation-tabs.cjs.entry.js +6 -4
  17. package/dist/cjs/tds-popover-core.cjs.entry.js +1 -1
  18. package/dist/cjs/tds-text-field.cjs.entry.js +13 -7
  19. package/dist/cjs/tds-textarea.cjs.entry.js +21 -9
  20. package/dist/cjs/tds-toast.cjs.entry.js +11 -4
  21. package/dist/cjs/tds-toggle.cjs.entry.js +2 -2
  22. package/dist/cjs/tds-tooltip.cjs.entry.js +14 -4
  23. package/dist/cjs/tegel.cjs.js +1 -1
  24. package/dist/collection/components/banner/banner.css +1 -1
  25. package/dist/collection/components/banner/banner.js +1 -1
  26. package/dist/collection/components/checkbox/checkbox.js +44 -3
  27. package/dist/collection/components/chip/chip.js +24 -2
  28. package/dist/collection/components/dropdown/dropdown-option/dropdown-option.js +2 -2
  29. package/dist/collection/components/dropdown/dropdown.js +86 -40
  30. package/dist/collection/components/icon/icon.js +1 -1
  31. package/dist/collection/components/icon/iconsArray.js +96 -1
  32. package/dist/collection/components/link/link.js +17 -3
  33. package/dist/collection/components/message/message.css +44 -26
  34. package/dist/collection/components/message/message.js +49 -2
  35. package/dist/collection/components/modal/modal.js +103 -3
  36. package/dist/collection/components/popover-core/tds-popover-core.css +596 -53
  37. package/dist/collection/components/tabs/folder-tabs/folder-tab/folder-tab.js +21 -2
  38. package/dist/collection/components/tabs/folder-tabs/folder-tabs.js +40 -2
  39. package/dist/collection/components/tabs/inline-tabs/inline-tab/inline-tab.js +21 -2
  40. package/dist/collection/components/tabs/inline-tabs/inline-tabs.js +40 -2
  41. package/dist/collection/components/tabs/navigation-tabs/navigation-tab/navigation-tab.js +21 -2
  42. package/dist/collection/components/tabs/navigation-tabs/navigation-tabs.js +42 -4
  43. package/dist/collection/components/text-field/text-field.js +31 -8
  44. package/dist/collection/components/textarea/textarea.css +11 -6
  45. package/dist/collection/components/textarea/textarea.js +38 -8
  46. package/dist/collection/components/toast/toast.css +1 -1
  47. package/dist/collection/components/toast/toast.js +45 -3
  48. package/dist/collection/components/toggle/toggle.js +2 -2
  49. package/dist/collection/components/tooltip/tooltip.js +40 -4
  50. package/dist/collection/utils/axeHelpers.js +1 -1
  51. package/dist/components/{p-c65351ab.js → p-14ab9663.js} +12 -3
  52. package/dist/components/p-17338bcb.js +115 -0
  53. package/dist/components/{p-2a43e410.js → p-2d93a742.js} +5 -5
  54. package/dist/components/p-4487c541.js +65 -0
  55. package/dist/components/{p-29d19dc8.js → p-60ff84f2.js} +1 -1
  56. package/dist/components/{p-a64dc22e.js → p-663b8e51.js} +72 -42
  57. package/dist/components/{p-4c1e3344.js → p-83db8b35.js} +1 -1
  58. package/dist/components/{p-b1d21573.js → p-a1181b1f.js} +1 -1
  59. package/dist/components/p-e71e3b2e.js +2052 -0
  60. package/dist/components/tds-accordion-item.js +1 -1
  61. package/dist/components/tds-banner.js +2 -2
  62. package/dist/components/tds-checkbox.js +1 -1
  63. package/dist/components/tds-chip.js +9 -3
  64. package/dist/components/tds-datetime.js +1 -1
  65. package/dist/components/tds-dropdown-option.js +1 -1
  66. package/dist/components/tds-dropdown.js +1 -1
  67. package/dist/components/tds-folder-tab.js +21 -2
  68. package/dist/components/tds-folder-tabs.js +7 -3
  69. package/dist/components/tds-footer-group.js +1 -1
  70. package/dist/components/tds-header-cell.js +1 -1
  71. package/dist/components/tds-header-dropdown.js +3 -3
  72. package/dist/components/tds-header-hamburger.js +1 -1
  73. package/dist/components/tds-header-launcher-button.js +1 -1
  74. package/dist/components/tds-header-launcher.js +4 -4
  75. package/dist/components/tds-icon.js +1 -1
  76. package/dist/components/tds-inline-tab.js +21 -2
  77. package/dist/components/tds-inline-tabs.js +7 -3
  78. package/dist/components/tds-link.js +17 -3
  79. package/dist/components/tds-message.js +19 -5
  80. package/dist/components/tds-modal.js +78 -4
  81. package/dist/components/tds-navigation-tab.js +21 -2
  82. package/dist/components/tds-navigation-tabs.js +9 -5
  83. package/dist/components/tds-popover-canvas.js +1 -1
  84. package/dist/components/tds-popover-core.js +1 -1
  85. package/dist/components/tds-popover-menu.js +1 -1
  86. package/dist/components/tds-side-menu-close-button.js +1 -1
  87. package/dist/components/tds-side-menu-dropdown.js +1 -1
  88. package/dist/components/tds-slider.js +1 -1
  89. package/dist/components/tds-step.js +1 -1
  90. package/dist/components/tds-table-body-input-wrapper.js +1 -1
  91. package/dist/components/tds-table-body-row.js +1 -1
  92. package/dist/components/tds-table-footer.js +4 -4
  93. package/dist/components/tds-table-header-input-wrapper.js +1 -1
  94. package/dist/components/tds-table-header.js +1 -1
  95. package/dist/components/tds-table-toolbar.js +1 -1
  96. package/dist/components/tds-text-field.js +15 -8
  97. package/dist/components/tds-textarea.js +36 -11
  98. package/dist/components/tds-toast.js +14 -5
  99. package/dist/components/tds-toggle.js +2 -2
  100. package/dist/components/tds-tooltip.js +1 -102
  101. package/dist/esm/index-51d04e39.js +4 -4
  102. package/dist/esm/loader.js +1 -1
  103. package/dist/esm/tds-banner.entry.js +1 -1
  104. package/dist/esm/tds-checkbox.entry.js +10 -3
  105. package/dist/esm/tds-chip.entry.js +7 -2
  106. package/dist/esm/tds-dropdown_2.entry.js +71 -42
  107. package/dist/esm/tds-folder-tab.entry.js +22 -3
  108. package/dist/esm/tds-folder-tabs.entry.js +4 -2
  109. package/dist/esm/tds-icon.entry.js +1 -1
  110. package/dist/esm/tds-inline-tab.entry.js +22 -3
  111. package/dist/esm/tds-inline-tabs.entry.js +4 -2
  112. package/dist/esm/tds-link.entry.js +17 -3
  113. package/dist/esm/tds-message.entry.js +15 -3
  114. package/dist/esm/tds-modal.entry.js +74 -2
  115. package/dist/esm/tds-navigation-tab.entry.js +22 -3
  116. package/dist/esm/tds-navigation-tabs.entry.js +6 -4
  117. package/dist/esm/tds-popover-core.entry.js +1 -1
  118. package/dist/esm/tds-text-field.entry.js +13 -7
  119. package/dist/esm/tds-textarea.entry.js +21 -9
  120. package/dist/esm/tds-toast.entry.js +11 -4
  121. package/dist/esm/tds-toggle.entry.js +2 -2
  122. package/dist/esm/tds-tooltip.entry.js +14 -4
  123. package/dist/esm/tegel.js +1 -1
  124. package/dist/tegel/p-0f2c9507.entry.js +1 -0
  125. package/dist/tegel/p-125a6b06.entry.js +1 -0
  126. package/dist/tegel/p-28517288.entry.js +1 -0
  127. package/dist/tegel/p-2af57972.entry.js +1 -0
  128. package/dist/tegel/{p-be1d1345.entry.js → p-4465f687.entry.js} +1 -1
  129. package/dist/tegel/p-668b7662.entry.js +1 -0
  130. package/dist/tegel/p-746e2927.entry.js +1 -0
  131. package/dist/tegel/p-754a4921.entry.js +1 -0
  132. package/dist/tegel/{p-46205cfb.entry.js → p-769d0503.entry.js} +1 -1
  133. package/dist/tegel/p-843413ba.entry.js +1 -0
  134. package/dist/tegel/p-97f10223.entry.js +1 -0
  135. package/dist/tegel/p-a21250b8.entry.js +1 -0
  136. package/dist/tegel/p-aadb2553.entry.js +1 -0
  137. package/dist/tegel/p-ad9a2141.entry.js +1 -0
  138. package/dist/tegel/p-b08886e3.entry.js +1 -0
  139. package/dist/tegel/p-b114ec3d.entry.js +1 -0
  140. package/dist/tegel/p-c3607f10.entry.js +1 -0
  141. package/dist/tegel/p-ddda64eb.entry.js +1 -0
  142. package/dist/tegel/p-eaa279dd.entry.js +1 -0
  143. package/dist/tegel/p-ee960089.entry.js +1 -0
  144. package/dist/tegel/tegel.css +13 -3
  145. package/dist/tegel/tegel.esm.js +1 -1
  146. package/dist/types/components/checkbox/checkbox.d.ts +5 -0
  147. package/dist/types/components/chip/chip.d.ts +3 -0
  148. package/dist/types/components/dropdown/dropdown.d.ts +5 -0
  149. package/dist/types/components/message/message.d.ts +5 -0
  150. package/dist/types/components/modal/modal.d.ts +6 -0
  151. package/dist/types/components/tabs/folder-tabs/folder-tab/folder-tab.d.ts +2 -0
  152. package/dist/types/components/tabs/folder-tabs/folder-tabs.d.ts +4 -0
  153. package/dist/types/components/tabs/inline-tabs/inline-tab/inline-tab.d.ts +2 -0
  154. package/dist/types/components/tabs/inline-tabs/inline-tabs.d.ts +4 -0
  155. package/dist/types/components/tabs/navigation-tabs/navigation-tab/navigation-tab.d.ts +2 -0
  156. package/dist/types/components/tabs/navigation-tabs/navigation-tabs.d.ts +4 -0
  157. package/dist/types/components/text-field/text-field.d.ts +4 -1
  158. package/dist/types/components/textarea/textarea.d.ts +7 -4
  159. package/dist/types/components/toast/toast.d.ts +5 -0
  160. package/dist/types/components/tooltip/tooltip.d.ts +3 -0
  161. package/dist/types/components.d.ts +146 -2
  162. package/dist/types/types/Icons.d.ts +1 -1
  163. package/dist/types/utils/axeHelpers.d.ts +1 -2
  164. package/package.json +1 -1
  165. package/dist/components/p-4764a1d5.js +0 -2052
  166. package/dist/components/p-a2b7bdef.js +0 -65
  167. package/dist/tegel/p-065d6f83.entry.js +0 -1
  168. package/dist/tegel/p-0c1e632d.entry.js +0 -1
  169. package/dist/tegel/p-168122a7.entry.js +0 -1
  170. package/dist/tegel/p-19eb4ae1.entry.js +0 -1
  171. package/dist/tegel/p-4e298888.entry.js +0 -1
  172. package/dist/tegel/p-4e33cbda.entry.js +0 -1
  173. package/dist/tegel/p-4ee344e5.entry.js +0 -1
  174. package/dist/tegel/p-64c80f14.entry.js +0 -1
  175. package/dist/tegel/p-72fd0083.entry.js +0 -1
  176. package/dist/tegel/p-93a4bd11.entry.js +0 -1
  177. package/dist/tegel/p-9e0b31a1.entry.js +0 -1
  178. package/dist/tegel/p-a0fc0cc2.entry.js +0 -1
  179. package/dist/tegel/p-b35e7208.entry.js +0 -1
  180. package/dist/tegel/p-b6526302.entry.js +0 -1
  181. package/dist/tegel/p-b686f1ad.entry.js +0 -1
  182. package/dist/tegel/p-cca85da0.entry.js +0 -1
  183. package/dist/tegel/p-d0abf078.entry.js +0 -1
  184. package/dist/tegel/p-dcbc35af.entry.js +0 -1
@@ -9,14 +9,28 @@ export class TdsLink {
9
9
  this.standalone = false;
10
10
  }
11
11
  connectedCallback() {
12
- this.host.children[0].classList.add('tds-link-component');
12
+ const links = this.host.querySelectorAll('a');
13
+ if (links.length > 1) {
14
+ console.warn('tds-link is only intended to wrap one <a> tag');
15
+ }
16
+ const link = links[0];
17
+ if (link) {
18
+ if (this.disabled) {
19
+ link.setAttribute('tabindex', '-1');
20
+ link.setAttribute('aria-disabled', 'true');
21
+ }
22
+ else {
23
+ link.removeAttribute('tabindex');
24
+ link.removeAttribute('aria-disabled');
25
+ }
26
+ }
13
27
  }
14
28
  render() {
15
- return (h("span", { key: '3fa509835f66a3128ee487b34b47c0efb9e73d82', class: {
29
+ return (h("span", { key: '1183de952c2fd6cb1193e9e0dec419f37bf07dee', class: {
16
30
  'disabled': this.disabled,
17
31
  'no-underline': !this.underline,
18
32
  'standalone': this.standalone,
19
- } }, h("slot", { key: 'd83160f7b9b04e0e0cd9bd9184a45ac8ac504744' })));
33
+ } }, h("slot", { key: 'e019a83d2335cd0a7d682e79a6bf0148452c3e71' })));
20
34
  }
21
35
  static get is() { return "tds-link"; }
22
36
  static get encapsulation() { return "shadow"; }
@@ -1,3 +1,17 @@
1
+ /* Typography Usage mixins */
2
+ /* Centralized map of typography types */
3
+ /* Utility mixin */
4
+ :host {
5
+ /* Default values */
6
+ --tds-message-background: var(--background-elevation-layer-03);
7
+ /* Variant values */
8
+ }
9
+ :host .tds-mode-variant-primary {
10
+ --tds-message-background: var(--background-elevation-layer-03);
11
+ }
12
+ :host .tds-mode-variant-secondary {
13
+ --tds-message-background: var(--background-elevation-layer-02);
14
+ }
1
15
  :host .wrapper {
2
16
  display: flex;
3
17
  padding: 16px;
@@ -5,43 +19,45 @@
5
19
  border-radius: 4px;
6
20
  }
7
21
  :host .wrapper.information {
8
- border-left: 4px solid var(--tds-information);
22
+ border-left: 4px solid var(--system-info-default);
9
23
  }
10
24
  :host .wrapper.information tds-icon {
11
- color: var(--tds-information);
25
+ color: var(--system-info-default);
12
26
  }
13
27
  :host .wrapper.success {
14
- border-left: 4px solid var(--tds-positive);
28
+ border-left: 4px solid var(--system-success-default);
15
29
  }
16
30
  :host .wrapper.success tds-icon {
17
- color: var(--tds-positive);
31
+ color: var(--system-success-default);
18
32
  }
19
33
  :host .wrapper.error {
20
- background-color: var(--tds-message-type-error-background);
21
- border-left: 4px solid var(--tds-negative);
34
+ background-color: var(--system-danger-subtle);
35
+ border-left: 4px solid var(--system-danger-default);
22
36
  }
23
37
  :host .wrapper.error tds-icon {
24
- color: var(--tds-negative);
38
+ color: var(--system-danger-default);
25
39
  }
26
40
  :host .wrapper.warning {
27
- border-left: 4px solid var(--tds-warning);
41
+ border-left: 4px solid var(--system-warning-default);
28
42
  }
29
43
  :host .wrapper.warning tds-icon {
30
- color: var(--tds-warning);
44
+ color: var(--system-warning-default);
31
45
  }
32
46
  :host .wrapper.minimal {
33
47
  border: none;
34
- display: flex;
35
- align-items: center;
36
48
  padding: 0;
37
49
  background-color: transparent;
38
50
  }
39
51
  :host .wrapper.minimal .header {
40
- font: var(--tds-detail-02);
41
- letter-spacing: var(--tds-detail-02-ls);
52
+ font-family: var(--detail-02-font-family);
53
+ font-size: var(--detail-02-font-size);
54
+ line-height: var(--detail-02-line-height);
55
+ font-weight: var(--detail-02-font-weight);
56
+ letter-spacing: var(--detail-02-letter-spacing);
57
+ text-transform: var(--detail-02-text-transform);
42
58
  }
43
59
  :host .wrapper.minimal.error .header {
44
- color: var(--tds-negative);
60
+ color: var(--system-danger-default);
45
61
  }
46
62
  :host tds-icon {
47
63
  padding-right: 16px;
@@ -50,21 +66,23 @@
50
66
  display: flex;
51
67
  flex-direction: column;
52
68
  gap: 4px;
53
- color: var(--tds-message-color);
69
+ color: var(--foreground-text-strong);
54
70
  padding: 2px 0;
55
71
  }
56
72
  :host .content .header {
57
- font: var(--tds-headline-07);
58
- letter-spacing: var(--tds-headline-07-ls);
73
+ font-family: var(--headline-07-font-family);
74
+ font-size: var(--headline-07-font-size);
75
+ line-height: var(--headline-07-line-height);
76
+ font-weight: var(--headline-07-font-weight);
77
+ letter-spacing: var(--headline-07-letter-spacing);
78
+ text-transform: var(--headline-07-text-transform);
59
79
  }
60
80
  :host .content .extended-message {
61
- color: var(--tds-message-color);
62
- font: var(--tds-detail-02);
63
- letter-spacing: var(--tds-detail-02-ls);
64
- }
65
- :host .tds-mode-variant-primary {
66
- --tds-message-background: var(--tds-message-background-primary);
67
- }
68
- :host .tds-mode-variant-secondary {
69
- --tds-message-background: var(--tds-message-background-secondary);
81
+ color: var(--foreground-text-strong);
82
+ font-family: var(--detail-02-font-family);
83
+ font-size: var(--detail-02-font-size);
84
+ line-height: var(--detail-02-line-height);
85
+ font-weight: var(--detail-02-font-weight);
86
+ letter-spacing: var(--detail-02-letter-spacing);
87
+ text-transform: var(--detail-02-text-transform);
70
88
  }
@@ -1,4 +1,5 @@
1
1
  import { Host, h } from "@stencil/core";
2
+ import generateUniqueId from "../../utils/generateUniqueId";
2
3
  /**
3
4
  * @slot <default> - <b>Unnamed slot.</b> For the extended message. Not visible on minimal messages.
4
5
  */
@@ -23,14 +24,25 @@ export class TdsMessage {
23
24
  this.variant = 'information';
24
25
  this.noIcon = false;
25
26
  this.minimal = false;
27
+ this.tdsAlertDialog = 'dialog';
28
+ this.tdsAriaLabel = undefined;
29
+ }
30
+ getAriaLabel() {
31
+ if (this.header) {
32
+ return undefined;
33
+ }
34
+ const variantLabel = `${this.variant} message`;
35
+ return this.tdsAriaLabel || variantLabel;
26
36
  }
27
37
  render() {
28
- return (h(Host, { key: 'efeee188e97e2562fa55dcd8217277cc69f80010' }, h("div", { key: '9d0f0fb52a4dfeb6912d141f8ee124d45c8ad382', class: {
38
+ const headerId = this.header ? `tds-message-header-${generateUniqueId()}` : undefined;
39
+ const contentId = !this.minimal ? `tds-message-content-${generateUniqueId()}` : undefined;
40
+ return (h(Host, { key: 'b28d7e5de5b3cb612e78f83650fa5c0621107dda', role: this.tdsAlertDialog, "aria-labelledby": headerId, "aria-describedby": contentId, "aria-label": this.getAriaLabel() }, h("div", { key: 'a3d7470a99af752df3516009d39f7e1c4bbed096', class: {
29
41
  wrapper: true,
30
42
  [this.variant]: true,
31
43
  minimal: this.minimal,
32
44
  [`tds-mode-variant-${this.modeVariant}`]: this.modeVariant !== null,
33
- } }, !this.noIcon && h("tds-icon", { key: 'd5fac1d2e80a7082520e5d8286f8cc3b158108fc', name: this.getIconName(), size: "20px" }), h("div", { key: 'e476f032fb5b14f219406f520690ce06b5677096', class: `content` }, this.header && h("div", { key: 'f9e23723c651c0c4ebf0a4da389779f87367739f', class: "header" }, this.header), !this.minimal && (h("div", { key: '3aa181cccd7fecbeea251245c54c53990956b271', class: "extended-message" }, h("slot", { key: 'ba233143933785b13fdeeee0f4154d4ce481dfe6' })))))));
45
+ } }, !this.noIcon && (h("tds-icon", { key: '5ce066cccec225e2707e660f73396f24197d024d', "aria-label": `${this.variant}`, svgTitle: `${this.variant}`, name: this.getIconName(), size: "20px" })), h("div", { key: 'ec0101d39dd0354b163219b732fd9dfa9cd66e60', class: `content` }, this.header && (h("div", { key: '434be3923b805cc8bd77d232a8cdbf847f9793c8', class: "header", id: headerId }, this.header)), !this.minimal && (h("div", { key: '14f5ead963e55d7e3bad6abc69e97ba9f994316f', class: "extended-message", id: contentId }, h("slot", { key: '37c61ef3a396e37a7cb130951d44af9454163699' })))))));
34
46
  }
35
47
  static get is() { return "tds-message"; }
36
48
  static get encapsulation() { return "shadow"; }
@@ -134,6 +146,41 @@ export class TdsMessage {
134
146
  "attribute": "minimal",
135
147
  "reflect": false,
136
148
  "defaultValue": "false"
149
+ },
150
+ "tdsAlertDialog": {
151
+ "type": "string",
152
+ "mutable": false,
153
+ "complexType": {
154
+ "original": "'alertdialog' | 'dialog'",
155
+ "resolved": "\"alertdialog\" | \"dialog\"",
156
+ "references": {}
157
+ },
158
+ "required": false,
159
+ "optional": false,
160
+ "docs": {
161
+ "tags": [],
162
+ "text": "Role of the message component. Can be either 'alertdialog' for important messages that require immediate attention, or 'dialog' for regular messages."
163
+ },
164
+ "attribute": "tds-alert-dialog",
165
+ "reflect": false,
166
+ "defaultValue": "'dialog'"
167
+ },
168
+ "tdsAriaLabel": {
169
+ "type": "string",
170
+ "mutable": false,
171
+ "complexType": {
172
+ "original": "string",
173
+ "resolved": "string",
174
+ "references": {}
175
+ },
176
+ "required": false,
177
+ "optional": false,
178
+ "docs": {
179
+ "tags": [],
180
+ "text": "Provides an accessible name for the message component when no header is present. This ensures proper screen reader support for dialog/alertdialog roles."
181
+ },
182
+ "attribute": "tds-aria-label",
183
+ "reflect": false
137
184
  }
138
185
  };
139
186
  }
@@ -1,5 +1,6 @@
1
1
  import { h, Host, } from "@stencil/core";
2
2
  import hasSlot from "../../utils/hasSlot";
3
+ import generateUniqueId from "../../utils/generateUniqueId";
3
4
  /**
4
5
  * @slot header - Slot for header text
5
6
  * @slot body - Slot for main content of modal
@@ -9,6 +10,7 @@ export class TdsModal {
9
10
  constructor() {
10
11
  this.handleClose = (event) => {
11
12
  const closeEvent = this.tdsClose.emit(event);
13
+ this.returnFocusOnClose();
12
14
  if (!closeEvent.defaultPrevented) {
13
15
  this.isShown = false;
14
16
  }
@@ -57,15 +59,26 @@ export class TdsModal {
57
59
  this.referenceEl = undefined;
58
60
  this.show = undefined;
59
61
  this.closable = true;
62
+ this.tdsAlertDialog = 'dialog';
60
63
  this.isShown = false;
64
+ this.activeElementIndex = 0;
61
65
  }
62
66
  /** Shows the Modal. */
63
67
  async showModal() {
64
68
  this.isShown = true;
69
+ // Set focus on first element when opened
70
+ requestAnimationFrame(() => {
71
+ const focusableElements = this.getFocusableElements();
72
+ if (focusableElements.length > 0) {
73
+ focusableElements[0].focus();
74
+ this.activeElementIndex = 0;
75
+ }
76
+ });
65
77
  }
66
78
  /** Closes the Modal. */
67
79
  async closeModal() {
68
80
  this.isShown = false;
81
+ this.returnFocusOnClose();
69
82
  }
70
83
  connectedCallback() {
71
84
  if (this.closable === undefined) {
@@ -103,6 +116,63 @@ export class TdsModal {
103
116
  dismissButton.removeEventListener('click', this.handleClose);
104
117
  });
105
118
  }
119
+ returnFocusOnClose() {
120
+ var _a;
121
+ let referenceEl = (_a = this.referenceEl) !== null && _a !== void 0 ? _a : document.querySelector(this.selector);
122
+ const potentialReferenceElements = ['BUTTON', 'A', 'INPUT'];
123
+ // If referenced element is a custom element eg: tds-button we find the interactive element inside
124
+ if (potentialReferenceElements.indexOf(referenceEl.tagName) < 0) {
125
+ referenceEl = referenceEl.querySelectorAll(potentialReferenceElements.join(','))[0];
126
+ }
127
+ referenceEl.focus();
128
+ }
129
+ getFocusableElements() {
130
+ const focusableSelectors = [
131
+ 'a[href]',
132
+ 'button:not([disabled])',
133
+ 'textarea:not([disabled])',
134
+ 'input:not([disabled])',
135
+ 'select:not([disabled])',
136
+ '[tabindex]:not([tabindex="-1"])',
137
+ ].join(',');
138
+ const focusableInShadowRoot = Array.from(this.host.shadowRoot.querySelectorAll(focusableSelectors));
139
+ const focusableInSlots = Array.from(this.host.querySelectorAll(focusableSelectors));
140
+ /** Focusable elements */
141
+ return [...focusableInShadowRoot, ...focusableInSlots];
142
+ }
143
+ handleFocusTrap(event) {
144
+ if (event.key === 'Escape' && this.isShown && !this.prevent) {
145
+ this.handleClose(event);
146
+ return;
147
+ }
148
+ // Only trap focus if the modal is open
149
+ if (!this.isShown)
150
+ return;
151
+ // We care only about the Tab key
152
+ if (event.key !== 'Tab')
153
+ return;
154
+ const focusableElements = this.getFocusableElements();
155
+ // If there are no focusable elements
156
+ if (focusableElements.length === 0)
157
+ return;
158
+ event.preventDefault();
159
+ // Going backwards (Shift + Tab) on the first element => move to last
160
+ if (event.shiftKey) {
161
+ this.activeElementIndex -= 1;
162
+ if (this.activeElementIndex === -1) {
163
+ this.activeElementIndex = focusableElements.length - 1;
164
+ }
165
+ }
166
+ // // Going forwards (Tab) on the last element => move to first
167
+ if (!event.shiftKey) {
168
+ this.activeElementIndex += 1;
169
+ if (this.activeElementIndex === focusableElements.length) {
170
+ this.activeElementIndex = 0;
171
+ }
172
+ }
173
+ const nextElement = focusableElements[this.activeElementIndex];
174
+ nextElement.focus();
175
+ }
106
176
  /** Adds an event listener to the dismiss buttons that closes the Modal. */
107
177
  setDismissButtons() {
108
178
  this.host.querySelectorAll('[data-dismiss-modal]').forEach((dismissButton) => {
@@ -112,10 +182,12 @@ export class TdsModal {
112
182
  render() {
113
183
  const usesHeaderSlot = hasSlot('header', this.host);
114
184
  const usesActionsSlot = hasSlot('actions', this.host);
115
- return (h(Host, { key: '3b815395be0ccab91eebda3ca785528de624d17e', class: {
185
+ const headerId = this.header ? `tds-modal-header-${generateUniqueId()}` : undefined;
186
+ const bodyId = `tds-modal-body-${generateUniqueId()}`;
187
+ return (h(Host, { key: '398809ea45126dd70b95422f2f7a08a481a22d53', role: this.tdsAlertDialog, "aria-modal": "true", "aria-describedby": bodyId, "aria-labelledby": headerId, class: {
116
188
  show: this.isShown,
117
189
  hide: !this.isShown,
118
- }, onClick: (event) => this.handleOverlayClick(event) }, h("div", { key: '84c9952f862e5defe06c04040e7031e08c5caca3', class: "tds-modal-backdrop" }), h("div", { key: '42b3ea985203a582b3a3dee5250b4a4468a23d6f', class: `tds-modal tds-modal__actions-${this.actionsPosition} tds-modal-${this.size}` }, h("div", { key: '06e005618aeab759c01f7d556cc4357f0aed0e1d', class: "header" }, this.header && h("div", { key: 'bff8080a479c4ecef96eae35dc0f33cc3fadaa8c', class: "header-text" }, this.header), usesHeaderSlot && h("slot", { key: 'dbec4b999fcda87c5c751a8cf3eb7b9f66e1ec43', name: "header" }), this.closable && (h("button", { key: 'bfbfe0d3419aa5e2a5fcbab7691560ed5619dd05', class: "tds-modal-close", "aria-label": "close", onClick: (event) => this.handleClose(event) }, h("tds-icon", { key: '3bcd38d4234a689acd63bb82e21b270c2b0825f9', name: "cross", size: "20px" })))), h("div", { key: '2fc5756d3261dfa354ce3025dc9d8ff213c49ba1', class: "body" }, h("slot", { key: '389ac6e307873c9de7c36c0960ce578cdfaf88e4', name: "body" })), usesActionsSlot && h("slot", { key: 'c964f9d3999f26995543187c553adcc9ac392f2a', name: "actions" }))));
190
+ }, onClick: (event) => this.handleOverlayClick(event) }, h("div", { key: '96e964cc4f3c6d9613fb53e340e0aa5dcd8b6d81', class: "tds-modal-backdrop" }), h("div", { key: 'af7ddc896ef35b6116ae70524d10c4b7b952e20a', class: `tds-modal tds-modal__actions-${this.actionsPosition} tds-modal-${this.size}` }, h("div", { key: '9dfcf95fcc8925cd5c97f10f29edc6cef183a0ca', id: headerId, class: "header" }, this.header && h("div", { key: '42533c25b07e696a0c61504556150018f8d3583a', class: "header-text" }, this.header), usesHeaderSlot && h("slot", { key: 'd9855a20e1763ad17d6c8b80df85796d8f6027a8', name: "header" }), this.closable && (h("button", { key: '3e99b76da7bcf39eaecbe2906e0674fd20ebe9a6', class: "tds-modal-close", "aria-label": "close", onClick: (event) => this.handleClose(event) }, h("tds-icon", { key: 'f6463437fb98ae280afe358d50a2f960914014ea', name: "cross", size: "20px" })))), h("div", { key: 'ba8ca2e65f5eac8103e6f3c431e3ae9aab2b5f72', id: bodyId, class: "body" }, h("slot", { key: '9e08cbdd00e1a60826588b15cb6ed23fc4b5b0d7', name: "body" })), usesActionsSlot && h("slot", { key: 'aeb50dfcbf6c12e80a8904d149bb15892c691d88', name: "actions" }))));
119
191
  }
120
192
  static get is() { return "tds-modal"; }
121
193
  static get encapsulation() { return "shadow"; }
@@ -273,12 +345,31 @@ export class TdsModal {
273
345
  "attribute": "closable",
274
346
  "reflect": false,
275
347
  "defaultValue": "true"
348
+ },
349
+ "tdsAlertDialog": {
350
+ "type": "string",
351
+ "mutable": false,
352
+ "complexType": {
353
+ "original": "'alertdialog' | 'dialog'",
354
+ "resolved": "\"alertdialog\" | \"dialog\"",
355
+ "references": {}
356
+ },
357
+ "required": false,
358
+ "optional": false,
359
+ "docs": {
360
+ "tags": [],
361
+ "text": "Role of the modal component. Can be either 'alertdialog' for important messages that require immediate attention, or 'dialog' for regular messages."
362
+ },
363
+ "attribute": "tds-alert-dialog",
364
+ "reflect": false,
365
+ "defaultValue": "'dialog'"
276
366
  }
277
367
  };
278
368
  }
279
369
  static get states() {
280
370
  return {
281
- "isShown": {}
371
+ "isShown": {},
372
+ "activeElementIndex": {}
282
373
  };
283
374
  }
284
375
  static get events() {
@@ -372,4 +463,13 @@ export class TdsModal {
372
463
  };
373
464
  }
374
465
  static get elementRef() { return "host"; }
466
+ static get listeners() {
467
+ return [{
468
+ "name": "keydown",
469
+ "method": "handleFocusTrap",
470
+ "target": "window",
471
+ "capture": true,
472
+ "passive": false
473
+ }];
474
+ }
375
475
  }