desy-html 8.6.0 → 8.8.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 (37) hide show
  1. package/docs/_macro.show-code-from-file.njk +3 -3
  2. package/docs/_macro.show-html-from-file.njk +3 -2
  3. package/docs/ds/_ds.example.layout-escritorio.njk +12 -12
  4. package/docs/ds/_ds.example.layout-movil.njk +4 -4
  5. package/docs/ds/_ds.example.layout-sidebar.njk +1 -1
  6. package/docs/ds/_ds.example.typography.njk +1 -1
  7. package/docs/ds/_ds.macro.code-snippet.njk +1 -1
  8. package/docs/ds/_ds.macro.section-title.njk +1 -1
  9. package/docs/ds/_ds.macro.subsection-title.njk +1 -1
  10. package/docs/ds/_ds.section.espaciado.njk +154 -16
  11. package/docs/ds/_ds.section.textos.njk +216 -142
  12. package/docs/index.html +13 -0
  13. package/package.json +1 -1
  14. package/src/js/aria/MenuHorizontal.js +58 -0
  15. package/src/js/aria/MenubarAction.js +210 -164
  16. package/src/js/aria/accordion.js +46 -2
  17. package/src/js/aria/listbox.js +68 -7
  18. package/src/js/aria/tabs.js +11 -9
  19. package/src/js/desy-html.js +47 -12
  20. package/src/js/index.js +2 -0
  21. package/src/templates/components/accordion/_examples.accordion.njk +10 -4
  22. package/src/templates/components/accordion/_template.accordion.njk +2 -1
  23. package/src/templates/components/accordion-history/_examples.accordion-history.njk +11 -5
  24. package/src/templates/components/accordion-history/_template.accordion-history.njk +2 -1
  25. package/src/templates/components/header/_template.header.header__offcanvas.njk +1 -0
  26. package/src/templates/components/header/_template.header.header__offcanvasButton.njk +1 -0
  27. package/src/templates/components/listbox/_examples.listbox.njk +11 -4
  28. package/src/templates/components/listbox/_template.listbox.njk +2 -2
  29. package/src/templates/components/menu-horizontal/_examples.menu-horizontal.njk +5 -3
  30. package/src/templates/components/menu-horizontal/_template.menu-horizontal.njk +2 -2
  31. package/src/templates/components/menubar/_examples.menubar.njk +156 -3
  32. package/src/templates/components/menubar/_template.menubar.njk +2 -2
  33. package/src/templates/components/modal/_template.modal.njk +1 -1
  34. package/src/templates/components/notification/_template.notification.njk +1 -1
  35. package/src/templates/components/pagination/_template.pagination.njk +12 -6
  36. package/src/templates/components/tabs/_examples.tabs.njk +4 -1
  37. package/src/templates/pages/_template.with-header-advanced.njk +218 -37
