react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Hack: Showing dropdown on top of select input

Open shivpatel opened this issue 9 years ago • 9 comments

Saw some issues on this topic, but no activity or merged PRs. Here's a quick hack you can do to get the dropdown menu going in the up direction. Paste the following into your CSS file. Wrap your <Select /> component in a div with the select-up class included.

.select-up .Select-menu-outer {
    position: absolute !important;
    top: auto !important;
    bottom: calc(100% - 1px) !important;
    border-bottom-left-radius: 0px !important;
    border-bottom-right-radius: 0px !important;
    border-top-left-radius: 5px !important;
    border-top-right-radius: 5px !important;
}

.select-up .is-open .Select-control {
    border-top-right-radius: 0 !important;
    border-top-left-radius: 0 !important;
    border-bottom-right-radius: 5px !important;
    border-bottom-left-radius: 5px !important;
}

Example Usage:

<div className="select-up">
    <Select />
</div>

Preview: screen shot 2017-03-30 at 12 31 58 pm

shivpatel avatar Mar 30 '17 16:03 shivpatel

@JedWatson is this something we would like to support in react-select?

export-mike avatar Apr 02 '17 03:04 export-mike

@shivpatel This fix always opening the dropdown in up direction. Dropdown options should open only in up direction, if it reaches to the edge of the window.

kuppula-pmap avatar Apr 06 '17 10:04 kuppula-pmap

@kuppula-pmap This was designed to be a quick fix/hack for anyone that wanted to force an upward facing react select component in their app. See these issues (#1479, #1515) for progress on a real component-level fix.

shivpatel avatar Apr 06 '17 13:04 shivpatel

@shivpatel @JedWatson is there a component-level fix for this i need for my requirement too ..

BopaiahMD avatar Jun 21 '17 10:06 BopaiahMD

Hi, based on your idea with the CSS modification I created a quick-and-dirty wrapper component that performs some DOM node calculations and tries to estimate the visual height of the menu. When this estimate fits into the screen below the select element, the overlay is displayed below it, otherwise it is displayed above the select element.

https://gist.github.com/MartinHaeusler/6dfc3769df20f534a150efda39573f0d

This is really dirty stuff, but it "works for me". If you use different font heights etc. then you might need to adjust the constants.

This functionality (not my implementation of it, mind you) desperately needs to be part of react-select.

MartinHaeusler avatar Jul 08 '17 20:07 MartinHaeusler

these styles must go in as a prop to enable or disable! 👍 real nice hack @shivpatel

dixitk13 avatar Apr 18 '18 19:04 dixitk13

css not working for me

kinizumi avatar Aug 19 '19 20:08 kinizumi

add to