- dropdown
- search with value coming back via prop
- navigate the list up/down with arrow up/down
- select any item with Enter
- select / navigate with mouse
- selected item is returned via prop
- height = pixels, just enter the number
- items = array of objects that must have jsx property:
[{jsx: <div>some text</div>, yourCustom: 123}, {...}]
- onInputChange = function to get new value of the search field
- onSelected = function to get selected item back. It will return original item like:
{jsx: <div>some text</div>, yourCustom: 123}
import AutoComplete from 'components/AutoComplete';
...
let items = [];
for (let index = 1; index <= 20; index++) {
items.push({
value: `some value ${index}`,
jsx: <div>Item <strong>strong!</strong> {index}</div>
});
}
...
<AutoComplete
items={items}
onSelected={(selected) => console.log('selected: ', selected)}
onInputChange={(item) => console.log('item: ', item)}
/>
...
npm i prop-types --save
From official ReactJs docs: React.PropTypes is deprecated linknpm i react --save
npm i @blueprintjs/core --save
You can easily modify and remove 3rd, but while i was using this lib while building https://www.geekystats.com/ it's there.
I needed auto complete field and blueprint doesn't have it yet. I've created my own, you can use it for whatever needed.