@@ -19,192 +19,238 @@ export function MenubarAction(aria) {
19
19
  * Each child element of domNode that represents a menubaritem
20
20
  * must be an A element.
21
21
  */
22
- aria.MenubarAction = function (domNode) {
23
- var msgPrefix = 'Menubar constructor argument domNode ';
22
+ (function () {
23
+ aria.MenubarAction = function (domNode) {
24
+ var msgPrefix = 'Menubar constructor argument domNode ';
24
25
 
25
- // Check whether domNode is a DOM element
26
- if (!domNode instanceof Element) {
27
- throw new TypeError(msgPrefix + 'is not a DOM Element.');
28
- }
26
+ // Check whether domNode is a DOM element
27
+ if (!domNode instanceof Element) {
28
+ throw new TypeError(msgPrefix + 'is not a DOM Element.');
29
+ }
29
30
 
30
- // Check whether domNode has descendant elements
31
- if (domNode.childElementCount === 0) {
32
- throw new Error(msgPrefix + 'has no element children.');
33
- }
31
+ // Check whether domNode has descendant elements
32
+ if (domNode.childElementCount === 0) {
33
+ throw new Error(msgPrefix + 'has no element children.');
34
+ }
34
35
 
35
- // Check whether domNode's descendant elements contain A elements
36
- var e = domNode.firstElementChild;
37
- while (e) {
38
- var menubarItem = e.firstElementChild;
39
- if (menubarItem && menubarItem.tagName !== 'A') {
40
- throw new Error(msgPrefix + 'has child elements that are not A elements.');
36
+ // Check whether domNode's descendant elements contain A elements
37
+ var e = domNode.firstElementChild;
38
+ while (e) {
39
+ e = e.nextElementSibling;
41
40
  }
42
- e = e.nextElementSibling;
43
- }
44
41
 
45
- this.domNode = domNode;
42
+ this.domNode = domNode;
46
43
 
47
- this.menubarItems = []; // see Menubar init method
48
- this.firstChars = []; // see Menubar init method
44
+ this.menubarItems = []; // see Menubar init method
45
+ this.firstChars = []; // see Menubar init method
49
46
 
50
- this.firstItem = null; // see Menubar init method
51
- this.lastItem = null; // see Menubar init method
52
- };
47
+ this.firstItem = null; // see Menubar init method
48
+ this.lastItem = null; // see Menubar init method
49
+ };
53
50
 
54
- /*
55
- * @method MenubarAction.prototype.init
56
- *
57
- * @desc
58
- * Adds ARIA role to the menubar node
59
- * Traverse menubar children for A elements to configure each A element as an ARIA menuitem
60
- * and populate menuitems array. Initialize firstItem and lastItem properties.
61
- */
62
- aria.MenubarAction.prototype.init = function (actionManager) {
63
- var menubarItem, menuElement, textContent, numItems;
51
+ /*
52
+ * @method MenubarAction.prototype.init
53
+ *
54
+ * @desc
55
+ * Adds ARIA role to the menubar node
56
+ * Traverse menubar children for A elements to configure each A element as an ARIA menuitem
57
+ * and populate menuitems array. Initialize firstItem and lastItem properties.
58
+ */
59
+ aria.MenubarAction.prototype.init = function (actionManager) {
60
+ var menubarItem, menuElement, textContent, numItems;
64
61
 
65
- this.actionManager = actionManager;
62
+ this.actionManager = actionManager;
66
63
 
67
- this.domNode.setAttribute('role', 'menubar');
64
+ this.domNode.setAttribute('role', 'menubar');
68
65
 
69
- this.domNode.addEventListener('focusin', this.handleFocusin.bind(this));
70
- this.domNode.addEventListener('focusout', this.handleFocusout.bind(this));
66
+ this.domNode.addEventListener('focusin', this.handleFocusin.bind(this));
67
+ this.domNode.addEventListener('focusout', this.handleFocusout.bind(this));
71
68
 
72
- // Traverse the element children of the menubar domNode: configure each with
73
- // menuitem role behavior and store reference in menuitems array.
74
- var e = this.domNode.firstElementChild;
69
+ // Traverse the element children of the menubar domNode: configure each with
70
+ // menuitem role behavior and store reference in menuitems array.
71
+ var e = this.domNode.firstElementChild;
75
72
 
76
- while (e) {
77
- menuElement = e.firstElementChild;
73
+ while (e) {
74
+ menuElement = e.firstElementChild;
78
75
 
79
- if (menuElement && menuElement.tagName === 'A') {
80
- menubarItem = new aria.MenubarItemAction(menuElement, this);
81
- menubarItem.init();
82
- this.menubarItems.push(menubarItem);
83
- textContent = menuElement.textContent.trim();
84
- this.firstChars.push(textContent.substring(0, 1).toLowerCase());
85
- }
76
+ if (menuElement && menuElement.tagName === 'A') {
77
+ menubarItem = new aria.MenubarItemAction(menuElement, this);
78
+ menubarItem.init();
79
+ this.menubarItems.push(menubarItem);
80
+ textContent = menuElement.textContent.trim();
81
+ this.firstChars.push(textContent.substring(0, 1).toLowerCase());
82
+ }
86
83
 
87
- e = e.nextElementSibling;
88
- }
84
+ e = e.nextElementSibling;
85
+ }
89
86
 
90
- // Use populated menuitems array to initialize firstItem and lastItem.
91
- numItems = this.menubarItems.length;
92
- if (numItems > 0) {
93
- this.firstItem = this.menubarItems[0];
94
- this.lastItem = this.menubarItems[numItems - 1];
95
- }
96
- this.firstItem.domNode.tabIndex = 0;
97
- };
87
+ // Use populated menuitems array to initialize firstItem and lastItem.
88
+ numItems = this.menubarItems.length;
89
+ if (numItems > 0) {
90
+ this.firstItem = this.menubarItems[0];
91
+ this.lastItem = this.menubarItems[numItems - 1];
92
+ }
93
+ this.firstItem.domNode.tabIndex = 0;
94
+ };
98
95
 
99
- /* FOCUS MANAGEMENT METHODS */
96
+ /* FOCUS MANAGEMENT METHODS */
100
97
 
101
- aria.MenubarAction.prototype.setFocusToItem = function (newItem, hover) {
102
- var isOpen = false;
103
- var hasFocus = this.domNode.contains(document.activeElement);
104
- for (var i = 0; i < this.menubarItems.length; i++) {
105
- var mbi = this.menubarItems[i];
106
- isOpen = isOpen || (mbi.popupMenu && mbi.popupMenu.isOpen());
107
- if (!hover || hasFocus) {
108
- mbi.domNode.tabIndex = -1;
109
- }
110
- if (mbi.popupMenu) {
111
- mbi.popupMenu.close();
112
- }
113
- }
114
- if (!hover || hasFocus) {
115
- newItem.domNode.focus();
116
- newItem.domNode.tabIndex = 0;
117
- }
118
- if (isOpen && newItem.popupMenu) {
119
- newItem.popupMenu.open();
120
- }
121
- };
122
-
123
- aria.MenubarAction.prototype.setFocusToFirstItem = function () {
124
- this.setFocusToItem(this.firstItem);
125
- };
126
- aria.MenubarAction.prototype.setFocusToLastItem = function () {
127
- this.setFocusToItem(this.lastItem);
128
- };
129
-
130
- aria.MenubarAction.prototype.setFocusToPreviousItem = function (currentItem) {
131
- var newItem, index;
132
-
133
- if (currentItem === this.firstItem) {
134
- newItem = this.lastItem;
135
- }
136
- else {
137
- index = this.menubarItems.indexOf(currentItem);
138
- newItem = this.menubarItems[ index - 1 ];
139
- }
140
-
141
- this.setFocusToItem(newItem);
142
- };
143
-
144
- aria.MenubarAction.prototype.setFocusToNextItem = function (currentItem) {
145
- var newItem, index;
146
-
147
- if (currentItem === this.lastItem) {
148
- newItem = this.firstItem;
149
- }
150
- else {
151
- index = this.menubarItems.indexOf(currentItem);
152
- newItem = this.menubarItems[ index + 1 ];
153
- }
154
- this.setFocusToItem(newItem);
155
- };
156
-
157
- aria.MenubarAction.prototype.setFocusByFirstCharacter = function (currentItem, char) {
158
- var start, index, char = char.toLowerCase();
159
-
160
- // Get start index for search based on position of currentItem
161
- start = this.menubarItems.indexOf(currentItem) + 1;
162
- if (start === this.menubarItems.length) {
163
- start = 0;
164
- }
165
-
166
- // Check remaining slots in the menu
167
- index = this.getIndexFirstChars(start, char);
168
-
169
- // If not found in remaining slots, check from beginning
170
- if (index === -1) {
171
- index = this.getIndexFirstChars(0, char);
172
- }
173
-
174
- // If match was found...
175
- if (index > -1) {
176
- this.menubarItems[index].domNode.focus();
177
- this.menubarItems[index].domNode.tabIndex = 0;
178
- currentItem.tabIndex = -1;
179
- }
180
- };
181
-
182
- aria.MenubarAction.prototype.getIndexFirstChars = function (startIndex, char) {
183
- for (var i = startIndex; i < this.firstChars.length; i++) {
184
- if (char === this.firstChars[i]) {
185
- return i;
186
- }
187
- }
188
- return -1;
189
- };
190
-
191
- aria.MenubarAction.prototype.handleFocusin = function (event) {
192
- // if the menubar or any of its menus has focus, add styling hook for hover
193
- this.domNode.classList.add('focus');
194
- };
195
-
196
- aria.MenubarAction.prototype.handleFocusout = function (event) {
197
- // if the next element to get focus is not in the menubar or its menus, then close menu
198
- if (!this.domNode.contains(event.relatedTarget)) {
98
+ aria.MenubarAction.prototype.setFocusToItem = function (newItem, hover) {
99
+ var isOpen = false;
100
+ var hasFocus = this.domNode.contains(document.activeElement);
199
101
  for (var i = 0; i < this.menubarItems.length; i++) {
200
102
  var mbi = this.menubarItems[i];
201
- if (mbi.popupMenu && mbi.popupMenu.isOpen()) {
103
+ isOpen = isOpen || (mbi.popupMenu && mbi.popupMenu.isOpen());
104
+ if (!hover || hasFocus) {
105
+ mbi.domNode.tabIndex = -1;
106
+ }
107
+ if (mbi.popupMenu) {
202
108
  mbi.popupMenu.close();
203
109
  }
204
110
  }
205
- }
206
- // remove styling hook for hover on menubar item
207
- this.domNode.classList.remove('focus');
208
- };
111
+ if (!hover || hasFocus) {
112
+ newItem.domNode.focus();
113
+ newItem.domNode.tabIndex = 0;
114
+ }
115
+ if (isOpen && newItem.popupMenu) {
116
+ newItem.popupMenu.open();
117
+ }
118
+ };
119
+
120
+ aria.MenubarAction.prototype.setFocusToFirstItem = function () {
121
+ this.setFocusToItem(this.firstItem);
122
+ };
123
+ aria.MenubarAction.prototype.setFocusToLastItem = function () {
124
+ this.setFocusToItem(this.lastItem);
125
+ };
126
+
127
+ aria.MenubarAction.prototype.setFocusToPreviousItem = function (currentItem) {
128
+ var newItem, index;
129
+
130
+ if (currentItem === this.firstItem) {
131
+ newItem = this.lastItem;
132
+ }
133
+ else {
134
+ index = this.menubarItems.indexOf(currentItem);
135
+ newItem = this.menubarItems[ index - 1 ];
136
+ }
137
+
138
+ this.setFocusToItem(newItem);
139
+ };
140
+
141
+ aria.MenubarAction.prototype.setFocusToNextItem = function (currentItem) {
142
+ var newItem, index;
143
+
144
+ if (currentItem === this.lastItem) {
145
+ newItem = this.firstItem;
146
+ }
147
+ else {
148
+ index = this.menubarItems.indexOf(currentItem);
149
+ newItem = this.menubarItems[ index + 1 ];
150
+ }
151
+ this.setFocusToItem(newItem);
152
+ };
153
+
154
+ aria.MenubarAction.prototype.setFocusByFirstCharacter = function (currentItem, char) {
155
+ var start, index, char = char.toLowerCase();
156
+
157
+ // Get start index for search based on position of currentItem
158
+ start = this.menubarItems.indexOf(currentItem) + 1;
159
+ if (start === this.menubarItems.length) {
160
+ start = 0;
161
+ }
162
+
163
+ // Check remaining slots in the menu
164
+ index = this.getIndexFirstChars(start, char);
165
+
166
+ // If not found in remaining slots, check from beginning
167
+ if (index === -1) {
168
+ index = this.getIndexFirstChars(0, char);
169
+ }
170
+
171
+ // If match was found...
172
+ if (index > -1) {
173
+ this.menubarItems[index].domNode.focus();
174
+ this.menubarItems[index].domNode.tabIndex = 0;
175
+ currentItem.tabIndex = -1;
176
+ }
177
+ };
178
+
179
+ aria.MenubarAction.prototype.getIndexFirstChars = function (startIndex, char) {
180
+ for (var i = startIndex; i < this.firstChars.length; i++) {
181
+ if (char === this.firstChars[i]) {
182
+ return i;
183
+ }
184
+ }
185
+ return -1;
186
+ };
187
+
188
+ aria.MenubarAction.prototype.handleFocusin = function (event) {
189
+ // if the menubar or any of its menus has focus, add styling hook for hover
190
+ this.domNode.classList.add('focus');
191
+ };
192
+
193
+ aria.MenubarAction.prototype.handleFocusout = function (event) {
194
+ // if the next element to get focus is not in the menubar or its menus, then close menu
195
+ if (!this.domNode.contains(event.relatedTarget)) {
196
+ for (var i = 0; i < this.menubarItems.length; i++) {
197
+ var mbi = this.menubarItems[i];
198
+ if (mbi.popupMenu && mbi.popupMenu.isOpen()) {
199
+ mbi.popupMenu.close();
200
+ }
201
+ }
202
+ }
203
+ // remove styling hook for hover on menubar item
204
+ this.domNode.classList.remove('focus');
205
+ };
206
+
207
+ window.activateItemMenuBarAction = function (menuId, itemsIds) {
208
+ const menu = document.getElementById(menuId);
209
+ if (menu) {
210
+ const menuInstance = new aria.MenubarAction(menu);
211
+ menuInstance.activateElements(menuId, itemsIds);
212
+ return [menu, itemsIds];
213
+ } else {
214
+ console.log('There is no menu with this id in the document.');
215
+ return null;
216
+ }
217
+ };
218
+
219
+ aria.MenubarAction.prototype.activateElements = function (menuId, activateElements) {
220
+ const getAllElements = this.domNode.querySelectorAll(`#${menuId} ul > li `);
221
+ const filterElements = [...getAllElements].filter((element) => element.id !== '' && element.getAttribute('role') !== 'separator');
222
+ [...filterElements].forEach((element) => {
223
+ if(isActive(element)) {
224
+ element.setAttribute('aria-checked', 'true');
225
+ element.innerHTML = `<strong class="font-bold">${element.textContent}</strong>`;
226
+ } else {
227
+ const getElementParent = element.parentElement.getAttribute('role') === 'group'
228
+ ? element.parentElement.parentElement.parentElement.parentElement.querySelector('a')
229
+ : element.parentElement.parentElement.querySelector('a');
230
+
231
+ getElementParent.classList.remove('c-menubar__button--has-selection');
232
+ getElementParent.firstChild.innerHTML = `${getElementParent.textContent}`;
233
+ element.setAttribute('aria-checked', 'false');
234
+ element.innerHTML = `${element.textContent}`;
235
+ }
236
+ });
237
+ [...filterElements].forEach((element) => {
238
+ if(element.getAttribute("aria-checked") === "true"){
239
+ const getElementParent = element.parentElement.getAttribute('role') === 'group'
240
+ ? element.parentElement.parentElement.parentElement.parentElement.querySelector('a')
241
+ : element.parentElement.parentElement.querySelector('a');
242
+ getElementParent.classList.add('c-menubar__button--has-selection');
243
+ getElementParent.firstChild.innerHTML = `<strong class="font-bold">${getElementParent.textContent}</strong>`;
244
+ }
245
+ });
246
+
247
+ function isActive(element){
248
+ const { id } = element;
249
+ return typeof activateElements === "string"
250
+ ? id === activateElements
251
+ : activateElements.includes(id);
252
+ }
253
+ };
254
+ }());
209
255
  }
210
256
 
@@ -92,7 +92,6 @@ export function accordion(aria) {
92
92
  // If toggling is not allowed, set disabled state on trigger
93
93
  if (!allowToggle) {
94
94
  target.setAttribute('aria-disabled', 'true');
95
- //target.querySelector('span').innerText = '';
96
95
  target.querySelector('.c-accordion__show').classList.add('hidden');
97
96
  target.querySelector('.c-accordion__hide').classList.add('hidden');
98
97
  }
@@ -178,11 +177,56 @@ export function accordion(aria) {
178
177
  // If an expanded/ active accordion is found, disable
179
178
  if (expanded) {
180
179
  expanded.setAttribute('aria-disabled', 'true');
181
- //expanded.querySelector('span').innerText = '';
182
180
  expanded.querySelector('.c-accordion__show').classList.add('hidden');
183
181
  expanded.querySelector('.c-accordion__hide').classList.add('hidden');
184
182
  }
185
183
  }
186
184
 
185
+ window.activateItemAccordion = function (menuId, activeItemId) {
186
+ const menu = document.getElementById(menuId);
187
+ if (menu) {
188
+ const activeItem = document.querySelector(`#${menuId} #${activeItemId}`);
189
+ if (activeItem) {
190
+ activateElement(menuId, activeItemId);
191
+ return [menu, activeItem]
192
+ } else {
193
+ console.log('There is no element with this id in the menu.');
194
+ return null;
195
+ }
196
+ } else {
197
+ console.log('There is no menu with this id in the document.');
198
+ return null;
199
+ }
200
+ };
201
+
202
+ function activateElement(menu, activeItem) {
203
+ const getAccordion = document.querySelector(`#${menu}`);
204
+ const allowMultiple = getAccordion.hasAttribute('data-allow-multiple');
205
+ const allowToggle = (allowMultiple) ? allowMultiple : accordion.hasAttribute('data-allow-toggle');
206
+ const selectAllTriggers = document.querySelectorAll(`#${menu} .c-accordion__trigger`);
207
+ [...selectAllTriggers].forEach((trigger) => {
208
+ const getPanel = trigger.parentElement.parentElement.querySelector('.c-accordion__panel');
209
+ const getShowMessage = trigger.querySelector('.c-accordion__show');
210
+ const getHideMessage = trigger.querySelector('.c-accordion__hide');
211
+ if (isActive(trigger)) {
212
+ trigger.setAttribute('aria-expanded', 'true');
213
+ getPanel.removeAttribute('hidden');
214
+ getShowMessage.classList.add('hidden');
215
+ getHideMessage.classList.remove('hidden');
216
+ } else {
217
+ trigger.setAttribute('aria-expanded', 'false');
218
+ getPanel.setAttribute('hidden', 'true');
219
+ getShowMessage.classList.remove('hidden');
220
+ getHideMessage.classList.add('hidden');
221
+ }
222
+ });
223
+
224
+ function isActive(element){
225
+ const { id } = element;
226
+ return typeof activeItem === "object" && allowToggle
227
+ ? activeItem.includes(id)
228
+ : id === activeItem;
229
+ }
230
+ }
187
231
  });
188
232
  }
