Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reduce the size of React Select in v2

Tags:

react-select

The new v2 react-select control is great, but by default is too large. Is there a (preferably) simple way to reduce the height to the same as a standard select control (using Bootstrap v3)?

like image 576
Darren Oster Avatar asked Apr 16 '18 02:04

Darren Oster


People also ask

How do you reduce the size of react select?

Read the react-select docs HERE. React-Select v2 uses emotion CSS-in-JS so the new way to control style over the select components and sub-components is by passing a style object to the styles prop. You can also set a className to style with an external stylesheet.

How do you style select options in react?

To style react-select drop down options, we can create an object with the styles we want to apply and set that as the value of the styles prop. We create the colourStyles object with the control method that return an object with the styles. And we have the option method that returns the styles for the options.


2 Answers

Try passing in a value for the maxMenuHeight prop:

<Select
  maxMenuHeight={190}
/>

see documentation

like image 57
ryanrain Avatar answered Sep 18 '22 13:09

ryanrain


The answer below was given when react-select v2 was in beta, much has changed since then.

Read the react-select docs HERE

React-Select v2 uses emotion CSS-in-JS so the new way to control style over the select components and sub-components is by passing a style object to the styles prop. You can also set a className to style with an external stylesheet.

CSS-in-JS way

const customControlStyles = base => ({
    height: 20,
    minHeight: 20
});

<Select ... styles={{control: customControlStyles}} ... />

CSS Way <Select ... className="myClassName" ... />

.myClassName__control {
    height: 20px;
    min-height: 20px;
}
like image 28
Evan Hennessy Avatar answered Sep 22 '22 13:09

Evan Hennessy