@momentum-design/components 0.74.2 → 0.74.4

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 (60) hide show
  1. package/dist/browser/index.js +396 -366
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/animation/animation.component.js +1 -1
  4. package/dist/components/listitem/listitem.component.d.ts +5 -0
  5. package/dist/components/listitem/listitem.component.js +25 -2
  6. package/dist/components/menu/index.d.ts +8 -0
  7. package/dist/components/menu/index.js +5 -0
  8. package/dist/components/menu/menu.component.d.ts +19 -0
  9. package/dist/components/menu/menu.component.js +35 -0
  10. package/dist/components/menu/menu.constants.d.ts +2 -0
  11. package/dist/components/menu/menu.constants.js +3 -0
  12. package/dist/components/menubar/index.d.ts +7 -0
  13. package/dist/components/menubar/index.js +4 -0
  14. package/dist/components/menubar/menubar.component.d.ts +32 -0
  15. package/dist/components/menubar/menubar.component.js +51 -0
  16. package/dist/components/menubar/menubar.constants.d.ts +6 -0
  17. package/dist/components/menubar/menubar.constants.js +7 -0
  18. package/dist/components/menubar/menubar.styles.d.ts +2 -0
  19. package/dist/components/menubar/menubar.styles.js +15 -0
  20. package/dist/components/menubar/menubar.types.d.ts +4 -0
  21. package/dist/components/menubar/menubar.types.js +1 -0
  22. package/dist/components/menuitem/index.d.ts +1 -0
  23. package/dist/components/menuitem/index.js +1 -0
  24. package/dist/components/menuitem/menuitem.component.d.ts +27 -0
  25. package/dist/components/menuitem/menuitem.component.js +54 -1
  26. package/dist/components/menuitem/menuitem.constants.d.ts +13 -1
  27. package/dist/components/menuitem/menuitem.constants.js +13 -1
  28. package/dist/components/menuitem/menuitem.styles.d.ts +2 -0
  29. package/dist/components/menuitem/menuitem.styles.js +11 -0
  30. package/dist/components/menuitem/menuitem.types.d.ts +5 -1
  31. package/dist/components/menupopover/index.d.ts +7 -0
  32. package/dist/components/menupopover/index.js +4 -0
  33. package/dist/components/menupopover/menupopover.component.d.ts +30 -0
  34. package/dist/components/menupopover/menupopover.component.js +56 -0
  35. package/dist/components/menupopover/menupopover.constants.d.ts +2 -0
  36. package/dist/components/menupopover/menupopover.constants.js +3 -0
  37. package/dist/components/menupopover/menupopover.styles.d.ts +2 -0
  38. package/dist/components/menupopover/menupopover.styles.js +7 -0
  39. package/dist/components/menusection/menusection.component.d.ts +0 -9
  40. package/dist/components/menusection/menusection.component.js +0 -19
  41. package/dist/custom-elements.json +13767 -9589
  42. package/dist/index.d.ts +8 -5
  43. package/dist/index.js +8 -5
  44. package/dist/react/index.d.ts +4 -1
  45. package/dist/react/index.js +4 -1
  46. package/dist/react/listitem/index.d.ts +1 -0
  47. package/dist/react/listitem/index.js +1 -0
  48. package/dist/react/menu/index.d.ts +13 -0
  49. package/dist/react/menu/index.js +22 -0
  50. package/dist/react/menubar/index.d.ts +23 -0
  51. package/dist/react/menubar/index.js +32 -0
  52. package/dist/react/menuitem/index.d.ts +2 -0
  53. package/dist/react/menuitem/index.js +2 -0
  54. package/dist/react/menupopover/index.d.ts +29 -0
  55. package/dist/react/menupopover/index.js +37 -0
  56. package/dist/utils/keys.d.ts +2 -0
  57. package/dist/utils/keys.js +2 -0
  58. package/dist/utils/mixins/MenuMixin.d.ts +12 -0
  59. package/dist/utils/mixins/MenuMixin.js +474 -0
  60. package/package.json +1 -1
