Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change react-select color

I'm unsure how to change the color from the default blue to something else. The example code is in the codesandbox link below. I tried changing the styling for root, but had no success.

https://codesandbox.io/s/ly87zo23kl

like image 240
Snoopy Avatar asked Oct 25 '18 17:10

Snoopy


People also ask

How do you select colors in react?

In react v3, style components have confusing names: neutral0 sets background, primary25 sets highlight and neutral80 sets selected text color. Non-selected text color can be set by setting color: '#ffffff' on the parent element.

How do I change my click react color?

To change background color on click in React: Set the onClick prop on the element. When the element is clicked, set the active state. Use a ternary operator to conditionally set the background color based on 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.

How can react select an item and change the background color?

– DDCODE How can react select an item in the list and change the background color? If you want to change the background color of a selected row in the click list and click this item, cancel it. However, this is the real dom operation after dom rendering.

How to use the color picker in ReactJS?

To use the color picker in your ReactJS project, you must first install the react-color module. So, on your terminal, type the command below to install the module. 2. Now import the module into your app.js file or the component where you wish to use it.

How do I get the styles of each component in react?

Each component gets passed a getStyles method which has the following signature: The key is a lowercased string value corresponding to the component that the styles apply to, i.e. option for the Option component, menuplacer for the MenuPlacer component.

How to change the background color of selected row in ClickList?

If you want to change the background color of a selected row in the click list and click this item, cancel it. However, this is the real dom operation after dom rendering. Is the real dom capable of using setState


1 Answers

Version 2.1.0 of react-select has added the option to override the theme.

Here an example of how it works:

<Select
    defaultValue={flavourOptions[0]}
    label="Single select"
    options={flavourOptions}
    theme={(theme) => ({
      ...theme,
      borderRadius: 0,
      colors: {
      ...theme.colors,
        text: 'orangered',
        primary25: 'hotpink',
        primary: 'black',
      },
    })}
  />

You can find here the complete documentation and live example and here the different variables that can be overwritten.

like image 200
Laura Avatar answered Sep 21 '22 18:09

Laura