AutoComplete components allow users to select items from a defined list. The input field acts as a search box and will narrow the list of items presented based on matches against the entered text.
AutoComplete shows an expand/collapse toggle button to make the users aware that a list of values exists.
Basic rendering uses text strings from the data
property to render list items and input text. The default is to use the id
value for item keys and the text
value for display text.
To render custom content for list items and input text, use the dataRendering
property.
To include a header, add an object in the data array with the header
property set to the text of the header. To include a divider (separator), add an object in the data array with the divider
property set to true
. To make a list item disabled, add a disabled
property set to true
to the object in the data array.
The loadingMsg
property can be used to add a Spinner to the dropdown loading animation.
To use infinite scrolling, the consumer must provide and call the required data using the infinite
object. The onLoadMore
callback is triggered near the bottom of the dropdown to allow for more data to be fetched. The new data should be appended to the previous data
property. To stop infinite scrolling or stop fetching data, change hasMore
to false
.
Use the disabled
property to disable the Autocomplete component. A disabled element is unusable and un-clickable.
ReadOnly is not a supported state for the Autocomplete component.
Property | Type | Default | Description |
---|---|---|---|
noResultsMsg | String or Object | Required | Displayed when no data items match entered text. If a string is used, it will display that text. If an object is used, it has props for title (primary text) and description (secondary text). |
dropdownTriggerLabel | String | Required | Localized assistive text for the dropdown trigger button. |
active | Node | Node of the active item. | |
className | String | Custom classes to be added to the <input> tag. | |
data | Array | Raw data for the dropdown items. Each element in the array (in JSON format) represents an item in the dropdown. For default rendering of list items, each item should have keys for id and text . For custom rendering of list items, see dataRendering . | |
dataRendering | Object | Enables custom rendering. See dataRendering for details about the available properties. | |
disabled | Boolean | false | Controls whether the component is enabled or disabled. |
flipContainer | Element or Element[] | Used to create a boundary for the underlying Popper to stay within. | |
infinite | Object | Defines the properties for infinite scrolling. See infinite for more details. | |
inputRef | Ref or Function | Attach a ref to the <input> element. | |
isLoading | Boolean | false | When true, loadingMsg will be displayed. |
isOpen | Boolean | false | When true, the input dropdown will be opened automatically on creation. |
itemKey | String or Function | 'id' | Used to identify the unique key for a list item. If a string is used, it identifies the field in the data to use as the key value for the list item. If a function is used, it must return the key value for the list item. The function will be passed the row of data (in JSON format). |
loadingMsg | Node | Displayed while data is loading. Must be non-empty if isLoading is true. | |
mruData | Array | Raw data for the most-recently used (MRU) items (in JSON format). For simple rendering of list items, each item should have keys for id and text . For custom rendering of list items, see dataRendering . | |
mruTitle | String | Title of MRU section inside dropdown menu. | |
placeholder | String | Placeholder displayed when input field is empty. | |
popperClassName | String | Custom classes to be added to the popper <div> element. | |
popperPlacement | String or String[] | Placement of the dropdown relative to the input element. Options are 'top' , 'top-start' , 'top-end' , 'bottom' , 'bottom-start' , 'bottom-end' , 'left' , 'left-start' , 'left-end' , 'right' , 'right-start' , 'right-end' . See Popover Placement for a more detailed description of the values. | |
required | Boolean | false | Adds the required attribute to the <input> element. NOTE: This does not perform any validation, but rather just marks the field as required. |
size | String | 'lg' | Component size. Options are 'lg' , 'md' and 'sm' . |
showAllOnFocus | Boolean | true | If true, dropdown menu opens automatically when component receives focus. If false, dropdown menu will not open until at least one character is entered (or more, depending on the value of showAllOnFocusThreshold . |
showAllOnFocusThreshold | Number | 0 | Minimum number of characters that must be entered before the autocomplete menu is displayed. |
targetClassName | String | Custom classes to be added to the target/reference <div> wrapper element. | |
validationMessage | Object | An object identifying a validation message. The object will include properties for state and text ; e.g., { state: 'warning', text: 'This is your last warning' } . The options for state are 'error' and 'warning' . text is the message shown in the validation tooltip; as with all text, it must be localized. | |
validationMessageType | String | This will determine how the validation message will appear. Options are 'iconAligned' , a tooltip from the warning or error icon, or 'inputAligned' , an overlay displaying underneath the input. | |
value | String | Initial (default) value of input field. | |
widthSizingType | String | 'minTarget' | The width of the popper component relative to the target. Options are 'none' ,'matchTarget' ,'minTarget' ,'maxTarget' |
Property | Parameters | Description |
---|---|---|
onBlur | event | Callback function for input field onBlur. Will be called only if input field loses focus and the Dropdown popover is closed. |
onChange | event | Callback function for input field onChange. |
onDropdownClose | event | Callback function for onDropdownClose. |
onDropdownTriggerClick | event | Callback function for onClick on the dropdown trigger button. |
onFocus | event | Callback function for input field onFocus. |
onKeyDown | event | Callback function for input field onKeyDown. |
onMouseDown | event | Callback function for input field onMouseDown. |
onSelect | item | Callback function for onSelect. |
Property | Type | Default | Description |
---|---|---|---|
inputRenderer | String or Function | 'text' | Used to render text in the input for a selected item. If a string is used, the value for that key (from data or mruData ) will be shown. If a function is used, it must return the text to display in the input field. The function will be passed the row of data (in JSON format). |
listItemRenderer | String or Function | 'text' | Used to render content for each list item in the dropdown. If a string is used, the value for that key (from data or mruData ) will be shown. If a function is used, it must return a valid node. The function will be passed the row of data (in JSON format). |
Property | Type | Default | Description |
---|---|---|---|
hasMore | Boolean | true | Sets whether there are more items to be loaded. Event listeners are removed if set to false . This can also be used to disable infinite loading. NOTE: Setting hasMore to true emits a loading message. Having bothisLoading and hasMore set to true will result in multiple loading messages. |
isInitialLoad | Boolean | true | Sets whether the component should load the first set of items when opened. |
pageStart | Number | 0 | The number of the first page to load. With the default of 0, the first page is loaded. |
threshold | Number | 250 | The distance in pixels from the bottom of the scroll area before a call to onLoadMore is triggered. |
Property | Parameters | Description |
---|---|---|
onLoadMore | pageNumber | A callback when more items are requested by the user. Provides a single parameter specifying the page to load. |