Skip to content

Autocomplete API

API reference docs for the React Autocomplete component. Learn about the props, CSS, and other APIs of this exported module.

Demos

For examples and details on the usage of this React component, visit the component demo pages:

Import

import Autocomplete from '@mui/joy/Autocomplete';
// or
import { Autocomplete } from '@mui/joy';
You can learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

NameTypeDefaultDescription
options*array
Array of options.
aria-describedbystring
Identifies the element (or elements) that describes the object.
aria-labelstring
Defines a string value that labels the current element.
aria-labelledbystring
Identifies the element (or elements) that labels the current element.
autoFocusbool
If true, the input element is focused during the first mount.
clearIconnode<ClearIcon fontSize="md" />
The icon to display in place of the default clear icon.
clearTextstring'Clear'
Override the default text for the clear icon button.
For localization purposes, you can use the provided translations.
closeTextstring'Close'
Override the default text for the close popup icon button.
For localization purposes, you can use the provided translations.
color'danger'
| 'info'
| 'neutral'
| 'primary'
| 'success'
| 'warning'
'neutral'
The color of the component. It supports those theme colors that make sense for this component. To learn how to add your own colors, check out Themed components—Extend colors.
defaultValueanyprops.multiple ? [] : null
The default value. Use when the component is not controlled.
disableClearableboolfalse
If true, the input can't be cleared.
disabledboolfalse
If true, the component is disabled.
endDecoratornode
Trailing adornment for this input.
errorboolfalse
If true, the input will indicate an error. The prop defaults to the value (false) inherited from the parent FormControl component.
filterOptionsfunccreateFilterOptions()
A function that determines the filtered options to be rendered on search.

Signature:
function(options: Array<T>, state: object) => Array<T>
options: The options to render.
state: The state of the component.
forcePopupIcon'auto'
| bool
'auto'
Force the visibility display of the popup icon.
freeSoloboolfalse
If true, the Autocomplete is free solo, meaning that the user input is not bound to provided options.
getLimitTagsTextfunc(more: string | number) => `+${more}`
The label to display when the tags are truncated (limitTags).

Signature:
function(more: string | number) => ReactNode
more: The number of truncated tags.
getOptionDisabledfunc
Used to determine the disabled state for a given option.

Signature:
function(option: T) => boolean
option: The option to test.
getOptionLabelfunc(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 renderOption is not provided).
If used in free solo mode, it must accept both the type of the options and a string.

Signature:
function(option: T) => string
groupByfunc
If 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.

Signature:
function(options: T) => string
options: The options to group.
idstring
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.
inputValuestring
The input value.
isOptionEqualToValuefunc
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.

Signature:
function(option: T, value: T) => boolean
option: The option to test.
value: The value to test against.
limitTagsinteger-1
The maximum number of tags that will be visible when not focused. Set -1 to disable the limit.
loadingboolfalse
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).
loadingTextnode'Loading…'
Text to display when in a loading state.
For localization purposes, you can use the provided translations.
multipleboolfalse
If true, value must be an array and the menu will support multiple selections.
namestring
Name attribute of the input element.
noOptionsTextnode'No options'
Text to display when there are no options.
For localization purposes, you can use the provided translations.
onChangefunc
Callback fired when the value changes.

Signature:
function(event: React.SyntheticEvent, value: T | Array<T>, reason: string, details?: string) => void
event: The event source of the callback.
value: The new value of the component.
reason: One of "createOption", "selectOption", "removeOption", "blur" or "clear".
onClosefunc
Callback fired when the popup requests to be closed. Use in controlled mode (see open).

Signature:
function(event: React.SyntheticEvent, reason: string) => void
event: The event source of the callback.
reason: Can be: "toggleInput", "escape", "selectOption", "removeOption", "blur".
onHighlightChangefunc
Callback fired when the highlight option changes.

Signature:
function(event: React.SyntheticEvent, option: T, reason: string) => void
event: The event source of the callback.
option: The highlighted option.
reason: Can be: "keyboard", "auto", "mouse", "touch".
onInputChangefunc
Callback fired when the input value changes.

Signature:
function(event: React.SyntheticEvent, value: string, reason: string) => void
event: The event source of the callback.
value: The new value of the text input.
reason: Can be: "input" (user input), "reset" (programmatic change), "clear".
onOpenfunc
Callback fired when the popup requests to be opened. Use in controlled mode (see open).

Signature:
function(event: React.SyntheticEvent) => void
event: The event source of the callback.
openbool
If true, the component is shown.
openTextstring'Open'
Override the default text for the open popup icon button.
For localization purposes, you can use the provided translations.
placeholderstring
The input placeholder
popupIconnode<ArrowDropDownIcon />
The icon to display in place of the default popup icon.
readOnlyboolfalse
If true, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.
renderGroupfunc
Render the group.

Signature:
function(params: AutocompleteRenderGroupParams) => ReactNode
params: The group to render.
renderOptionfunc
Render the option, use getOptionLabel by default.

