What\'s the best way to style a react-select component\'s (https://github.com/JedWatson/react-select) options?
I can target the select itself just fine,
This new version introduces a new styles-api and some other major changes.
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 {
...styles,
backgroundColor: isDisabled ? 'red' : blue,
color: '#FFF',
cursor: isDisabled ? 'not-allowed' : 'default',
...
};
},
...
};
export default () => (
);
Now there is better documentation and more clear examples on the project's website:
https://react-select.com/upgrade-guide#new-styles-api
https://react-select.com/home#custom-styles
https://react-select.com/styles#styles
You can provide a custom className prop to the component, which will be added to the base .Select className for the outer container. The built-in Options renderer also support custom classNames.
Add your customclassName as a property to objects in the options array:
const options = [
{label: "one", value: 1, className: 'custom-class'},
{label: "two", value: 2, className: 'awesome-class'}
// more options...
];
...
The menuRenderer property can be used to override the default drop-down list of options.
optionClassName
StringThe className that gets used for options
Example: react-select/master/src/utils/defaultMenuRenderer.js