Dropdown in semantic ui can't be made of multiple selection type when wrapped with styled-components

让人想犯罪 __ 提交于 2020-12-15 09:02:05

问题


I am using react semantic ui Dropdown:

https://react.semantic-ui.com/modules/dropdown/

and styled-components:

https://styled-components.com/

And when I do the following (in React render method), it works well:

          <Dropdown
            placeholder="Select tags"
            multiple
            fluid
            selection
            options={tagOptions}
            onChange={this.navigateToTag}
          />

I can select multiple items in it. But now I am trying to style it the following way:

const SelectTagsDropdown = styled(Dropdown)`
  margin: ${props => props.margin || '1em 0em 1em 0em'}
`

and then in render:

          <SelectTagsDropdown
            placeholder="Select tags"
            multiple
            fluid
            selection
            options={tagOptions}
            onChange={this.navigateToTag}
          />

And it becomes not multiple with only one selection possible. How to still make it multiple? I tried supplying it in attrs like this:

styled(Dropdown).attrs({ multiple: true, selection: true, fluid: true })

and also directly in the styled properties:

const SelectTagsDropdown = styled(Dropdown)`
  margin: ${props => props.margin || '1em 0em 1em 0em'};
  multiple: ${props => props.multiple};
`

But neither is working.


回答1:


I was able to style the Dropdown but indirectly by styling the Grid.Row that everything was wrapped in:

const ControlRow = styled(Grid.Row)`
  .multiple.selection.dropdown {
      margin: 1em 0em 1em 0em !important;
  }
`

And then html:

    <ControlRow>
        <Grid.Column width={5}>
          <Dropdown
            multiple
            fluid
            selection
            options={myOptions}
            onChange={this.navigateToMyFunc}
          />
     ...
     ...


来源:https://stackoverflow.com/questions/59846128/dropdown-in-semantic-ui-cant-be-made-of-multiple-selection-type-when-wrapped-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!