@@ -0,0 +1,474 @@
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
+ };
10
+ import { property, queryAssignedElements } from 'lit/decorators.js';
11
+ import { TAG_NAME as MENU_TAGNAME } from '../../components/menu/menu.constants';
12
+ import { ORIENTATION, TAG_NAME as MENUBAR_TAGNAME } from '../../components/menubar/menubar.constants';
13
+ import { TAG_NAME as MENUITEM_TAGNAME } from '../../components/menuitem/menuitem.constants';
14
+ import { TAG_NAME as MENUITEMCHECKBOX_TAGNAME } from '../../components/menuitemcheckbox/menuitemcheckbox.constants';
15
+ import { TAG_NAME as MENUITEMRADIO_TAGNAME } from '../../components/menuitemradio/menuitemradio.constants';
16
+ import { TAG_NAME as MENUPOPOVER_TAGNAME } from '../../components/menupopover/menupopover.constants';
17
+ import { TAG_NAME as MENUSECTION_TAGNAME } from '../../components/menusection/menusection.constants';
18
+ import { POPOVER_PLACEMENT } from '../../components/popover/popover.constants';
19
+ import { KEYS } from '../keys';
20
+ export const MenuMixin = (superClass) => {
21
+ class InnerMixinClass extends superClass {
22
+ constructor() {
23
+ super(...arguments);
24
+ /**
25
+ * Defines the orientation of the menu. This value is reflected to
26
+ * the `aria-orientation` attribute and can be either `'horizontal'` or `'vertical'`.
27
+ * @default 'horizontal'
28
+ */
29
+ this.ariaOrientation = ORIENTATION.HORIZONTAL;
30
+ }
31
+ /** @internal */
32
+ get menuItems() {
33
+ var _a;
34
+ const slot = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot');
35
+ const allAssignedElements = ((slot === null || slot === void 0 ? void 0 : slot.assignedElements({ flatten: true })) || []);
36
+ return allAssignedElements.map((node) => {
37
+ if (node.tagName.toLowerCase() === MENUSECTION_TAGNAME) {
38
+ return Array.from(node.children)
39
+ .filter((child) => this.isValidMenuItem(child));
40
+ }
41
+ return this.isValidMenuItem(node) ? node : [];
42
+ })
43
+ .flat()
44
+ .filter((node) => !!node)
45
+ .filter((node) => !node.hasAttribute('disabled'));
46
+ }
47
+ firstUpdated(changedProperties) {
48
+ super.firstUpdated(changedProperties);
49
+ this.setMenuBarPopoverValue(false);
50
+ }
51
+ /**
52
+ * Sets the value of the data-menu-popover-open attribute on the menu element.
53
+ * @param value - The value to set.
54
+ */
55
+ setMenuBarPopoverValue(value) {
56
+ const { menu } = this.getParentMenuItemDetails('', this);
57
+ menu === null || menu === void 0 ? void 0 : menu.setAttribute('data-menu-popover-open', value.toString());
58
+ }
59
+ /**
60
+ * Returns true if the data-menu-popover-open attribute on the menu element is set to 'true', false otherwise.
61
+ */
62
+ isMenuPopoverOpen() {
63
+ const { menu } = this.getParentMenuItemDetails('', this);
64
+ return (menu === null || menu === void 0 ? void 0 : menu.getAttribute('data-menu-popover-open')) === 'true';
65
+ }
66
+ /**
67
+ * Returns the index of the given target in the menuItems array.
68
+ * If the target is not a menu item, but a child element of a menu item,
69
+ * it returns the index of the parent menu item.
70
+ * @param target - The target element to find the index of.
71
+ * @returns The index of the target element in the menuItems array.
72
+ */
73
+ getCurrentIndex(target) {
74
+ return this.menuItems.findIndex((node) => node === target || node === target.parentElement);
75
+ }
76
+ /**
77
+ * Updates the placement of the popover based on the aria-orientation property.
78
+ */
79
+ updatePopoverPlacementBasedOnOrientation() {
80
+ if (this.ariaOrientation === ORIENTATION.HORIZONTAL) {
81
+ this.menuPopoverItems.forEach((node) => {
82
+ node.setAttribute('placement', POPOVER_PLACEMENT.BOTTOM_START);
83
+ });
84
+ }
85
+ else {
86
+ this.menuPopoverItems.forEach((node) => {
87
+ node.setAttribute('placement', POPOVER_PLACEMENT.RIGHT_START);
88
+ });
89
+ }
90
+ }
91
+ /**
92
+ * Updates the tabindex of the current index to -1 and the tabindex of the new index to 0,
93
+ * effectively setting the active element. This is used when navigating the menu via keyboard.
94
+ * @param menuItems - The list of menu items.
95
+ * @param currentIndex - The current index of the focused menu item.
96
+ * @param newIndex - The index of the new active element in the list.
97
+ */
98
+ updateTabIndexAndFocusNewIndex(menuItems, currentIndex, newIndex) {
99
+ var _a, _b, _c, _d;
100
+ if (newIndex < 0 || currentIndex < 0) {
101
+ return;
102
+ }
103
+ if (currentIndex === newIndex) {
104
+ (_a = menuItems[currentIndex]) === null || _a === void 0 ? void 0 : _a.focus();
105
+ return;
106
+ }
107
+ (_b = menuItems[currentIndex]) === null || _b === void 0 ? void 0 : _b.setAttribute('tabindex', '-1');
108
+ (_c = menuItems[newIndex]) === null || _c === void 0 ? void 0 : _c.setAttribute('tabindex', '0');
109
+ (_d = menuItems[newIndex]) === null || _d === void 0 ? void 0 : _d.focus();
110
+ }
111
+ /**
112
+ * Checks if the given tag name is a valid menu tag name.
113
+ * @param tagName - The tag name to check.
114
+ * @returns True if the tag name is a valid menu, false otherwise.
115
+ */
116
+ isValidMenu(tagName) {
117
+ return ((tagName === null || tagName === void 0 ? void 0 : tagName.toLowerCase()) === MENU_TAGNAME
118
+ || (tagName === null || tagName === void 0 ? void 0 : tagName.toLowerCase()) === MENUBAR_TAGNAME);
119
+ }
120
+ /**
121
+ * Checks if the given tag name is a valid menu popover tag name.
122
+ * @param tagName - The tag name to check.
123
+ * @returns True if the tag name is a valid menu popover, false otherwise.
124
+ */
125
+ isValidPopover(tagName) {
126
+ return (tagName === null || tagName === void 0 ? void 0 : tagName.toLowerCase()) === MENUPOPOVER_TAGNAME;
127
+ }
128
+ /**
129
+ * Opens the popover at the given index if it exists.
130
+ * @param index - The index of the menu item to open the popover for.
131
+ * @returns True if the popover was opened, false if not.
132
+ */
133
+ openPopover(index) {
134
+ var _a, _b;
135
+ if (this.isValidPopover((_b = (_a = this.menuItems[index]) === null || _a === void 0 ? void 0 : _a.nextElementSibling) === null || _b === void 0 ? void 0 : _b.tagName)) {
136
+ const currentMenuId = this.menuItems[index].getAttribute('id');
137
+ const result = this.menuPopoverItems.findIndex((node) => node.getAttribute('triggerid') === currentMenuId);
138
+ if (result !== -1) {
139
+ if (!this.menuPopoverItems[result].hasAttribute('visible')) {
140
+ this.menuPopoverItems[result].toggleAttribute('visible');
141
+ }
142
+ this.setMenuBarPopoverValue(true);
143
+ return true;
144
+ }
145
+ }
146
+ return false;
147
+ }
148
+ /**
149
+ * Navigates to the previous menu item and updates the tabindex of the current index
150
+ * to -1 and the tabindex of the new index to 0.
151
+ * @param currentIndex - The current index of the focused menu item.
152
+ * @param firstMenuIndex - The index of the first menu item.
153
+ * @param lastMenuIndex - The index of the last menu item.
154
+ * @param ariaOrientation - The orientation of the menu.
155
+ */
156
+ navigateToPrevMenuItem(currentIndex, firstMenuIndex, lastMenuIndex, ariaOrientation) {
157
+ const newIndex = currentIndex === firstMenuIndex ? lastMenuIndex : currentIndex - 1;
158
+ this.updateTabIndexAndFocusNewIndex(this.menuItems, currentIndex, newIndex);
159
+ // - if the isMenuPopoverOpen is true and orientation is horizontal, then we will open the popover.
160
+ if (this.isMenuPopoverOpen() && ariaOrientation === ORIENTATION.HORIZONTAL) {
161
+ this.openPopover(newIndex);
162
+ }
163
+ }
164
+ /**
165
+ * Navigates to the next menu item and updates the tabindex of the current index
166
+ * to -1 and the tabindex of the new index to 0.
167
+ * @param currentIndex - The current index of the focused menu item.
168
+ * @param firstMenuIndex - The index of the first menu item.
169
+ * @param lastMenuIndex - The index of the last menu item.
170
+ * @param ariaOrientation - The orientation of the menu.
171
+ */
172
+ navigateToNextMenuItem(currentIndex, firstMenuIndex, lastMenuIndex, ariaOrientation) {
173
+ const newIndex = currentIndex === lastMenuIndex ? firstMenuIndex : currentIndex + 1;
174
+ this.updateTabIndexAndFocusNewIndex(this.menuItems, currentIndex, newIndex);
175
+ // - if the isMenuPopoverOpen is true, then we will close all popovers recursively,
176
+ if (this.isMenuPopoverOpen() && ariaOrientation === ORIENTATION.HORIZONTAL) {
177
+ this.openPopover(newIndex);
178
+ }
179
+ }
180
+ /**
181
+ * Returns the parent menu item details for the given menu child id.
182
+ * It recursively traverses up the DOM tree until it finds a menu or menubar element.
183
+ * @param menuChildId - The id of the menu child element.
184
+ * @param menu - The current menu element to start traversing from.
185
+ * @returns An object containing the parent menu element and the menu child id.
186
+ */
187
+ getParentMenuItemDetails(menuChildId, menu) {
188
+ var _a, _b;
189
+ if (menu && this.isValidMenu(menu.tagName)) {
190
+ return { menu, menuChildId };
191
+ }
192
+ return this.getParentMenuItemDetails((_b = (_a = menu === null || menu === void 0 ? void 0 : menu.previousElementSibling) === null || _a === void 0 ? void 0 : _a.getAttribute('id')) !== null && _b !== void 0 ? _b : '', menu === null || menu === void 0 ? void 0 : menu.parentElement);
193
+ }
194
+ /**
195
+ * Recursively hides all the popovers up the DOM tree until it finds a menu or menubar element.
196
+ * @param menu - The current menu element to start traversing from.
197
+ */
198
+ hideAllPopovers(menu) {
199
+ if (this.isValidMenu(menu === null || menu === void 0 ? void 0 : menu.tagName)) {
200
+ return;
201
+ }
202
+ if (this.isValidPopover(menu === null || menu === void 0 ? void 0 : menu.tagName)) {
203
+ menu === null || menu === void 0 ? void 0 : menu.toggleAttribute('visible');
204
+ }
205
+ if (menu === null || menu === void 0 ? void 0 : menu.parentElement) {
206
+ this.hideAllPopovers(menu.parentElement);
207
+ }
208
+ }
209
+ /**
210
+ * Recursively navigates up the DOM tree until it finds the previous menu item
211
+ * and updates the tabindex of the current index to -1 and the tabindex of the new index to 0.
212
+ * Also opens the popover of the previous menu item.
213
+ * @param currentIndex - The current index of the focused menu item.
214
+ */
215
+ navigateToPrevParentMenuItem(currentIndex, key) {
216
+ var _a, _b, _c, _d, _e;
217
+ const parentMenuItem = (_a = this.menuItems[currentIndex].parentElement) === null || _a === void 0 ? void 0 : _a.previousElementSibling;
218
+ const parentMenuItemsChildren = Array.from(((_b = this.parentElement) === null || _b === void 0 ? void 0 : _b.children) || []).filter((node) => this.isValidMenuItem(node));
219
+ const parentMenuItemIndex = parentMenuItemsChildren.findIndex((node) => node === parentMenuItem);
220
+ let newIndex = parentMenuItemIndex;
221
+ if (key === KEYS.ARROW_LEFT && this.isValidMenu((_c = this.parentElement) === null || _c === void 0 ? void 0 : _c.tagName)) {
222
+ newIndex = parentMenuItemIndex - 1;
223
+ }
224
+ this.updateTabIndexAndFocusNewIndex(parentMenuItemsChildren, parentMenuItemIndex, newIndex);
225
+ if (key === KEYS.ARROW_LEFT) {
226
+ (_e = (_d = parentMenuItemsChildren[parentMenuItemIndex - 1]) === null || _d === void 0 ? void 0 : _d.nextElementSibling) === null || _e === void 0 ? void 0 : _e.toggleAttribute('visible');
227
+ }
228
+ }
229
+ /**
230
+ * Closes the current menu popover and navigates to the previous parent menu item.
231
+ * @param currentIndex - The current index of the focused menu item.
232
+ */
233
+ closePopoverAndNavigateToPrevParentMenuItem(currentIndex, key) {
234
+ // - close popover first
235
+ this.toggleAttribute('visible');
236
+ // - get parent menu item details and update the tab index to parent menu item.
237
+ this.navigateToPrevParentMenuItem(currentIndex, key);
238
+ }
239
+ /**
240
+ * Gets the parent menu contents of the given current menu item.
241
+ * It recursively traverses up the DOM tree until it finds the parent menu element
242
+ * and gets the parent menu item details and the children of the parent menu item.
243
+ * @param currentMenuItem - The current menu item to start traversing from.
244
+ * @returns An object containing the parent menu item details and the children of the parent menu item.
245
+ */
246
+ getParentMenuContents(currentMenuItem) {
247
+ var _a;
248
+ const parentMenuItemDetails = this.getParentMenuItemDetails('', currentMenuItem);
249
+ const parentMenuItemsChildren = Array.from(((_a = parentMenuItemDetails.menu) === null || _a === void 0 ? void 0 : _a.children) || []).filter((node) => this.isValidMenuItem(node));
250
+ return { parentMenuItemDetails, parentMenuItemsChildren };
251
+ }
252
+ /**
253
+ * Sets focus to the parent menu item of the given current menu item.
254
+ * It retrieves the parent menu item details and its children, then focuses
255
+ * on the menu item that matches the parent menu child ID.
256
+ * @param currentMenuItem - The current menu item from which to find and focus the parent menu item.
257
+ */
258
+ setFocusToParentMenuItem(currentMenuItem) {
259
+ var _a;
260
+ const { parentMenuItemDetails, parentMenuItemsChildren, } = this.getParentMenuContents(currentMenuItem);
261
+ // Only proceed if menuChildId is non-empty
262
+ if (parentMenuItemDetails === null || parentMenuItemDetails === void 0 ? void 0 : parentMenuItemDetails.menuChildId) {
263
+ const menuBarMenuItem = parentMenuItemsChildren.filter((node) => node.getAttribute('id') === parentMenuItemDetails.menuChildId);
264
+ (_a = menuBarMenuItem[0]) === null || _a === void 0 ? void 0 : _a.focus();
265
+ }
266
+ }
267
+ /**
268
+ * Opens the popover of the next children menu item if there are children.
269
+ * If there are no children, then it closes all popovers recursively and
270
+ * navigates to the next menu item from the menu bar.
271
+ * If the parent menu item does not have any children, then we will go to the next menu item.
272
+ * @param currentIndex - The current index of the focused menu item.
273
+ */
274
+ openPopoverAndNavigateToNextChildrenMenuItem(currentIndex) {
275
+ var _a, _b;
276
+ if (this.openPopover(currentIndex)) {
277
+ return;
278
+ }
279
+ // - If there are no popovers to the right, then we will close all popovers recursively,
280
+ // and go the next menu item from the menu bar
281
+ this.hideAllPopovers(this.menuItems[currentIndex]);
282
+ // - get the top parent menu items using recursion.
283
+ const { parentMenuItemDetails, parentMenuItemsChildren, } = this.getParentMenuContents(this.menuItems[currentIndex]);
284
+ if (parentMenuItemsChildren.length === 0 || (parentMenuItemDetails === null || parentMenuItemDetails === void 0 ? void 0 : parentMenuItemDetails.menuChildId) === '') {
285
+ this.navigateToNextMenuItem(currentIndex, 0, this.menuItems.length - 1, this.ariaOrientation);
286
+ return;
287
+ }
288
+ const parentMenuItemIndex = parentMenuItemsChildren.findIndex((node) => node.getAttribute('id') === (parentMenuItemDetails === null || parentMenuItemDetails === void 0 ? void 0 : parentMenuItemDetails.menuChildId));
289
+ const newIndex = parentMenuItemIndex === -1 ? currentIndex + 1 : parentMenuItemIndex + 1;
290
+ this.updateTabIndexAndFocusNewIndex(parentMenuItemsChildren, parentMenuItemIndex, newIndex);
291
+ (_b = (_a = parentMenuItemsChildren[newIndex]) === null || _a === void 0 ? void 0 : _a.nextElementSibling) === null || _b === void 0 ? void 0 : _b.toggleAttribute('visible');
292
+ }
293
+ /**
294
+ * Checks if the given menu item is a valid menu item.
295
+ * @param menuItem - The menu item to check.
296
+ * @returns True if the menu item is a valid menu item, false otherwise.
297
+ */
298
+ isValidMenuItem(menuItem) {
299
+ var _a;
300
+ return [MENUITEM_TAGNAME, MENUITEMCHECKBOX_TAGNAME, MENUITEMRADIO_TAGNAME]
301
+ .includes((_a = menuItem.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase());
302
+ }
303
+ /**
304
+ * Handles the mouse click event on the menu items.
305
+ * Resets all the menu items tabindex to -1 and sets the tabindex of the
306
+ * element at the given index to 0, effectively setting the active
307
+ * element. This is used when clicking on the menu items.
308
+ * @param event - The mouse click event.
309
+ */
310
+ setTabIndexOnMouseClick(event) {
311
+ var _a;
312
+ const newIndex = this.getCurrentIndex(event.target);
313
+ this.resetTabIndexAndSetActiveTabIndex(newIndex);
314
+ (_a = this.menuItems[newIndex]) === null || _a === void 0 ? void 0 : _a.focus();
315
+ }
316
+ /**
317
+ * Resets all list items tabindex to -1 and sets the tabindex of the
318
+ * element at the given index to 0, effectively setting the active
319
+ * element. This is used when navigating the list via keyboard.
320
+ *
321
+ * @param newIndex - The index of the new active element in the list.
322
+ */
323
+ resetTabIndexAndSetActiveTabIndex(newIndex) {
324
+ this.menuItems.forEach((node, index) => {
325
+ const newTabindex = newIndex === index ? '0' : '-1';
326
+ node === null || node === void 0 ? void 0 : node.setAttribute('tabindex', newTabindex);
327
+ });
328
+ }
329
+ /**
330
+ * Handles the keydown event on the menu bar.
331
+ * The keys are as follows:
332
+ * - HOME: Sets focus to the first menu item.
333
+ * - END: Sets focus to the last menu item.
334
+ * - ARROW_LEFT:
335
+ * - If orientation is horizontal, then it navigates to the previous menu item.
336
+ * - If orientation is vertical, then it closes the popover of the current menu item and
337
+ * navigates to the previous parent menu item.
338
+ * - ARROW_RIGHT:
339
+ * - If orientation is horizontal, then it navigates to the next menu item.
340
+ * - If orientation is vertical, then it opens the popover of the current menu item and
341
+ * navigates to the next children menu item.
342
+ * - ARROW_UP:
343
+ * - If orientation is horizontal, then it opens the popover of the current menu item.
344
+ * - If orientation is vertical, then it navigates to the previous menu item.
345
+ * - ARROW_DOWN:
346
+ * - If orientation is horizontal, then it opens the popover of the current menu item.
347
+ * - If orientation is vertical, then it navigates to the next menu item.
348
+ * - SPACE:
349
+ * - ENTER:
350
+ * - If the next element sibling is a menu popover, then it opens the popover of the current
351
+ * menu item and navigates to the next children menu item.
352
+ * - If the target element is a menu item, then it closes all popovers recursively and
353
+ * navigates to the previous parent menu item.
354
+ * - ESCAPE:
355
+ * - If a popover is already open then we close it and navigate to the parent menu item.
356
+ * - If the current menuitem is a child of menubar, then we will set the value of isMenuPopoverOpen to false.,
357
+ * @param event - The keyboard event.
358
+ */
359
+ handleKeyDown(event) {
360
+ var _a, _b;
361
+ const firstMenuIndex = 0;
362
+ const lastMenuIndex = this.menuItems.length - 1;
363
+ const currentIndex = this.getCurrentIndex(event.target);
364
+ if (currentIndex === -1)
365
+ return;
366
+ switch (event.key) {
367
+ case KEYS.HOME:
368
+ this.updateTabIndexAndFocusNewIndex(this.menuItems, currentIndex, firstMenuIndex);
369
+ break;
370
+ case KEYS.END:
371
+ this.updateTabIndexAndFocusNewIndex(this.menuItems, currentIndex, lastMenuIndex);
372
+ break;
373
+ case KEYS.ARROW_LEFT: {
374
+ if (this.ariaOrientation === ORIENTATION.HORIZONTAL) {
375
+ this.navigateToPrevMenuItem(currentIndex, firstMenuIndex, lastMenuIndex, this.ariaOrientation);
376
+ }
377
+ if (this.ariaOrientation === ORIENTATION.VERTICAL) {
378
+ this.closePopoverAndNavigateToPrevParentMenuItem(currentIndex, event.key);
379
+ }
380
+ break;
381
+ }
382
+ case KEYS.ARROW_RIGHT: {
383
+ if (this.ariaOrientation === ORIENTATION.HORIZONTAL) {
384
+ this.navigateToNextMenuItem(currentIndex, firstMenuIndex, lastMenuIndex, this.ariaOrientation);
385
+ }
386
+ if (this.ariaOrientation === ORIENTATION.VERTICAL) {
387
+ this.openPopoverAndNavigateToNextChildrenMenuItem(currentIndex);
388
+ }
389
+ break;
390
+ }
391
+ case KEYS.ARROW_UP: {
392
+ if (this.ariaOrientation === ORIENTATION.HORIZONTAL) {
393
+ this.openPopover(currentIndex);
394
+ }
395
+ if (this.ariaOrientation === ORIENTATION.VERTICAL) {
396
+ this.navigateToPrevMenuItem(currentIndex, firstMenuIndex, lastMenuIndex, this.ariaOrientation);
397
+ }
398
+ event.preventDefault();
399
+ break;
400
+ }
401
+ case KEYS.ARROW_DOWN: {
402
+ if (this.ariaOrientation === ORIENTATION.HORIZONTAL) {
403
+ this.openPopover(currentIndex);
404
+ }
405
+ if (this.ariaOrientation === ORIENTATION.VERTICAL) {
406
+ this.navigateToNextMenuItem(currentIndex, firstMenuIndex, lastMenuIndex, this.ariaOrientation);
407
+ }
408
+ event.preventDefault();
409
+ break;
410
+ }
411
+ case KEYS.SPACE:
412
+ case KEYS.ENTER: {
413
+ if (this.isValidPopover((_b = (_a = this.menuItems[currentIndex]) === null || _a === void 0 ? void 0 : _a.nextElementSibling) === null || _b === void 0 ? void 0 : _b.tagName)) {
414
+ this.openPopoverAndNavigateToNextChildrenMenuItem(currentIndex);
415
+ }
416
+ else if (this.isValidMenuItem(event.target)) {
417
+ this.setMenuBarPopoverValue(false);
418
+ this.setFocusToParentMenuItem(this.menuItems[currentIndex]);
419
+ }
420
+ break;
421
+ }
422
+ case KEYS.ESCAPE: {
423
+ this.setMenuBarPopoverValue(false);
424
+ if (this.ariaOrientation === ORIENTATION.VERTICAL) {
425
+ this.navigateToPrevParentMenuItem(currentIndex, event.key);
426
+ }
427
+ break;
428
+ }
429
+ default:
430
+ break;
431
+ }
432
+ }
433
+ /**
434
+ * Closes all popovers except the current one.
435
+ * @param currentIndex - The index of the current menu item.
436
+ */
437
+ closeAllPopoversExceptCurrent(currentIndex) {
438
+ this.menuPopoverItems
439
+ .filter((node) => node !== this.menuItems[currentIndex])
440
+ .filter((node) => node.hasAttribute('visible'))
441
+ .forEach((node) => node.toggleAttribute('visible'));
442
+ }
443
+ /**
444
+ * Handles the mouse click event on the menu items.
445
+ * - If the menuitem has children, then it opens the popover of the next children menu item.
446
+ * - If the menuitem does not have children, then it closes all popovers recursively.
447
+ * @param event - The mouse click event.
448
+ */
449
+ handleMouseClick(event) {
450
+ var _a, _b;
451
+ const target = event.target;
452
+ const currentIndex = this.getCurrentIndex(target);
453
+ if (currentIndex === -1)
454
+ return;
455
+ if (this.isValidPopover((_b = (_a = this.menuItems[currentIndex]) === null || _a === void 0 ? void 0 : _a.nextElementSibling) === null || _b === void 0 ? void 0 : _b.tagName)) {
456
+ this.closeAllPopoversExceptCurrent(currentIndex);
457
+ this.openPopoverAndNavigateToNextChildrenMenuItem(currentIndex);
458
+ }
459
+ else if (this.isValidMenuItem(target)) {
460
+ this.hideAllPopovers(this.menuItems[currentIndex]);
461
+ }
462
+ }
463
+ }
464
+ __decorate([
465
+ property({ type: String, reflect: true, attribute: 'aria-orientation' }),
466
+ __metadata("design:type", String)
467
+ ], InnerMixinClass.prototype, "ariaOrientation", void 0);
468
+ __decorate([
469
+ queryAssignedElements({ selector: `${MENUPOPOVER_TAGNAME}:not([disabled])` }),
470
+ __metadata("design:type", Array)
471
+ ], InnerMixinClass.prototype, "menuPopoverItems", void 0);
472
+ // Cast return type to your mixin's interface intersected with the superClass type
473
+ return InnerMixinClass;
474
+ };
package/package.json CHANGED
@@ -41,5 +41,5 @@
41
41
  "lottie-web": "^5.12.2",
42
42
  "uuid": "^11.0.5"
43
43
  },
44
- "version": "0.74.2"
44
+ "version": "0.74.4"
45
45
  }