React Autocomplete Component API
Autocomplete API
Explore the API reference for the React Autocomplete component and discover how to effectively utilize its props for customization.
CAutocomplete#
import { CAutocomplete } from '@coreui/react-pro'// orimport CAutocomplete from '@coreui/react-pro/src/components/autocomplete/CAutocomplete'
Property | Default | Type |
---|---|---|
allowOnlyDefinedOptions# | false | boolean |
Only allow selection of predefined options. When | ||
className# | - | string |
A string of all className you want applied to the base component. These classes will be merged with the default React autocomplete classes. | ||
cleaner# | false | boolean |
Enables selection cleaner element. When | ||
clearSearchOnSelect# | true | boolean |
Whether to clear the internal search state after selecting an option. | ||
container# | - | Element , DocumentFragment , (() => Element | DocumentFragment) |
Specifies the DOM element where the dropdown should be rendered when using portal mode. Can be a DOM element reference, DocumentFragment, function that returns an element or null, or null (renders to document body). Works in conjunction with the | ||
disabled# | - | boolean |
Toggle the disabled state for the component. When | ||
feedback#4.2.0+ | - | ReactNode |
Provide valuable, actionable feedback. | ||
feedbackInvalid#4.2.0+ | - | ReactNode |
Provide valuable, actionable feedback. | ||
feedbackValid#4.2.0+ | - | ReactNode |
Provide valuable, actionable invalid feedback when using standard HTML form validation which applied two CSS pseudo-classes, | ||
highlightOptionsOnSearch# | false | boolean |
Highlight options that match the search criteria. When | ||
id# | - | string |
Set the id attribute for the native input element. This id is used for accessibility purposes and form associations. If not provided, a unique id may be generated automatically. | ||
indicator# | - | boolean |
Show dropdown indicator/arrow button. When | ||
invalid# | - | boolean |
Set component validation state to invalid. | ||
label#4.2.0+ | - | ReactNode |
Add a caption for a component. | ||
loading# | - | boolean |
When set, the options list will have a loading style: loading spinner and reduced opacity. Use this to indicate that options are being fetched asynchronously. The dropdown remains functional but shows visual loading indicators. | ||
name# | - | string |
The name attribute for the input element. Used for form submission and identification in form data. Important for proper form handling and accessibility. | ||
onChange# | - | (option: Option) => void |
Execute a function when a user changes the selected option. Called with the selected option object or | ||
onHide# | - | () => void |
The callback is fired when the dropdown requests to be hidden. Called when the dropdown closes due to user interaction, clicks outside, escape key, or programmatic changes. | ||
onInput# | - | (value: string) => void |
Execute a function when the filter/search value changes. Called whenever the user types in the search input. Useful for implementing external search functionality or analytics. | ||
onShow# | - | () => void |
The callback is fired when the dropdown requests to be shown. Called when the dropdown opens due to user interaction, focus, or programmatic changes. | ||
options# | - | (Option | OptionsGroup)[] |
List of option elements. Can contain Option objects, OptionsGroup objects, or plain strings. Plain strings are converted to simple Option objects internally. This is a required prop - the React autocomplete needs options to function. | ||
optionsGroupsTemplate# | - | (option: OptionsGroup) => ReactNode |
Custom template for rendering option groups. Allows customization of how option group headers appear in the dropdown. The function receives an OptionsGroup object and should return a ReactNode. | ||
optionsMaxHeight# | auto | string , number |
Sets maxHeight of options list. Controls the maximum height of the dropdown options container. Can be a number (pixels) or a CSS length string (e.g., '200px', '10rem'). When content exceeds this height, a scrollbar will appear. | ||
optionsTemplate# | - | (option: Option) => ReactNode |
Custom template for rendering individual options. Allows complete customization of how each option appears in the dropdown. The function receives an Option object and should return a ReactNode. | ||
placeholder# | - | string |
Specifies a short hint that is visible in the search input. Displayed when the input is empty to guide user interaction. Standard HTML input placeholder behavior. | ||
portal# | false | boolean |
Renders the autocomplete dropdown in a React portal, allowing it to break out of its parent container's styling constraints (like overflow, z-index, or positioning). When enabled, the dropdown is rendered at the document root level, ensuring it appears above other page elements and isn't clipped by parent containers. | ||
readOnly# | - | boolean |
Toggle the readonly state for the component. When | ||
required# | - | boolean |
When it is present, it indicates that the user must choose a value before submitting the form. Adds HTML5 form validation requirement. The form will not submit until a valid selection is made. | ||
resetSelectionOnOptionsChange# | false | boolean |
Determines whether the selected options should be cleared when the options list is updated. When | ||
search# | - | Search |
Enables and configures search functionality.
| ||
searchNoResultsLabel# | false | ReactNode |
Sets the label for no results when filtering.
| ||
showHints# | false | boolean |
Show hint options based on the current input value. When | ||
size# | - | 'sm' , 'lg' |
Size the component small or large.
| ||
text#4.2.0+ | - | ReactNode |
Add helper text to the component. | ||
tooltipFeedback#4.2.0+ | - | boolean |
Display validation feedback in a styled tooltip. | ||
valid# | - | boolean |
Set component validation state to valid. | ||
value# | - | string , number |
Sets the initially selected value for the React.js autocomplete component. Can be a string (matched against option labels) or number (matched against option values). The component will attempt to find and select the matching option on mount. | ||
virtualScroller# | false | boolean |
Enable virtual scroller for the options list. When | ||
visible# | - | boolean |
Toggle the visibility of autocomplete dropdown. Controls whether the dropdown is initially visible. The dropdown visibility can still be toggled through user interaction. | ||
visibleItems# | 10 | number |
Amount of visible items when virtualScroller is enabled. Determines how many option items are rendered at once when virtual scrolling is active. Higher values show more items but use more memory. Lower values improve performance. |