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';
Component name
The nameJoyAutocomplete
can be used when providing default props or style overrides in the theme.Props
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. | |
autoFocus | bool | If true , the input element is focused during the first mount. | |
clearIcon | node | <ClearIcon fontSize="md" /> | The icon to display in place of the default clear icon. |
clearText | string | 'Clear' | Override the default text for the clear icon button. For localization purposes, you can use the provided translations. |
closeText | string | '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. |
defaultValue | any | props.multiple ? [] : null | The default value. Use when the component is not controlled. |
disableClearable | bool | false | If true , the input can't be cleared. |
disabled | bool | false | If true , the component is disabled. |
endDecorator | node | Trailing adornment for this input. | |
error | bool | false | If true , the input will indicate an error. The prop defaults to the value (false ) inherited from the parent FormControl component. |
filterOptions | func | 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. |
freeSolo | bool | false | If true , the Autocomplete is free solo, meaning that the user input is not bound to provided options. |
getLimitTagsText | func | (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. |
getOptionDisabled | func | Used to determine the disabled state for a given option. Signature: function(option: T) => boolean option: The option to test. | |
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 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 |
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 renderGroup is not provided.Signature: function(options: T) => string options: The options to group. | |
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. | |
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: T, value: T) => boolean option: The option to test. value: The value to test against. | |
limitTags | integer | -1 | The maximum number of tags that will be visible when not focused. Set -1 to disable the limit. |
loading | bool | false | 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). |
loadingText | node | 'Loading…' | Text to display when in a loading state. For localization purposes, you can use the provided translations. |
multiple | bool | false | If true , value must be an array and the menu will support multiple selections. |
name | string | Name attribute of the input element. | |
noOptionsText | node | 'No options' | Text to display when there are no options. For localization purposes, you can use the provided translations. |
onChange | func | 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". | |
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 event: The event source of the callback. reason: Can be: "toggleInput" , "escape" , "selectOption" , "removeOption" , "blur" . | |
onHighlightChange | func | 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" . | |
onInputChange | func | 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" . | |
onOpen | func | 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. | |
open | bool | If true , the component is shown. | |
openText | string | 'Open' | Override the default text for the open popup icon button. For localization purposes, you can use the provided translations. |
placeholder | string | The input placeholder | |
popupIcon | node | <ArrowDropDownIcon /> | The icon to display in place of the default popup icon. |
readOnly | bool | false | If true , the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted. |
renderGroup | func | Render the group. Signature: function(params: AutocompleteRenderGroupParams) => ReactNode params: The group to render. | |
renderOption | func | 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. | |
renderTags | func | 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. | |
required | bool | 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. |
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 input element. It should be a valid HTML5 input type. | |
value | any | 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 variant to use. |
The
ref
is forwarded to the root element.