Skip to content

Commit d3b53f5

Browse files
authored
fix(Menu): Fix crash in menu referencing invalid array index (#10153)
* Fix crash in menu * Update code best on review feedback * fix linting
1 parent 525c184 commit d3b53f5

File tree

1 file changed

+5
-3
lines changed
  • packages/react-core/src/components/Menu

1 file changed

+5
-3
lines changed

packages/react-core/src/components/Menu/Menu.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@ class MenuBase extends React.Component<MenuProps, MenuState> {
156156
this.setState({ transitionMoveTarget: null });
157157
} else {
158158
const nextMenu = current.querySelector('#' + this.props.activeMenu) || current || null;
159-
const nextMenuChildren = Array.from(nextMenu.getElementsByTagName('UL')[0].children);
160-
159+
const nextMenuLists = nextMenu.getElementsByTagName('UL');
160+
if (nextMenuLists.length === 0) {
161+
return;
162+
}
163+
const nextMenuChildren = Array.from(nextMenuLists[0].children);
161164
if (!this.state.currentDrilldownMenuId || nextMenu.id !== this.state.currentDrilldownMenuId) {
162165
this.setState({ currentDrilldownMenuId: nextMenu.id });
163166
} else {
@@ -167,7 +170,6 @@ class MenuBase extends React.Component<MenuProps, MenuState> {
167170
const nextTarget = nextMenuChildren.filter(
168171
(el) => !(el.classList.contains('pf-m-disabled') || el.classList.contains(styles.divider))
169172
)[0].firstChild;
170-
171173
(nextTarget as HTMLElement).focus();
172174
(nextTarget as HTMLElement).tabIndex = 0;
173175
}

0 commit comments

Comments
 (0)