Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Antd AutoComplete to use {children} for both dataSource and input

Can I customize both 1) dataSource and 2) input when using {children} approach?

Docs say:

children (for customize input element)
customize input element
HTMLInputElement / HTMLTextAreaElement / React.ReactElement

children (for dataSource)
Data source for autocomplete
React.ReactElement / Array

I got it working using one or the other but not both. Really annoying that is no renderOption attribute or something similar...

like image 380
Philipp Kyeck Avatar asked Nov 27 '25 02:11

Philipp Kyeck


1 Answers

If you want to use both, you can write something like this:

const results = dataSource.map(x => (
  <Select.Option key={x} {/* props you want */}>{x}</Option>
))

<AutoComplete dataSource={results}>
  <Search placeholder="Search..." />
</AutoComplete>
like image 144
chonnychu Avatar answered Nov 29 '25 15:11

chonnychu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!