question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

zIndex on document.body (dropdown)

See original GitHub issue

Is there a way that we can assign a class inside menu container? Currently I used below code to open dropdown and attach to body.

menuPortalTarget={document.body}

the problem for this is the init div (dropdown) z-index is 1 by default and class name default is something css-*(randomly). I wonder that I can just assign my own class something similar like classNamePrefix ?

The issue now is dropdown menu is hidden on modal popup. I was trying to change the zIndex but have no solution yet.

Please advise, thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

50reactions
ZackKnoppcommented, Sep 12, 2018

From their example of portalling you can pass styles to the menuPortal component, see here

styles={{ menuPortal: base => ({ ...base, zIndex: 9999 }) }}

Full component example:

<Select
  defaultValue={colourOptions[0]}
  isClearable
  styles={{ menuPortal: base => ({ ...base, zIndex: 9999 }) }}
  menuPortalTarget={document.body}
  isSearchable
  name="color"
  menuPosition={isFixed ? 'fixed' : 'absolute'}
  menuPlacement={portalPlacement}
  options={colourOptions}
/>
4reactions
folkjccommented, May 21, 2019
const customStyles = {
            container: (base, state) => {
                return ({
                    ...base,
                    zIndex: state.isFocused ? "999" : "1"  //Only when current state focused
                })
            }
        }

return <Select 
   styles={customStyles}
/>

Since we only need the zIndex to be high when the component is focused, use a conditional styling for the container. Otherwise if you happen to have multiple <Select /> components (or other components requiring a high zIndex) it might cause problems if all of them have the same 999 zIndex.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change zIndex in react-select drowpdown
Add these lines in your all Select tag: <Select // other props menuPortalTarget={document.body} styles={{ menuPortal: base => ({ ...base, ...
Read more >
Diagnosis: z-index (submenu hidden behind content)
jQuery/javascript errors ... [+] Submenus (dropdowns) not displaying ... The z-index property of an element determines how an element will be layered ...
Read more >
z-index - CSS: Cascading Style Sheets - MDN Web Docs
The z-index CSS property sets the z-order of a positioned element and its descendants or flex items. Overlapping elements with a larger ...
Read more >
HTML DOM Style zIndex Property - W3Schools
The zIndex property sets or returns the stack order of a positioned element. An element with greater stack order (1) is always in...
Read more >
Z-Index Problems: My buttons show up on top of my dropdown ...
document.getElementById("desc"+i.toString()).innerHTML = "Taken On:"+imagedescriptions[(4*pageIndex)+i-1];. document.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found