【问题标题】:Changing the arrow icon of "Select"更改“选择”的箭头图标
【发布时间】:2020-09-15 07:37:19
【问题描述】:

我想用 ant design (https://ant.design/components/icon/) 提供的图标替换默认的下拉选择箭头,例如 DownCircleOutlined。可能吗?这是我当前的代码。我还没有任何样式,因为我不知道方法。

<Select>
    <Option value="1">a</Option>
    <Option value="2">b</Option>
    <Option value="3">c</Option>
</Select>

【问题讨论】:

标签: reactjs select dropdown antd


【解决方案1】:

Select 组件上使用suffixIcon 属性。

https://codesandbox.io/s/select-with-search-field-ant-design-demo-k217c?file=/index.js:0-679

像这样:

import React from 'react'
import ReactDOM from 'react-dom'
import 'antd/dist/antd.css'
import './index.css'
import { Select } from 'antd'
import { DownCircleTwoTone } from '@ant-design/icons'
const { Option } = Select

ReactDOM.render(
  <Select
    suffixIcon={<DownCircleTwoTone />}
    showSearch
    style={{ width: 200 }}
    placeholder="Select a person"
    optionFilterProp="children"
    filterOption={(input, option) =>
      option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
    }
  >
    <Option value="jack">Jack</Option>
    <Option value="lucy">Lucy</Option>
    <Option value="tom">Tom</Option>
  </Select>,
  document.getElementById('container')
)

【讨论】:

  • suffixIcon onclick 没有打开下拉菜单,有什么解决办法吗?
  • @TechticSolutionsInc 将className="ant-select-suffix" 添加到您的组件中
  • 如何修改其颜色?
  • @ChervinTanilon 给DownCircleTwoTone 一个类名。检查元素。您将看到该图标的 html 结构应该是:.CLASSNAMEGIVEN > svg > path, path, path(3 个兄弟路径元素)您需要使用伪选择器来定位每个兄弟,例如nth-child() 并更改path 元素的fill 属性以修改图标颜色。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 2016-12-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多