Skip to content

Commit

Permalink
fix(Menu): Fix crash in menu referencing invalid array index (pattern…
Browse files Browse the repository at this point in the history
…fly#10153)

* Fix crash in menu

* Update code best on review feedback

* fix linting
  • Loading branch information
jamestalton authored and tlabaj committed Mar 12, 2024
1 parent 193cb22 commit 9b671de
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/react-core/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ class MenuBase extends React.Component<MenuProps, MenuState> {
this.setState({ transitionMoveTarget: null });
} else {
const nextMenu = current.querySelector('#' + this.props.activeMenu) || current || null;
const nextMenuChildren = Array.from(nextMenu.getElementsByTagName('UL')[0].children);

const nextMenuLists = nextMenu.getElementsByTagName('UL');
if (nextMenuLists.length === 0) {
return;
}
const nextMenuChildren = Array.from(nextMenuLists[0].children);
if (!this.state.currentDrilldownMenuId || nextMenu.id !== this.state.currentDrilldownMenuId) {
this.setState({ currentDrilldownMenuId: nextMenu.id });
} else {
Expand All @@ -167,7 +170,6 @@ class MenuBase extends React.Component<MenuProps, MenuState> {
const nextTarget = nextMenuChildren.filter(
(el) => !(el.classList.contains('pf-m-disabled') || el.classList.contains(styles.divider))
)[0].firstChild;

(nextTarget as HTMLElement).focus();
(nextTarget as HTMLElement).tabIndex = 0;
}
Expand Down

0 comments on commit 9b671de

Please sign in to comment.