Autocomplete
Usage
Controlled
Data prop
Autocomplete support two different data formats:
- An array of strings
- An array of objects with required
value
property and any other additional properties
Dynamic data
data
prop can have dynamic values:
Custom item component
Autocomplete item component and filtering logic can be changed. To do so:
- Add extra props to
data
objects - Create
filter
function which determines whether item should be added to the search results - Provide
itemComponent
which will consumedata
objects
data
prop must be an array of objects with required value
field:
Then define custom filter
function and itemComponent
which will consume data:
Limit amount of options
By default, Autocomplete will render 5 items at a time, to change that set limit
prop:
Dropdown position
By default, dropdown is placed below the input and when there is not enough space, it flips to be above the input.
To change this behavior, set dropdownPosition
prop:
Animations
By default, dropdown animations are turned off to increase responsiveness. To enable animations set the following optional props:
transition
– premade transition name or custom transition styles object, see Transition component for all available optionstransitionDuration
– transition duration in ms, defaults to 0transitionTimingFunction
– defaults totheme.transitionTimingFunction
With icon
Invalid state and error
Disabled state
Input props
Component supports all props from Input and InputWrapper components:
Get input ref
Accessibility
Provide aria-label
in case component does not have a label for screen reader support: