我正在尝试在 react select 的输入元素前面添加一个图标。我能够在占位符中获取图标,但占位符的问题是当我从下拉列表中选择一些数据时,占位符图标会被删除。我需要一些帮助来获取 Select 语句前面的图标。
这是我到目前为止所取得的成就的代码
import React, { Component } from 'react'
import Select, { components } from 'react-select'
export default class InfluencersForm extends Component {
constructor(){
super();
this.handleInfluencerName = this.handleInfluencerName.bind(this);
}
handleInfluencerName(event){
console.log(event)
}
render() {
const influencers = [
{ value: 'abc', label: 'abc' },
{ value: 'def', label: 'def' }
]
const DropdownIndicator = (props) => {
return components.DropdownIndicator && (
<components.DropdownIndicator {...props}>
<i className="fa fa-search" aria-hidden="true" style={{ position: 'initial' }}></i>
</components.DropdownIndicator>
);
};
return (
<div>
<div>
<Select
options={influencers}
isMulti={false}
onChange={this.handleInfluencerName}
isSearchable={true}
components={{ DropdownIndicator }}
placeholder={placeholderComponent}
classNamePrefix="vyrill"/>
</div>
</div>
)
}
}
const placeholderComponent = (
<div>
<i className="fa fa-search" aria-hidden="true" style={{ position: 'initial' }}></i>
I am placeholder
</div>
);