Skip to content

Commit

Permalink
fix(Menu): focused items should scrollintoview when overflowed
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcfaul committed Jul 31, 2023
1 parent ceef7a7 commit 3d650a6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/react-core/src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,23 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
setFlyoutRef(null);
}
};

React.useEffect(() => {
if (isFocused && ref.current) {
const itemEl = ref.current;
const parentListEl = itemEl.parentElement;

if (parentListEl) {
const isAboveTop = itemEl.offsetTop - parentListEl.offsetTop < parentListEl.scrollTop;
const isBelowBottom = itemEl.offsetTop - parentListEl.offsetTop + itemEl.clientHeight;

if (isAboveTop || isBelowBottom) {
itemEl.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
}
}
}, [isFocused]);

const isSelectMenu = menuRole === 'listbox';

const renderItem = (
Expand Down

0 comments on commit 3d650a6

Please sign in to comment.