React JS : React Select Dropdown position to top if there is no space below
You can use menuPlacement option on your Select component with “bottom” (default), “top” or “auto”. You can see other props here 😉
You can use menuPlacement option on your Select component with “bottom” (default), “top” or “auto”. You can see other props here 😉
react-select allows us to control components by doing components={{ IndicatorSeparator: () => null }} For example: <Select id=”search-commodity” options={comodityOptions} components={{ IndicatorSeparator: () => null }} />
Inline styles did not work for me. I just wrapped the Select component in a div and gave the div the width I wanted. <div style={{width: ‘300px’}}> <Select menuPlacement=”auto” menuPosition=”fixed” etc, etc.. /> </div>
On Cypress 4.2.0 and react-select 3.0.8 pressing enter twice is working for me: cy.get(‘#react-select-component-id’).type(‘Something{enter}{enter}’);
For a majority of use cases, you probably don’t need to replace the full Option component. If you’re looking to stay with the same overall structure and look and feel of the Option, but you want to display several blocks of text, or an image, or some other special treatment to the body of each … Read more
This is a recurrent question. I’m sharing my own code with 100% passing tests which cover 100% of my source code. My component looks like this MySelectComponent({ options, onChange }) { return <div data-testid=”my-select-component”> <Select className=”basic-single” classNamePrefix=”select” name=”myOptions” placeholder=”Select an option” options={options} onChange={e => onChange(e)} /> </div>; } The reason I’m adding a wrapper on … Read more
Spending hours, I end up with this to get exact 30px height of react select with border 1px: const customStyles = { control: (provided, state) => ({ …provided, background: ‘#fff’, borderColor: ‘#9e9e9e’, minHeight: ’30px’, height: ’30px’, boxShadow: state.isFocused ? null : null, }), valueContainer: (provided, state) => ({ …provided, height: ’30px’, padding: ‘0 6px’ }), … Read more
options is the magic key: render() { const options = [ { label: “Group 1”, options: [ { label: “Group 1, option 1”, value: “value_1” }, { label: “Group 1, option 2”, value: “value_2” } ] }, { label: “A root option”, value: “value_3” }, { label: “Another root option”, value: “value_4” } ]; return … Read more
We can remove the dropdown indicator by including DropdownIndicator: () => null in components property. Update:As @shlgug and @nickornotto suggested remove separator by including IndicatorSeparator:() => null <Select components={{ DropdownIndicator:() => null, IndicatorSeparator:() => null }} />
react select v2 (update) This new version introduces a new styles-api and some other major changes. Custom Styles Style individual components with custom css using the styles prop. const colourStyles = { control: styles => ({ …styles, backgroundColor: ‘white’ }), option: (styles, { data, isDisabled, isFocused, isSelected }) => { const color = chroma(data.color); return … Read more