the*_*hme 9 font-awesome reactjs react-select
我正在尝试将用于react-select多选指示器的图标更改为字体很棒的图标,但它不起作用。知道为什么吗?
import React from "react";
import Select, { components } from "react-select";
import { colourOptions } from "./docs/data";
const Placeholder = props => {
return <components.Placeholder {...props} />;
};
const CaretDownIcon = () => {
return <i className="fas fa-caret-down" />;
};
const DropdownIndicator = props => {
return (
<components.DropdownIndicator {...props}>
<CaretDownIcon />
</components.DropdownIndicator>
);
};
export default () => (
<Select
closeMenuOnSelect={false}
components={{ Placeholder, DropdownIndicator }}
placeholder={"Choose"}
styles={{
placeholder: base => ({
...base,
fontSize: "1em",
color: colourOptions[2].color,
fontWeight: 400
})
}}
options={colourOptions}
/>
);
Run Code Online (Sandbox Code Playgroud)
item 标签显示在 DOM 中,但我没有看到图标。
Lau*_*ura 20
我建议您查看Font Awesome for React的文档。
为了达到预期的结果,我最终得到了以下代码:
import React from "react";
import ReactDOM from "react-dom";
import Select, { components } from "react-select";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCaretDown } from "@fortawesome/free-solid-svg-icons";
import { library } from "@fortawesome/fontawesome-svg-core";
library.add(faCaretDown);
const CaretDownIcon = () => {
return <FontAwesomeIcon icon="caret-down" />;
};
const DropdownIndicator = props => {
return (
<components.DropdownIndicator {...props}>
<CaretDownIcon />
</components.DropdownIndicator>
);
};
function App() {
return (
<div className="App">
<Select
closeMenuOnSelect={false}
components={{ Placeholder, DropdownIndicator }}
placeholder={"Choose"}
options={colourOptions}
/>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
这是你想要的一个活生生的例子。
| 归档时间: |
|
| 查看次数: |
17820 次 |
| 最近记录: |