Autocomplete API
API reference docs for the React Autocomplete component. Learn about the props, CSS, and other APIs of this exported module.
Component demos
Import
import Autocomplete from '@mui/material/Autocomplete';
// or
import { Autocomplete } from '@mui/material';Props of the native component are also available.
If true, the portion of the selected suggestion that the user hasn't typed, known as the completion string, appears inline after the input cursor in the textbox. The inline completion string is visually highlighted and has a selected state.
Type:bool
Default:false
If true, the selected option becomes the value of the input when the Autocomplete loses focus unless the user chooses a different option or changes the character string in the input.
When using the freeSolo mode, the typed value will be the input value if the Autocomplete loses focus without highlighting an option.
Type:bool
Default:false
Control if the input should be blurred when an option is selected:
falsethe input is not blurred.truethe input is always blurred.touchthe input is blurred after a touch event.mousethe input is blurred after a mouse event.
Type:'mouse'
| 'touch'
| bool
Default:false
Override or extend the styles applied to the component.
See CSS API below for more details.
Type:object
The icon to display in place of the default clear icon.
Type:node
Default:<ClearIcon fontSize="small" />
If true, the input's text is cleared on blur if no value is selected.
Set it to true if you want to help the user enter a new value. Set it to false if you want to help the user resume their search.
Type:bool
Default:!props.freeSolo
If true, clear all values when the user presses escape and the popup is closed.
Type:bool
Default:false
Override the default text for the clear icon button.
For localization purposes, you can use the provided translations.
Type:string
Default:'Clear'
Override the default text for the close popup icon button.
For localization purposes, you can use the provided translations.
Type:string
Default:'Close'
The props used for each slot inside.
Type:{ clearIndicator?: object, paper?: object, popper?: object, popupIndicator?: object }
Default:{}
The default value. Use when the component is not controlled.
Type:any
Default:props.multiple ? [] : null
If true, the Popper content will be under the DOM hierarchy of the parent component.
Type:bool
Default:false
A function that determines the filtered options to be rendered on search.
Type:func
Default:createFilterOptions()
function(options: Array, state: object) => Array optionsThe options to render.stateThe state of the component.
If true, the Autocomplete is free solo, meaning that the user input is not bound to provided options.
Type:bool
Default:false
The label to display when the tags are truncated (limitTags).
Type:func
Default:(more) => `+${more}`
function(more: number) => ReactNodemoreThe number of truncated tags.
Used to determine the disabled state for a given option.
Type:func
function(option: Value) => booleanoptionThe option to test.
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).
Type:func
function(option: Value) => string | numberoptionThe option to get the key for.
Used to determine the string value for a given option. It's used to fill the input (and the list box options if renderOption is not provided).
If used in free solo mode, it must accept both the type of the options and a string.
Type:func
Default:(option) => option.label ?? option
function(option: Value) => stringIf provided, the options will be grouped under the returned string. The groupBy value is also used as the text for group headings when renderGroup is not provided.
Type:func
function(options: Value) => stringoptionsThe options to group.
If true, the component handles the "Home" and "End" keys when the popup is open. It should move focus to the first option and last option, respectively.
Type:bool
Default:!props.freeSolo
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.
Type:string
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.
Type:func
function(option: Value, value: Value) => booleanoptionThe option to test.valueThe value to test against.
The maximum number of tags that will be visible when not focused. Set -1 to disable the limit.
Type:integer
Default:-1
If true, the component is in a loading state. This shows the loadingText in place of suggestions (only if there are no suggestions to show, e.g. options are empty).
Type:bool
Default:false
Text to display when in a loading state.
For localization purposes, you can use the provided translations.
Type:node
Default:'Loading…'
If true, value must be an array and the menu will support multiple selections.
Type:bool
Default:false
Text to display when there are no options.
For localization purposes, you can use the provided translations.
Type:node
Default:'No options'
Callback fired when the value changes.
Type:func
function(event: React.SyntheticEvent, value: Value | Array, reason: string, details?: string) => void eventThe event source of the callback.valueThe new value of the component.reasonOne of "createOption", "selectOption", "removeOption", "blur" or "clear".
Callback fired when the popup requests to be closed. Use in controlled mode (see open).
Type:func
function(event: React.SyntheticEvent, reason: string) => voideventThe event source of the callback.reasonCan be:"toggleInput","escape","selectOption","removeOption","blur".
Callback fired when the highlight option changes.
Type:func
function(event: React.SyntheticEvent, option: Value, reason: string) => voideventThe event source of the callback.optionThe highlighted option.reasonCan be:"keyboard","auto","mouse","touch".
Callback fired when the input value changes.
Type:func
function(event: React.SyntheticEvent, value: string, reason: string) => voideventThe event source of the callback.valueThe new value of the text input.reasonCan be:"input"(user input),"reset"(programmatic change),"clear".
Callback fired when the popup requests to be opened. Use in controlled mode (see open).
Type:func
function(event: React.SyntheticEvent) => voideventThe event source of the callback.
Override the default text for the open popup icon button.
For localization purposes, you can use the provided translations.
Type:string
Default:'Open'
The icon to display in place of the default popup icon.
Type:node
Default:<ArrowDropDownIcon />
If true, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.
Type:bool
Default:false
Render the group.
Type:func
function(params: AutocompleteRenderGroupParams) => ReactNodeparamsThe group to render.
Render the option, use getOptionLabel by default.
Type:func
function(props: object, option: Value, state: object, ownerState: object) => ReactNodepropsThe props to apply on the li element.optionThe option to render.stateThe state of each option.ownerStateThe state of the Autocomplete component.
Render the selected value.
Type:func
function(value: Array, getTagProps: function, ownerState: object) => ReactNode valueThevalueprovided to the component.getTagPropsA tag props getter.ownerStateThe state of the Autocomplete component.
If true, the input's text is selected on focus. It helps the user clear the selected value.
Type:bool
Default:!props.freeSolo
The props used for each slot inside.
Type:{ clearIndicator?: object, paper?: object, popper?: object, popupIndicator?: object }
Default:{}
The system prop that allows defining system overrides as well as additional CSS styles.
See the `sx` page for more details.
Type:Array<func
| object
| bool>
| func
| object
ref is forwarded to the root element.Theme default props
You can use MuiAutocomplete to change the default props of this component with the theme.
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Styles applied to the root element if fullWidth={true}.
Rule name:fullWidth
Styles applied to the input element if the input is focused.
Rule name:inputFocused
Styles applied to the popper element if disablePortal={true}.
Rule name:popperDisablePortal
Styles applied to the popup indicator if the popup is open.
Rule name:popupIndicatorOpen
Styles applied to the tag elements, e.g. the chips if size="medium".
Rule name:tagSizeMedium
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverridesproperty in a custom theme.