Autocomplete API
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';
Props
Props of the native component are also available.
The icon to display in place of the default clear icon.
Type:
node
Default:
<ClearIcon fontSize="md" />
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 color of the component. It supports those theme colors that make sense for this component.
Type:
'danger' | 'neutral' | 'primary' | 'success' | 'warning'
Default:
'neutral'
The default value. Use when the component is not controlled.
Type:
any
Default:
props.multiple ? [] : null
If true
, the input
will indicate an error. The prop defaults to the value (false
) inherited from the parent FormControl component.
Type:
bool
Default:
false
A function that determines the filtered options to be rendered on search.
Type:
func
Default:
createFilterOptions()
Signature:
function(options: Array, state: object) => Array
options
The options to render.state
The 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: string | number) => `+${more}`
Signature:
function(more: string | number) => ReactNode
more
The number of truncated tags.
Used to determine the disabled state for a given option.
Type:
func
Signature:
function(option: T) => boolean
option
The option to test.
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
Signature:
function(option: T) => 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 renderGroup
is not provided.
Type:
func
Signature:
function(options: T) => string
options
The options to group.
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
Signature:
function(option: T, value: T) => boolean
option
The option to test.value
The 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
Signature:
function(event: React.SyntheticEvent, value: T | Array, 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".
Callback fired when the popup requests to be closed. Use in controlled mode (see open).
Type:
func
Signature:
function(event: React.SyntheticEvent, reason: string) => void
event
The event source of the callback.reason
Can be:"toggleInput"
,"escape"
,"selectOption"
,"removeOption"
,"blur"
.
Callback fired when the highlight option changes.
Type:
func
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"
.
Callback fired when the input value changes.
Type:
func
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"
.
Callback fired when the popup requests to be opened. Use in controlled mode (see open).
Type:
func
Signature:
function(event: React.SyntheticEvent) => void
event
The 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
Signature:
function(params: AutocompleteRenderGroupParams) => ReactNode
params
The group to render.
Render the option, use getOptionLabel
by default.
Type:
func
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.
Render the selected value.
Type:
func
Signature:
function(value: Array, getTagProps: function, ownerState: object) => ReactNode
value
Thevalue
provided to the component.getTagProps
A tag props getter.ownerState
The state of the Autocomplete component.
If true
, the input
element is required. The prop defaults to the value (false
) inherited from the parent FormControl component.
Type:
bool
The props used for each slot inside.
Type:
{ 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 }
Default:
{}
The components used for each slot inside.
Type:
{ clearIndicator?: elementType, endDecorator?: elementType, input?: elementType, limitTag?: elementType, listbox?: elementType, loading?: elementType, noOptions?: elementType, option?: elementType, popupIndicator?: elementType, root?: elementType, startDecorator?: elementType, wrapper?: elementType }
Default:
{}
The system prop that allows defining system overrides as well as additional CSS styles.
Type:
Array<func | object | bool> | func | object
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.
Type:
any
ref
is forwarded to the root element.Theme default props
You can useJoyAutocomplete
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.
Global class: .MuiAutocomplete-root
Description: The component that renders the root.
Global class: .MuiAutocomplete-wrapper
Description: The component that renders the wrapper.
Global class: .MuiAutocomplete-input
Description: The component that renders the input.
Global class: .MuiAutocomplete-startDecorator
Description: The component that renders the start decorator.
Global class: .MuiAutocomplete-endDecorator
Description: The component that renders the end decorator.
Global class: .MuiAutocomplete-clearIndicator
Description: The component that renders the clear indicator.
Global class: .MuiAutocomplete-popupIndicator
Description: The component that renders the popup indicator.
Global class: .MuiAutocomplete-listbox
Description: The component that renders the listbox.
Global class: .MuiAutocomplete-option
Description: The component that renders the option.
Global class: .MuiAutocomplete-loading
Description: The component that renders the loading.
Global class: .MuiAutocomplete-noOptions
Description: The component that renders the no-options.
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.
CSS classes
These class names are useful for styling with CSS. They are applied to the root slot when specific states are triggered.
Class name applied to the root element when color inversion is triggered.
Class name applied to the root element if the component is a descendant of FormControl
.