@@ -279,10 +279,6 @@ export function listbox(aria) {
279
279
  'aria-selected',
280
280
  element.getAttribute('aria-selected') === 'true' ? 'false' : 'true'
281
281
  );
282
- element.setAttribute(
283
- 'aria-checked',
284
- element.getAttribute('aria-checked') === 'true' ? 'false' : 'true'
285
- );
286
282
 
287
283
  if (this.moveButton) {
288
284
  if (this.listboxNode.querySelector('[aria-selected="true"]')) {
@@ -308,7 +304,6 @@ export function listbox(aria) {
308
304
  }
309
305
  if (!this.multiselectable) {
310
306
  element.removeAttribute('aria-selected');
311
- element.removeAttribute('aria-checked');
312
307
  }
313
308
  aria.Utils.removeClass(element, 'focused');
314
309
  };
@@ -324,7 +319,6 @@ export function listbox(aria) {
324
319
  this.defocusItem(document.getElementById(this.activeDescendant));
325
320
  if (!this.multiselectable) {
326
321
  element.setAttribute('aria-selected', 'true');
327
- element.setAttribute('aria-checked', 'true');
328
322
  }
329
323
  aria.Utils.addClass(element, 'focused');
330
324
  this.listboxNode.setAttribute('aria-activedescendant', element.id);
@@ -559,5 +553,72 @@ export function listbox(aria) {
559
553
  this.handleFocusChange = focusChangeHandler;
560
554
  };
561
555
 
556
+ function activateElement(menuId, activeItem) {
557
+ const getListBox = document.querySelector(`#${menuId}`);
558
+ const getTippy = document.querySelector(`#${menuId} [data-tippy-root]`);
559
+ const getTippyBox = document.querySelector(`#${menuId} .tippy-box`);
560
+ const getListBoxUl = document.querySelector(`#${menuId} [data-module="c-listbox-list"]`);
561
+ const getListBoxButton = document.querySelector(`#${menuId} .c-listbox`);
562
+ const getListBoxButtonText = document.querySelector(`#${menuId} .c-listbox span`);
563
+ const getMultiSelectable = getListBoxButton.getAttribute('aria-labelledby');
564
+ const allowMultiple = getMultiSelectable.includes('is-multiselectable-label');
565
+ const selectAllElements = document.querySelectorAll(`#${menuId} li`);
566
+
567
+ getListBoxButton.click();
568
+ getTippy.style.visibility = 'visible';
569
+ getTippyBox.setAttribute('data-state','visible');
570
+ getListBoxButton._tippy.popper._tippy.show();
571
+ getListBoxUl.focus();
572
+
573
+ [...selectAllElements].forEach((element) => {
574
+ if (isActive(element, activeItem)) {
575
+ element.setAttribute('aria-selected', 'true');
576
+ if(!allowMultiple && getListBoxButton.dataset.change){
577
+ getListBoxButtonText.innerHTML = element.textContent;
578
+ }
579
+ } else {
580
+ element.setAttribute('aria-selected', 'false');
581
+ }
582
+ });
583
+
584
+ getTippy.style.visibility = 'hidden';
585
+ getTippyBox.setAttribute('data-state','hidden');
586
+
587
+ getListBoxUl.dispatchEvent(new KeyboardEvent("keydown", {
588
+ key: "Escape",
589
+ keyCode: 27,
590
+ code: "Escape",
591
+ which: 27
592
+ }));
593
+
594
+ getListBoxButton._tippy.popper._tippy.hide();
595
+ getListBoxButton.classList.remove('open');
596
+
597
+ function isActive(element, activeItem) {
598
+ const { id } = element;
599
+ return typeof activeItem === "object" && allowMultiple
600
+ ? activeItem.includes(id)
601
+ : id === activeItem;
602
+ }
603
+ };
604
+
605
+ window.activateItemListBox = function (menuId, activeItemId) {
606
+ const menu = document.getElementById(menuId);
607
+ if (menu) {
608
+ const getListBoxButton = document.querySelector(`#${menuId} .c-listbox`);
609
+ getListBoxButton.click();
610
+ const activeItem = document.querySelector(`#${menuId} #${activeItemId}`);
611
+ if (activeItem) {
612
+ activateElement(menuId, activeItemId);
613
+ return [menu, activeItem]
614
+ } else {
615
+ console.log('There is no element with this id in the menu.');
616
+ return null;
617
+ }
618
+ } else {
619
+ console.log('There is no menu with this id in the document.');
620
+ return null;
621
+ }
622
+ };
562
623
  return aria;
563
- }
624
+ }
@@ -281,13 +281,18 @@ export function tabs(aria) {
281
281
  //Add active class to current tab
282
282
  element.classList.add("c-tabs__link--is-active");
283
283
  element.setAttribute('role', 'tab');
284
- element.innerHTML = `<strong class="font-bold">${element.textContent}</strong>`;
284
+ if(element.querySelector('strong') === null) {
285
+ element.innerHTML = `<strong class="font-bold">${element.innerHTML}</strong>` ;
286
+ }
285
287
  }
