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 called
|
onOptionHover = (focusedOption: OptionType) => { |
|
if (this.blockOptionHover || this.state.focusedOption === focusedOption) { |
|
return; |
|
} |
|
this.setState({ focusedOption }); |
|
}; |
which calls setState;
- because the
setState was called the menu is rerendered and freshly calculated offset is applied:
|
const rect = getBoundingClientObj(controlElement); |
|
const scrollDistance = isFixed ? 0 : window.pageYOffset; |
|
const offset = rect[placement] + scrollDistance; |
Thanks,
Patryk.
P.S. Thanks for this awesome library!
When using
react-selectwithmenuPostion="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:
Is this an expected behaviour?
Here is what I found after digging into the code:
onOptionHovergets calledreact-select/packages/react-select/src/Select.js
Lines 1142 to 1147 in 32ad5c0
setState;setStatewas 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
Thanks,
Patryk.
P.S. Thanks for this awesome library!