How to style react-select options

前端 未结 6 1571
甜味超标
甜味超标 2020-12-24 02:20

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,

6条回答
  •  猫巷女王i
    2020-12-24 03:23

    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 {
          ...styles,
          backgroundColor: isDisabled ? 'red' : blue,
          color: '#FFF',
          cursor: isDisabled ? 'not-allowed' : 'default',
          ...
        };
      },
      ...
    };
    
    export default () => (
      
    


    MenuRender

    The menuRenderer property can be used to override the default drop-down list of options.

    optionClassName String The className that gets used for options

    Example: react-select/master/src/utils/defaultMenuRenderer.js

提交回复
热议问题