Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change zIndex in react-select drowpdown

I am using the react-select library to create autocomplete drop-down. I have used 2 drop-down parallel if 2nd has some data & I open first one then the zIndex problem comes. see the imageenter image description here

like image 370
Khushboo Avatar asked Apr 24 '19 13:04

Khushboo


People also ask

How do I change the placeholder in react-select?

Set the first option element of the select tag to disabled and give it an empty string value. Initialize the state for the select tag to an empty string.

How do I change the selected value in react JS?

To handle the onChange event on a select element in React: Set the onChange prop on the select element. Keep the value of the selected option in a state variable. Every time the user changes the selected option, update the state variable.

How do I change the background color in react-select?

To set the background color for react-select drop downs, we can return an object with the color values set. We set the styles prop to the customStyles object which has various styles. The control method in the object returns an object with the style values.


2 Answers

Add these lines in your all Select tag:

<Select      // other props     menuPortalTarget={document.body}      styles={{ menuPortal: base => ({ ...base, zIndex: 9999 }) }} /> 
like image 142
hemant rao Avatar answered Oct 03 '22 20:10

hemant rao


Try this hacky way of setting zIndex, and let me know if it worked :)

<Select   styles={{     // Fixes the overlapping problem of the component     menu: provided => ({ ...provided, zIndex: 9999 })   }}   value={selectedOption}   onChange={evt => onSelectChange(evt, index)}   options={options} /> 
like image 20
Vicente Avatar answered Oct 03 '22 21:10

Vicente