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/joy/Autocomplete';
// or
import { Autocomplete } from '@mui/joy';
Props of the native component are also available.
Name | Type | Default | Description |
---|---|---|---|
options* | array | Array of options. | |
aria-describedby | string | Identifies the element (or elements) that describes the object. | |
aria-label | string | Defines a string value that labels the current element. | |
aria-labelledby | string | Identifies the element (or elements) that labels the current element. | |
autoComplete | bool | false | If |
autoFocus | bool | If | |
autoHighlight | bool | false | If |
autoSelect | bool | false | If |
blurOnSelect | 'mouse' | 'touch' | bool | false | Control if the input should be blurred when an option is selected:
|
clearIcon | node | <ClearIcon fontSize="md" /> | The icon to display in place of the default clear icon. |
clearOnBlur | bool | !props.freeSolo | If |
clearOnEscape | bool | false | If |
clearText | string | 'Clear' | Override the default text for the clear icon button. |
closeText | string | 'Close' | Override the default text for the close popup icon button. |
color | 'danger' | '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. |
defaultValue | any | props.multiple ? [] : null | The default value. Use when the component is not controlled. |
disableClearable | bool | false | If |
disableCloseOnSelect | bool | false | If |
disabled | bool | false | If |
disabledItemsFocusable | bool | false | If |
disableListWrap | bool | false | If |
endDecorator | node | Trailing adornment for this input. | |
error | bool | false | If |
filterOptions | func | createFilterOptions() | A function that determines the filtered options to be rendered on search. Signature: function(options: Array
|
filterSelectedOptions | bool | false | If |
forcePopupIcon | 'auto' | bool | 'auto' | Force the visibility display of the popup icon. |
freeSolo | bool | false | If |
getLimitTagsText | func | (more: string | number) => `+${more}` | The label to display when the tags are truncated ( Signature: function(more: string | number) => ReactNode
|
getOptionDisabled | func | Used to determine the disabled state for a given option. Signature: function(option: Value) => boolean
| |
getOptionKey | func | 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). Signature: function(option: Value) => string | number
| |
getOptionLabel | func | (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 Signature: function(option: Value) => string |
groupBy | func | If provided, the options will be grouped under the returned string. The groupBy value is also used as the text for group headings when Signature: function(options: Value) => string
| |
handleHomeEndKeys | bool | !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 | bool | false | If |
inputValue | string | The input value. | |
isOptionEqualToValue | func | 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: Value, value: Value) => boolean
| |
limitTags | integer | -1 | The maximum number of tags that will be visible when not focused. Set |
loading | bool | false | If |
loadingText | node | 'Loading…' | Text to display when in a loading state. |
multiple | bool | false | If |
name | string | Name attribute of the | |
noOptionsText | node | 'No options' | Text to display when there are no options. |
onChange | func | Callback fired when the value changes. Signature: function(event: React.SyntheticEvent, value: Value | Array
| |
onClose | func | Callback fired when the popup requests to be closed. Use in controlled mode (see open). Signature: function(event: React.SyntheticEvent, reason: string) => void
| |
onHighlightChange | func | Callback fired when the highlight option changes. Signature: function(event: React.SyntheticEvent, option: Value, reason: string) => void
| |
onInputChange | func | Callback fired when the input value changes. Signature: function(event: React.SyntheticEvent, value: string, reason: string) => void
| |
onOpen | func | Callback fired when the popup requests to be opened. Use in controlled mode (see open). Signature: function(event: React.SyntheticEvent) => void
| |
open | bool | If | |
openOnFocus | bool | false | If |
openText | string | 'Open' | Override the default text for the open popup icon button. |
placeholder | string | The input placeholder | |
popupIcon | node | <ArrowDropDownIcon /> | The icon to display in place of the default popup icon. |
readOnly | bool | false | If |
renderGroup | func | Render the group. Signature: function(params: AutocompleteRenderGroupParams) => ReactNode
| |
renderOption | func | Render the option, use Signature: function(props: object, option: T, state: object) => ReactNode
| |
renderTags | func | Render the selected value. Signature: function(value: Array
| |
required | bool | If | |
selectOnFocus | bool | !props.freeSolo | If |
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. |
startDecorator | node | Leading adornment for this input. | |
sx | Array<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. | |
type | string | Type of the | |
value | any | The value of the autocomplete. | |
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. |
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.
To learn how to customize the slot, check out the Overriding component structure guide.
Slot name | Class name | Default component | Description |
---|---|---|---|
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. |
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name | Rule name | Description |
---|---|---|
.Mui-disabled | Class name applied to the root element if disabled={true} . | |
.Mui-error | State class applied to the root element if error={true} . | |
.Mui-focused | Class name applied to the root element if the component is focused. | |
.MuiAutocomplete-colorContext | colorContext | Class name applied to the root element when color inversion is triggered. |
.MuiAutocomplete-colorDanger | colorDanger | Class name applied to the root element if color="danger" . |
.MuiAutocomplete-colorNeutral | colorNeutral | Class name applied to the root element if color="neutral" . |
.MuiAutocomplete-colorPrimary | colorPrimary | Class name applied to the root element if color="primary" . |
.MuiAutocomplete-colorSuccess | colorSuccess | Class name applied to the root element if color="success" . |
.MuiAutocomplete-colorWarning | colorWarning | Class name applied to the root element if color="warning" . |
.MuiAutocomplete-formControl | formControl | Class name applied to the root element if the component is a descendant of FormControl . |
.MuiAutocomplete-hasClearIcon | hasClearIcon | Class name applied when the clear icon is rendered. |
.MuiAutocomplete-hasPopupIcon | hasPopupIcon | Class name applied when the popup icon is rendered. |
.MuiAutocomplete-multiple | multiple | Class name applied to the wrapper element if multiple={true} . |
.MuiAutocomplete-popupIndicatorOpen | popupIndicatorOpen | Class name applied to the popup indicator if the popup is open. |
.MuiAutocomplete-sizeLg | sizeLg | Class name applied to the root element if size="lg" . |
.MuiAutocomplete-sizeMd | sizeMd | Class name applied to the root element if size="md" . |
.MuiAutocomplete-sizeSm | sizeSm | Class name applied to the root element if size="sm" . |
.MuiAutocomplete-variantOutlined | variantOutlined | Class name applied to the root element if variant="outlined" . |
.MuiAutocomplete-variantPlain | variantPlain | Class name applied to the root element if variant="plain" . |
.MuiAutocomplete-variantSoft | variantSoft | Class name applied to the root element if variant="soft" . |
.MuiAutocomplete-variantSolid | variantSolid | Class name applied to the root element if variant="solid" . |
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
styleOverrides
property in a custom theme.