Skip to content

Commit

Permalink
fix(menu): fix arrow key navigation when onClose is called but not cl…
Browse files Browse the repository at this point in the history
…osed (#13195)

* fix(menu): only clear registered items when root is closing

* fix(menu): auto-cleanup registered items

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
janhassel and kodiakhq[bot] committed Mar 2, 2023
1 parent f5b9a13 commit 22d87ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 0 additions & 2 deletions packages/react/src/components/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ const Menu = React.forwardRef(function Menu(
returnFocus();
}

childDispatch({ type: 'clearRegisteredItems' });

if (onClose) {
onClose();
}
Expand Down
9 changes: 3 additions & 6 deletions packages/react/src/components/Menu/MenuContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ function menuReducer(state, action) {
case 'registerItem':
return {
...state,
items: [...state.items, action.payload],
};
case 'clearRegisteredItems':
return {
...state,
items: [],
items: [...state.items, action.payload].filter(
(item) => item.ref.current !== null
),
};
}
}
Expand Down

0 comments on commit 22d87ca

Please sign in to comment.