Skip to content

Menu is re-rendering after scrolling the page and trying to click on an option #4159

@Wojtasik

Description

@Wojtasik

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue/needs-reviewissue/reviewedIssue has recently been reviewed (mid-2020)menu-bugAddresses menu positioning, scrolling, or general interactions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions