React JS : React Select Dropdown position to top if there is no space below
21,824
Solution 1
You can use menuPlacement
option on your Select component with "bottom" (default), "top" or "auto".
You can see other props here ;)
Solution 2
<Select
menuPlacement="top"
...
/>
You can use menuPlacement
prop top
, bottom
or auto
Solution 3
Inside component:
render() {
const className = this.state.dropUp ? 'drop-up' : '';
return (
<Select {...this.props} className={className} />
);
}
And in css file:
.drop-up .Select-menu-outer {
top: auto;
bottom: 100%;
}
Related videos on Youtube
Author by
Xperia Reno
Updated on July 09, 2022Comments
-
Xperia Reno almost 2 years
I am using React Select
I want its Dropdown position to be dynamic. let's say if there is no space below it, then the dropdown should be opened to above select box.
<Select value={selectedOption} onChange={this.handleChange} options={options} />
Is there any option to make dropdown position dynamic?
Any help would be great.
Thank You.
-
Karthick Vinod almost 4 yearsWhich version of react-select are you using? v3?
-
Xperia Reno almost 4 yearsI am using Version 3.1.0
-
-
Admin almost 4 yearsside note: you can make state value of dropup false by window size
-
Chase Sandmann about 3 yearsIt's usually fine to make the cheeky "check the docs ;)" comment, but the React Select docs are honestly terrible to search through. It took me hours to find this prop
-
Manny Alvarado almost 2 yearsThat prop doesn't work, at least for asyncs. It's an unresolved issue on their end.