Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Placeholder Component React-Select

Tags:

react-select

How can I set a custom placeholder element?

I'd like to add a search icon when the field is empty

Thanks.

like image 625
bernatfortet Avatar asked Nov 02 '17 14:11

bernatfortet


2 Answers

TLDR; I just figured out that I can just simply pass a component

I guess I did not get that a node could be a component.

The documentation indicates:

placeholder - type: string|node

The following line comes from the source. As you see, it allows a component to be passed.

return !this.state.inputValue ? <div className="Select-placeholder">{this.props.placeholder}</div> : null;

So I can use

<Select placeholder={<div>Type to search</div>} />
like image 122
bernatfortet Avatar answered Sep 20 '22 18:09

bernatfortet


<Select placeholder={Type to search} />

works

like image 27
Byorn Avatar answered Sep 20 '22 18:09

Byorn