@momentum-design/components 0.85.5 → 0.85.6

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.
@@ -26,7 +26,10 @@ import { Component } from '../../models';
26
26
  declare class MenuBar extends Component {
27
27
  constructor();
28
28
  connectedCallback(): void;
29
- menuItems: Array<HTMLElement>;
29
+ /**
30
+ * Returns all menuitem elements, including those nested inside menusection.
31
+ */
32
+ get menuItems(): Array<HTMLElement>;
30
33
  update(changedProperties: PropertyValues): void;
31
34
  firstUpdated(changedProperties: PropertyValues): void;
32
35
  /**
@@ -43,6 +46,9 @@ declare class MenuBar extends Component {
43
46
  private navigateToMenuItem;
44
47
  private showSubmenu;
45
48
  private getKeyWithDirectionFix;
49
+ /**
50
+ * Determines if a menuitem is a top-level menuitem (direct child of menubar or child of menusection whose parent is menubar)
51
+ */
46
52
  private isTopLevelMenuItem;
47
53
  private isNestedMenuItem;
48
54
  private closeAllMenuPopovers;
@@ -1,19 +1,9 @@
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
1
  import { html } from 'lit';
11
- import { queryAssignedElements } from 'lit/decorators.js';
12
2
  import { Component } from '../../models';
13
3
  import { ROLE } from '../../utils/roles';
14
4
  import { POPOVER_PLACEMENT } from '../popover/popover.constants';
15
5
  import { TAG_NAME as MENUPOPOVER_TAGNAME } from '../menupopover/menupopover.constants';
16
- import { TAG_NAME as MENUITEM_TAGNAME } from '../menuitem/menuitem.constants';
6
+ import { TAG_NAME as MENUSECTION_TAGNAME } from '../menusection/menusection.constants';
17
7
  import { KEYS } from '../../utils/keys';
18
8
  import { popoverStack } from '../popover/popover.stack';
19
9
  import { DEFAULTS, TAG_NAME as MENUBAR_TAGNAME } from './menubar.constants';
@@ -51,6 +41,25 @@ class MenuBar extends Component {
51
41
  this.role = ROLE.MENUBAR;
52
42
  this.ariaOrientation = DEFAULTS.ORIENTATION;
53
43
  }
44
+ /**
45
+ * Returns all menuitem elements, including those nested inside menusection.
46
+ */
47
+ get menuItems() {
48
+ var _a, _b;
49
+ const slot = (_a = this.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('slot');
50
+ const assigned = (_b = slot === null || slot === void 0 ? void 0 : slot.assignedElements({ flatten: true })) !== null && _b !== void 0 ? _b : [];
51
+ const items = [];
52
+ const collect = (el) => {
53
+ if (el.role === ROLE.MENUITEM && !el.hasAttribute('disabled')) {
54
+ items.push(el);
55
+ }
56
+ else if (el.tagName.toLowerCase() === MENUSECTION_TAGNAME) {
57
+ Array.from(el.children).forEach(collect);
58
+ }
59
+ };
60
+ assigned.forEach(collect);
61
+ return items;
62
+ }
54
63
  update(changedProperties) {
55
64
  super.update(changedProperties);
56
65
  this.updatePopoverPlacement();
@@ -124,13 +133,26 @@ class MenuBar extends Component {
124
133
  return KEYS.ARROW_LEFT;
125
134
  return originalKey;
126
135
  }
136
+ /**
137
+ * Determines if a menuitem is a top-level menuitem (direct child of menubar or child of menusection whose parent is menubar)
138
+ */
127
139
  isTopLevelMenuItem(element) {
128
140
  var _a;
129
- return (((_a = element.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) === MENUBAR_TAGNAME &&
130
- element.tagName.toLowerCase() === MENUITEM_TAGNAME);
141
+ const parent = element.parentElement;
142
+ if (!parent || element.role !== ROLE.MENUITEM)
143
+ return false;
144
+ const parentTag = parent.tagName.toLowerCase();
145
+ if (parentTag === MENUBAR_TAGNAME) {
146
+ return true;
147
+ }
148
+ if (parentTag === MENUSECTION_TAGNAME &&
149
+ ((_a = parent.parentElement) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) === MENUBAR_TAGNAME) {
150
+ return true;
151
+ }
152
+ return false;
131
153
  }
132
154
  isNestedMenuItem(element) {
133
- return !!element.closest(MENUPOPOVER_TAGNAME) && element.tagName.toLowerCase() === MENUITEM_TAGNAME;
155
+ return !!element.closest(MENUPOPOVER_TAGNAME) && element.role === ROLE.MENUITEM;
134
156
  }
135
157
  async closeAllMenuPopovers() {
136
158
  const popovers = [];
@@ -144,7 +166,7 @@ class MenuBar extends Component {
144
166
  await Promise.all(popovers.map(popover => popover.updateComplete));
145
167
  }
146
168
  async crossMenubarNavigationOnLeft(element) {
147
- const isMenuItem = element.tagName.toLowerCase() === MENUITEM_TAGNAME;
169
+ const isMenuItem = element.role === ROLE.MENUITEM;
148
170
  if (isMenuItem) {
149
171
  const parentPopover = element.closest(MENUPOPOVER_TAGNAME);
150
172
  const triggerId = parentPopover === null || parentPopover === void 0 ? void 0 : parentPopover.getAttribute('triggerid');
@@ -229,8 +251,4 @@ class MenuBar extends Component {
229
251
  }
230
252
  }
231
253
  MenuBar.styles = [...Component.styles, ...styles];
232
- __decorate([
233
- queryAssignedElements({ selector: `${MENUITEM_TAGNAME}:not([disabled])` }),
234
- __metadata("design:type", Array)
235
- ], MenuBar.prototype, "menuItems", void 0);
236
254
  export default MenuBar;
@@ -15228,7 +15228,9 @@
15228
15228
  "name": "menuItems",
15229
15229
  "type": {
15230
15230
  "text": "Array<HTMLElement>"
15231
- }
15231
+ },
15232
+ "description": "Returns all menuitem elements, including those nested inside menusection.",
15233
+ "readonly": true
15232
15234
  },
15233
15235
  {
15234
15236
  "kind": "method",
@@ -15386,7 +15388,8 @@
15386
15388
  "text": "HTMLElement"
15387
15389
  }
15388
15390
  }
15389
- ]
15391
+ ],
15392
+ "description": "Determines if a menuitem is a top-level menuitem (direct child of menubar or child of menusection whose parent is menubar)"
15390
15393
  },
15391
15394
  {
15392
15395
  "kind": "method",
@@ -20922,6 +20925,8 @@
20922
20925
  "type": {
20923
20926
  "text": "Array<HTMLElement>"
20924
20927
  },
20928
+ "description": "Returns all menuitem elements, including those nested inside menusection.",
20929
+ "readonly": true,
20925
20930
  "inheritedFrom": {
20926
20931
  "name": "MenuBar",
20927
20932
  "module": "components/menubar/menubar.component.js"
@@ -21112,6 +21117,7 @@
21112
21117
  }
21113
21118
  }
21114
21119
  ],
21120
+ "description": "Determines if a menuitem is a top-level menuitem (direct child of menubar or child of menusection whose parent is menubar)",
21115
21121
  "inheritedFrom": {
21116
21122
  "name": "MenuBar",
21117
21123
  "module": "components/menubar/menubar.component.js"
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.85.5"
44
+ "version": "0.85.6"
45
45
  }