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