Signature:
function(props: object, option: T, state: object) => ReactNode
props: The props to apply on the li element.
option: The option to render.
state: The state of the component.
renderTagsfunc
Render the selected value.

Signature:
function(value: Array<T>, getTagProps: function, ownerState: object) => ReactNode
value: The value provided to the component.
getTagProps: A tag props getter.
ownerState: The state of the Autocomplete component.
requiredbool
If true, the input element is required. The prop defaults to the value (false) inherited from the parent FormControl component.
size'sm'
| 'md'
| 'lg'
| string
'md'
The size of the component. To learn how to add custom sizes to the component, check out Themed components—Extend sizes.
slotProps{ clearIndicator?: func
| object, endDecorator?: func
| object, input?: func
| object, limitTag?: func
| object, listbox?: func
| object, loading?: func
| object, noOptions?: func
| object, option?: func
| object, popupIndicator?: func
| object, root?: func
| object, startDecorator?: func
| object, wrapper?: func
| object }
{}
The props used for each slot inside.
slots{ clearIndicator?: elementType, endDecorator?: elementType, input?: elementType, limitTag?: elementType, listbox?: elementType, loading?: elementType, noOptions?: elementType, option?: elementType, popupIndicator?: elementType, root?: elementType, startDecorator?: elementType, wrapper?: elementType }{}
The components used for each slot inside. See Slots API below for more details.
startDecoratornode
Leading adornment for this input.
sxArray<func
| object
| bool>
| func
| object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.
typestring
Type of the input element. It should be a valid HTML5 input type.
valueany
The value of the autocomplete.
The value must have reference equality with the option in order to be selected. You can customize the equality behavior with the isOptionEqualToValue prop.
variant'outlined'
| 'plain'
| 'soft'
| 'solid'
'outlined'
The global variant to use. To learn how to add your own variants, check out Themed components—Extend variants.

The ref is forwarded to the root element.

Theme default props

You can use JoyAutocomplete to change the default props of this component with the theme.

Slots

To learn how to customize the slot, check out the Overriding component structure guide.

NameDefault classDefault HTML tagDescription
root.MuiAutocomplete-root'div'The component that renders the root.
wrapper.MuiAutocomplete-wrapper'div'The component that renders the wrapper.
input.MuiAutocomplete-input'input'The component that renders the input.
startDecorator.MuiAutocomplete-startDecorator'div'The component that renders the start decorator.
endDecorator.MuiAutocomplete-endDecorator'div'The component that renders the end decorator.
clearIndicator.MuiAutocomplete-clearIndicator'button'The component that renders the clear indicator.
popupIndicator.MuiAutocomplete-popupIndicator'button'The component that renders the popup indicator.
listbox.MuiAutocomplete-listbox'ul'The component that renders the listbox.
option.MuiAutocomplete-option'li'The component that renders the option.
loading.MuiAutocomplete-loading'li'The component that renders the loading.
noOptions.MuiAutocomplete-noOptions'li'The component that renders the no-options.
limitTag.MuiAutocomplete-limitTag'div'The component that renders the limit tag.

You can override the style of the component using one of these customization options:

CSS classes

These class names are useful for styling with CSS. They are applied to the root slot when specific states are triggered.

Global classDescription
.Mui-disabled
STATE
Class name applied to the root element if disabled={true}.
.Mui-error
STATE
State class applied to the root element if error={true}.
.Mui-focused
STATE
Class name applied to the root element if the component is focused.
.MuiAutocomplete-colorContextClass name applied to the root element when color inversion is triggered.
.MuiAutocomplete-colorDangerClass name applied to the root element if color="danger".
.MuiAutocomplete-colorInfoClass name applied to the root element if color="info".
.MuiAutocomplete-colorNeutralClass name applied to the root element if color="neutral".
.MuiAutocomplete-colorPrimaryClass name applied to the root element if color="primary".
.MuiAutocomplete-colorSuccessClass name applied to the root element if color="success".
.MuiAutocomplete-colorWarningClass name applied to the root element if color="warning".
.MuiAutocomplete-formControlClass name applied to the root element if the component is a descendant of FormControl.
.MuiAutocomplete-hasClearIconClass name applied when the clear icon is rendered.
.MuiAutocomplete-hasPopupIconClass name applied when the popup icon is rendered.
.MuiAutocomplete-multipleClass name applied to the wrapper element if multiple={true}.
.MuiAutocomplete-popupIndicatorOpenClass name applied to the popup indicator if the popup is open.
.MuiAutocomplete-sizeLgClass name applied to the root element if size="lg".
.MuiAutocomplete-sizeMdClass name applied to the root element if size="md".
.MuiAutocomplete-sizeSmClass name applied to the root element if size="sm".
.MuiAutocomplete-variantOutlinedClass name applied to the root element if variant="outlined".
.MuiAutocomplete-variantPlainClass name applied to the root element if variant="plain".
.MuiAutocomplete-variantSoftClass name applied to the root element if variant="soft".
.MuiAutocomplete-variantSolidClass name applied to the root element if variant="solid".