286
288
 
287
289
  function removeActiveClass(element) {
288
290
  element.classList.remove("c-tabs__link--is-active");
289
291
  element.removeAttribute('role');
290
- element.innerHTML = element.textContent;
292
+ if(element.querySelector('strong')) {
293
+ const replaceStrong = element.innerHTML.replace('<strong class="font-bold">', '').replace('<strong/>', '');
294
+ element.innerHTML = `${replaceStrong}`;
295
+ }
291
296
  }
292
297
 
293
298
  window.activateItemTabs = function (menuId, tabItemId) {
@@ -296,16 +301,13 @@ export function tabs(aria) {
296
301
  const activeItemTab = document.querySelector(`#${menuId} #${tabItemId}`);
297
302
  const activeItemPanel = document.querySelector(`[aria-labelledby="${tabItemId}"]`);
298
303
  if (activeItemTab) {
299
- document.querySelectorAll('.c-tabs__link').forEach((tab) => {
300
- tab.classList.remove("c-tabs__link--is-active");
301
- tab.innerHTML = tab.textContent;
304
+ document.querySelectorAll(`#${menuId} .c-tabs__link`).forEach((tab) => {
305
+ removeActiveClass(tab)
302
306
  })
303
307
 
304
- activeItemTab.classList.add("c-tabs__link--is-active");
305
- activeItemTab.setAttribute('role', 'tab');
306
- activeItemTab.innerHTML = `<strong class="font-bold">${activeItemTab.textContent}</strong>`;
308
+ addActiveClass(activeItemTab)
307
309
 
308
- document.querySelectorAll('.c-tabs__panel').forEach((panel) => {
310
+ document.querySelectorAll(`#${menuId} .c-tabs__panel`).forEach((panel) => {
309
311
  panel.setAttribute('hidden', 'hidden')
310
312
  })
311
313