Autocomplete
An autocomplete component is a text input enhanced by a panel of suggested options.
useAutocomplete API
Import
import { useAutocomplete } from '@mui/base/useAutocomplete';
// or
import { useAutocomplete } from '@mui/base';Learn about the difference by reading this guide on minimizing bundle size.
| Name | Type | Default | Description |
|---|---|---|---|
| options* | ReadonlyArray<Value> | - | Array of options. |
| autoComplete | boolean | false | If |
| autoHighlight | boolean | false | If |
| autoSelect | boolean | false | If |
| blurOnSelect | 'touch' | 'mouse' | true | false | false | Control if the input should be blurred when an option is selected:
|
| clearOnBlur | boolean | !props.freeSolo | If |
| clearOnEscape | boolean | false | If |
| componentName | string | - | The component name that is using this hook. Used for warnings. |
| defaultValue | AutocompleteValue<Value, Multiple, DisableClearable, FreeSolo> | props.multiple ? [] : null | The default value. Use when the component is not controlled. |
| disableClearable | DisableClearable | false | If |
| disableCloseOnSelect | boolean | false | If |
| disabled | boolean | false | If |
| disabledItemsFocusable | boolean | false | If |
| disableListWrap | boolean | false | If |
| filterOptions | (options: Value[], state: FilterOptionsState<Value>) => Value[] | createFilterOptions() | A function that determines the filtered options to be rendered on search. |
| filterSelectedOptions | boolean | false | If |
| freeSolo | FreeSolo | false | If |
| getOptionDisabled | (option: Value) => boolean | - | Used to determine the disabled state for a given option. |
| getOptionKey | (option: Value | AutocompleteFreeSoloValueMapping<FreeSolo>) => string | number | - | Used to determine the key for a given option. This can be useful when the labels of options are not unique (since labels are used as keys by default). |
| getOptionLabel | (option: Value | AutocompleteFreeSoloValueMapping<FreeSolo>) => string | (option) => option.label ?? option | Used to determine the string value for a given option. It's used to fill the input (and the list box options if |
| groupBy | (option: Value) => string | - | If provided, the options will be grouped under the returned string. The groupBy value is also used as the text for group headings when |
| handleHomeEndKeys | boolean | !props.freeSolo | If |
| id | string | - | This prop is used to help implement the accessibility logic. If you don't provide an id it will fall back to a randomly generated one. |
| includeInputInList | boolean | false | If |
| inputValue | string | - | The input value. |
| isOptionEqualToValue | (option: Value, value: Value) => boolean | - | Used to determine if the option represents the given value. Uses strict equality by default. ⚠️ Both arguments need to be handled, an option can only match with one value. |
| multiple | Multiple | false | If |
| onChange | (event: React.SyntheticEvent, value: AutocompleteValue<Value, Multiple, DisableClearable, FreeSolo>, reason: AutocompleteChangeReason, details?: AutocompleteChangeDetails<Value>) => void | - | Callback fired when the value changes. |
| onClose | (event: React.SyntheticEvent, reason: AutocompleteCloseReason) => void | - | Callback fired when the popup requests to be closed. Use in controlled mode (see open). |
| onHighlightChange | (event: React.SyntheticEvent, option: Value | null, reason: AutocompleteHighlightChangeReason) => void | - | Callback fired when the highlight option changes. |
| onInputChange | (event: React.SyntheticEvent, value: string, reason: AutocompleteInputChangeReason) => void | - | Callback fired when the input value changes. |
| onOpen | (event: React.SyntheticEvent) => void | - | Callback fired when the popup requests to be opened. Use in controlled mode (see open). |
| open | boolean | - | If |
| openOnFocus | boolean | false | If |
| readOnly | boolean | false | If |
| selectOnFocus | boolean | !props.freeSolo | If |
| unstable_classNamePrefix | string | 'Mui' | |
| unstable_isActiveElementInListbox | (listbox: React.RefObject<HTMLElement | null>) => boolean | - | |
| value | AutocompleteValue<Value, Multiple, DisableClearable, FreeSolo> | - | The value of the autocomplete. |
| Name | Type | Description |
|---|---|---|
| anchorEl | null | HTMLElement | An HTML element that is used to set the position of the component. |
| dirty | boolean | If |
| expanded | boolean | If |
| focused | boolean | If |
| focusedTag | number | Index of the focused tag for the component. |
| getClearProps | () => React.HTMLAttributes<HTMLButtonElement> | Resolver for the |
| getInputLabelProps | () => Omit<React.HTMLAttributes<HTMLLabelElement>, 'color'> | Resolver for the input label element's props. |
| getInputProps | () => React.InputHTMLAttributes<HTMLInputElement> & { ref: React.Ref<HTMLInputElement> } | Resolver for the input element's props. |
| getListboxProps | () => React.HTMLAttributes<HTMLUListElement> | Resolver for the listbox component's props. |
| getOptionProps | (renderedOption: UseAutocompleteRenderedOption<Value>) => React.HTMLAttributes<HTMLLIElement> & { key: any } | Resolver for the rendered option element's props. |
| getPopupIndicatorProps | () => React.HTMLAttributes<HTMLButtonElement> | Resolver for the popup icon's props. |
| getRootProps | (externalProps?: any) => React.HTMLAttributes<HTMLDivElement> | Resolver for the root slot's props. |
| getTagProps | AutocompleteGetTagProps | A tag props getter. |
| groupedOptions | Value[] | Array<AutocompleteGroupedOption<Value>> | The options to render. It's either |
| id | string | Id for the Autocomplete. |
| inputValue | string | The input value. |
| popupOpen | boolean | If |
| setAnchorEl | () => void | Setter for the component |
| value | AutocompleteValue<Value, Multiple, DisableClearable, FreeSolo> | The value of the autocomplete. |