Skip to content

Commit

Permalink
fix: auto scrolling on mouse over jacobworrel#59
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkpokk committed Sep 15, 2023
1 parent e58abfc commit d1be6e2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/MenuList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,30 @@ function MenuList (props) {
}
};

const scrollToItem = React.useCallback(
() => {
if (currentIndex >= 0 && list.current !== null) {
list.current.scrollToItem(currentIndex);
}
},
[currentIndex, list]
);

React.useEffect(
() => {
/**
* enables scrolling on key down arrow
*/
if (currentIndex >= 0 && list.current !== null) {
list.current.scrollToItem(currentIndex);
if (typeof document !== 'undefined') {
const element = document.activeElement
if (element && element.tagName === 'INPUT' && (element.getAttribute('id') ?? '').indexOf('react-select') === 0) {
scrollToItem();
}
} else {
scrollToItem();
}
},
[currentIndex, children, list]
[children, scrollToItem]
);

return (
Expand Down

0 comments on commit d1be6e2

Please sign in to comment.