Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic menu placement sometimes not correct within a scroll container #5502

Open
oschwede opened this issue Dec 1, 2022 · 2 comments
Open
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet

Comments

@oschwede
Copy link

oschwede commented Dec 1, 2022

The placement calculations for automatic menu placement seem to be wrong for some cases since #5177 has been merged.

Example codesandbox:
https://codesandbox.io/s/react-select-v5-sandbox-forked-8sgyet

Steps to reproduce:

  1. Have a scroll container that does not span the full window/viewport height
  2. Render the near at the bottom of that scroll container
  3. If the menu is opened, the MenuPlacer should let the menu flip and show on top of the select

Instead, the menu opens below, sometimes even increasing the scrollable area.

Possible cause:
https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/components/Menu.tsx#L94
The computation of viewSpaceBelow seems incorrect when the scroll container's top edge is different from the windows top edge: menuTop comes from a call to getBoundingClientRect(), which gives the top offset relative to the viewport. When located in a scroll container, menuTop should actually be the top offset of the menu relative to the scroll parent, so that the comparison with viewHeight (the scrollParent height) returns the true view space available below the select.

Not sure which computation would give better results, I think menuTop should be relative to the scrollParent, not the viewport so that other computations remain correct. So something like
const menuTop = isFixedPosition ? menuEl.getBoundingClientRect().top : menuEl.getBoundingClientRect().top - scrollParent.getBoundingClientRect().top

I'm also willing to contribute a PR, but a good solution should be discussed first.

@oschwede oschwede added the issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet label Dec 1, 2022
@jainishp6
Copy link

facing the same issue as well.

@malakutsko
Copy link

malakutsko commented Feb 20, 2023

I'm facing the same issue, but in my case the select with half of the menu is scrolled out of the view by this line: https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/components/Menu.tsx#L161

I forked the sandbox of @oschwede to reproduce it: https://codesandbox.io/s/react-select-v5-sandbox-forked-1m3qjv
The issue is reproducible by opening the top most select element.
The main difference to the original sandbox is that my container has position: "relative".

@oschwede, I think you are right about the cause. I came to the same conclusion while debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/bug-unconfirmed Issues that describe a bug that hasn't been confirmed by a maintainer yet
Projects
None yet
Development

No branches or pull requests

3 participants