Why can I not use value/label data structure with Autocomplete/TagsInput?
Last updated
Data structure
Autocomplete and TagsInput allow user entering any string value – the selection is not limited to predefined list of options. If you decide to use these components, your application must handle free user input.
Example of Autocomplete usage with data prop:
In this example, the user can select either React or Vue from the list of options
or enter any other string value, for example, Angular.
Value/label data split
Unlike Select and MultiSelect
components data in { value: string; label: string; } is not supported in Autocomplete and TagsInput.
It is done on purpose to avoid confusion and make it clear that user can enter any string value.
Consider the following example:
If Autocomplete would support { value: string; label: string; } data structure:
- When user selects
Reactfrom the list,18361will be logged to the console - When user selects
Vuefrom the list,09411will be logged to the console - When user enters
Angularor any other value not present in the list, what should be logged to the console? - When user enters
React, should18361be logged to the console or should it be treated as free user input?
To avoid confusion and make it clear that user can enter any string value, Autocomplete and TagsInput
do not support { value: string; label: string; } data structure.
Difference between Autocomplete and Select
If you need to limit user input to predefined list of options, consider using searchable Select instead. To learn more about the difference between Autocomplete and Select components, check out this guide.