-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Z-Index doesn't seem to be configurable #5329
Comments
EDIT: Sorry, I meant to mention in my comment that for the menuPortal approach to work, you need to be working with portals, and pass e.g. react-select.with.portals.and.z-index.mp4I believe you want to target <Select
...
styles={{
menuPortal: provided => ({
...provided,
zIndex: 100 // arbitrary z-index value, you should reference your z-index scale/strategy for this value
})
}}
/> The menu portal is the positioned container that holds the menu. Depending on your stacking context / z-index setup, you may need to use |
I opened a PR to address this late last year: #5830 |
Sorry, I meant to mention in my comment that for the menuPortal approach to work, you need to pass e.g. react-select.with.portals.and.z-index.mp4 |
It seems to me that if the expected setup is that That said, it really seems like overkill to require this, when a large z-index can be set by default, which is what my PR does. It solves this problem in a lot of cases, which makes the |
You can certainly accomplish handling z-index without portals, but portals are the most straightforward way without actually understanding z-index and stacking context. Setting a very high (even the highest possible) z-index on an element is often not enough to cause it to appear above other elements. For example, in this codepen, you have two parent elements, one has z-index of 1 ( Guess which child appears on top? The div with a z-index of 1, or of 1000? It's the div with a z-index of 1, because its parent established a new stacking context that is higher than that of its sibling, and setting a high z-index value of the sibling's child at that point will do nothing to make it appear on top. There are other gotchas with z-index as well that can cause new stacking contexts to be established that are unpredictable. So, just setting some arbitrary high z-index value is not helpful. You can certainly build your site's layout to avoid creating gotchas like that, but trying to build a generalized solution to this problem by just giving the select menu a high z-index won't do it. The default of 1 already places it above its sibling content given z-index is not set on other elements. Portals are a reliable way to solve this problem, and it's a feature that react-select provides. If you're careful with how you set up your layout in the first place, it's likely you can avoid needing to use z-index at all. But if you start running into complicated situations, you'll be happy to have the tool available. When you start messing with z-index such that your menu is not appearing on top of content around it, then either you need to dig into understanding your particular z-index situation, or you should reach for portals. Portals are also useful when your select is inside a container with Josh Comeau has a great (as always) piece on z-index if you'd like to learn more about it: https://www.joshwcomeau.com/css/stacking-contexts/ |
I agree that the react-select docs don't give an in-depth explanation of what portaling is or why you'd need it, or how do deal with z-index. From their docs
They're definitely letting "for layering purposes" do a lot of work there. They're assuming that if you have a z-index/layering issue, you will investigate other resources that will help you understand common solutions to the stacking problem, and then understand how to use the tools react-select provides for you. It's a complicated issue and it's not necessarily their job to teach you how z-index works. |
I'm not saying this project is or should be responsible for teaching anyone how z-index works. Failing that, the documentation should highlight portaling very early on if it's the intended solution to this not-uncommon problem. |
The bottom line is that the default menu z-index of 1 already does work for almost every situation where you're not setting your own z-index on other elements. |
I'm suggesting that there's almost no (or more likely: literally no) scenario where the react select menu should not be above other elements. So this seems like an odd decision. Seems like anyone wanting other elements to be rendered over the menu is a much less likely scenario - so that should be when people have to add workarounds, not "you have set any z-index on any element, therefore you have to also do something about this menu element". I'm also suggesting that even if that is the decision the maintainers want to go with, it needs to be better documented.
I'm happy to bump the value to |
I am using the latest version: 5.8.1 along with nextjs 14.2.15 and I solved this issue by adding a value in the global.scss:
It seems that the z-index value is set manually to 1 and overrides this setting, thus the need for I realize the above workaround may not work in the future, but for now its the only working solution I found. |
Thanks for using react-select!
If you are going to ask a question or want to propose a change or a new feature, then please don't file an issue for this.
Questions and feature requests have their own place in our discussions section.
Are you reporting a bug or runtime error?
A bug. No matter what I try, looking back at the examples nor at the previous issue queue, I cannot affect z-index whatsoever.
Code is fairly standard:
I've tried all sorts of style stuff, like this:
No luck.
This is in a React Native Web application, if that makes any difference.
How do I get z-index to work? If I put the z-index of everythingI want underneath the dropdown to
-1
it works, but that's obviously not a great solutionThe text was updated successfully, but these errors were encountered: