如何在菜单下拉react-select中删除顶部填充?

时间:2019-08-01 12:34:18

标签: reactjs react-select

如何在菜单下拉react-select中删除顶部填充?

const customStyles = {

    indicatorSeparator: styles => ({ ...styles, display: "none" }),
    option: (provided, state) => ({
      ...provided,
      fontSize: 16,

        height:"40px",
      paddingLeft: "11px",
      ":firstChild": {
        margin: "10px",
        padding: "10px",
        borderRadius: "10px 10px 10px 10px"

    }),



 <Select
    styles={customStyles}
    defaultValue={[colourOptions[2], colourOptions[3]]}
    isMulti
    name="colors"
    options={colourOptions}
    className="basic-multi-select"
    classNamePrefix="select"
  />

enter image description here https://codesandbox.io/s/react-codesandboxer-example-90zz6

3 个答案:

答案 0 :(得分:2)

您应根据反应选择docs来设置menuList样式键的样式。

menuList: (provided, state) => ({
   ...provided,
   paddingTop: 0,
   paddingBottom: 0,
}),

答案 1 :(得分:1)

通过使用{[firststyle,secandstyle]}使用此多内联样式 并将第二种样式定义为

之后的形状
 `const nopadinng={
      paddingTop:0};`

and remove  the classname

    // remove the className 
        className="basic-multi-select"


    const nopadinng={
      paddingTop:0};
            styles={[customStyles,nopadinng]}

答案 2 :(得分:1)

可以使用道具margin-top轻松删除菜单列表和选择框之间的默认styles

const styles = {
  menu: base => ({
    ...base,
    marginTop: 0
  })
}

实时example here