-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
issue/needs-reviewissue/reviewedIssue has recently been reviewed (mid-2020)Issue has recently been reviewed (mid-2020)menu-bugAddresses menu positioning, scrolling, or general interactionsAddresses menu positioning, scrolling, or general interactions
Description
When using react-select
with menuPostion="fixed"
I've noticed a strange behaviour when trying to select an option after scrolling down.
The issue can be reproduced in this sandbox: https://codesandbox.io/s/react-codesandboxer-example-mxslt?file=/example.js
Steps:
- click on the select to open the options menu;
- scroll down the page (not the options menu) to the bottom (would be best if the select is no longer visible in the viewport);
- try to select any option that is not highlighted;
- the menu will re-render at different postion.
Is this an expected behaviour?
Here is what I found after digging into the code:
- when user hovers on an option in the menu,
onOptionHover
gets calledreact-select/packages/react-select/src/Select.js
Lines 1142 to 1147 in 32ad5c0
onOptionHover = (focusedOption: OptionType) => { if (this.blockOptionHover || this.state.focusedOption === focusedOption) { return; } this.setState({ focusedOption }); }; setState
; - because the
setState
was called the menu is rerendered and freshly calculated offset is applied:react-select/packages/react-select/src/components/Menu.js
Lines 519 to 521 in 32ad5c0
const rect = getBoundingClientObj(controlElement); const scrollDistance = isFixed ? 0 : window.pageYOffset; const offset = rect[placement] + scrollDistance;
Thanks,
Patryk.
P.S. Thanks for this awesome library!
ebonow, Besuf and krishnan-456
Metadata
Metadata
Assignees
Labels
issue/needs-reviewissue/reviewedIssue has recently been reviewed (mid-2020)Issue has recently been reviewed (mid-2020)menu-bugAddresses menu positioning, scrolling, or general interactionsAddresses menu positioning, scrolling, or general interactions