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/material/Autocomplete';
// or
import { Autocomplete } from '@mui/material';
Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

optionsRequired

Array of options.

Type:

array

renderInputRequired

Render the input.

Type:

func

Signature:

function(params: object) => ReactNode

    autoComplete

    If true, the portion of the selected suggestion that has not been typed by the user, 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

    autoHighlight

    If true, the first option is automatically highlighted.

    Type:

    bool

    Default:

    false

    autoSelect

    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 freeSolo mode, the typed value will be the input value if the Autocomplete loses focus without highlighting an option.

    Type:

    bool

    Default:

    false

    blurOnSelect

    Control if the input should be blurred when an option is selected:
    - false the input is not blurred. - true the input is always blurred. - touch the input is blurred after a touch event. - mouse the input is blurred after a mouse event.

    Type:

    'mouse' | 'touch' | bool

    Default:

    false

    ChipProps

    Props applied to the Chip element.

    Type:

    object

    classes

    Override or extend the styles applied to the component.

    See CSS API below for more details.

    Type:

    object

    clearIcon

    The icon to display in place of the default clear icon.

    Type:

    node

    Default:

    <ClearIcon fontSize="small" />

    clearOnBlur

    If true, the input's text is cleared on blur if no value is selected.
    Set to true if you want to help the user enter a new value. Set to false if you want to help the user resume their search.

    Type:

    bool

    Default:

    !props.freeSolo

    clearOnEscape

    If true, clear all values when the user presses escape and the popup is closed.

    Type:

    bool

    Default:

    false

    clearText

    Override the default text for the clear icon button.
    For localization purposes, you can use the provided translations.

    Type:

    string

    Default:

    'Clear'

    closeText

    Override the default text for the close popup icon button.
    For localization purposes, you can use the provided translations.

    Type:

    string

    Default:

    'Close'

    componentsProps

    The props used for each slot inside.

    Type:

    { clearIndicator?: object, paper?: object, popper?: object, popupIndicator?: object }

    Default:

    {}

    defaultValue

    The default value. Use when the component is not controlled.

    Type:

    any

    Default:

    props.multiple ? [] : null

    disableClearable

    If true, the input can't be cleared.

    Type:

    bool

    Default:

    false

    disableCloseOnSelect

    If true, the popup won't close when a value is selected.

    Type:

    bool

    Default:

    false

    disabled

    If true, the component is disabled.

    Type:

    bool

    Default:

    false

    disabledItemsFocusable

    If true, will allow focus on disabled items.

    Type:

    bool

    Default:

    false

    disableListWrap

    If true, the list box in the popup will not wrap focus.

    Type:

    bool

    Default:

    false

    disablePortal

    If true, the Popper content will be under the DOM hierarchy of the parent component.

    Type:

    bool

    Default:

    false

    filterOptions

    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.

    filterSelectedOptions

    If true, hide the selected options from the list box.

    Type:

    bool

    Default:

    false

    forcePopupIcon

    Force the visibility display of the popup icon.

    Type:

    'auto' | bool

    Default:

    'auto'

    freeSolo

    If true, the Autocomplete is free solo, meaning that the user input is not bound to provided options.

    Type:

    bool

    Default:

    false

    fullWidth

    If true, the input will take up the full width of its container.

    Type:

    bool

    Default:

    false

    getLimitTagsText

    The label to display when the tags are truncated (limitTags).

    Type:

    func

    Default:

    (more) => `+${more}`

    Signature:

    function(more: number) => ReactNode
    • more The number of truncated tags.

    getOptionDisabled

    Used to determine the disabled state for a given option.

    Type:

    func

    Signature:

    function(option: Value) => boolean
    • option The option to test.

    getOptionLabel

    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: Value) => string

      groupBy

      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: Value) => string
      • options The options to group.

      handleHomeEndKeys

      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

      id

      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

      includeInputInList

      If true, the highlight can move to the input.

      Type:

      bool

      Default:

      false

      inputValue

      The input value.

      Type:

      string

      isOptionEqualToValue

      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: Value, value: Value) => boolean
      • option The option to test.
      • value The value to test against.

      limitTags

      The maximum number of tags that will be visible when not focused. Set -1 to disable the limit.

      Type:

      integer

      Default:

      -1

      ListboxComponent

      The component used to render the listbox.

      Type:

      elementType

      Default:

      'ul'

      ListboxProps

      Props applied to the Listbox element.

      Type:

      object

      loading

      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

      loadingText

      Text to display when in a loading state.
      For localization purposes, you can use the provided translations.

      Type:

      node

      Default:

      'Loading…'

      multiple

      If true, value must be an array and the menu will support multiple selections.

      Type:

      bool

      Default:

      false

      noOptionsText

      Text to display when there are no options.
      For localization purposes, you can use the provided translations.

      Type:

      node

      Default:

      'No options'

      onChange

      Callback fired when the value changes.

      Type:

      func

      Signature:

      function(event: React.SyntheticEvent, value: Value | 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".

      onClose

      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".

      onHighlightChange

      Callback fired when the highlight option changes.

      Type:

      func

      Signature:

      function(event: React.SyntheticEvent, option: Value, reason: string) => void
      • event The event source of the callback.
      • option The highlighted option.
      • reason Can be: "keyboard", "auto", "mouse", "touch".

      onInputChange

      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".

      onOpen

      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.

      open

      If true, the component is shown.

      Type:

      bool

      openOnFocus

      If true, the popup will open on input focus.

      Type:

      bool

      Default:

      false

      openText

      Override the default text for the open popup icon button.
      For localization purposes, you can use the provided translations.

      Type:

      string

      Default:

      'Open'

      PaperComponent

      The component used to render the body of the popup.

      Type:

      elementType

      Default:

      Paper

      PopperComponent

      The component used to position the popup.

      Type:

      elementType

      Default:

      Popper

      popupIcon

      The icon to display in place of the default popup icon.

      Type:

      node

      Default:

      <ArrowDropDownIcon />

      readOnly

      If true, the component becomes readonly. It is also supported for multiple tags where the tag cannot be deleted.

      Type:

      bool

      Default:

      false

      renderGroup

      Render the group.

      Type:

      func

      Signature:

      function(params: AutocompleteRenderGroupParams) => ReactNode
      • params The group to render.

      renderOption

      Render the option, use getOptionLabel by default.

      Type:

      func

      Signature:

      function(props: object, option: Value, state: object, ownerState: object) => ReactNode
      • props The props to apply on the li element.
      • option The option to render.
      • state The state of each option.
      • ownerState The state of the Autocomplete component.

      renderTags

      Render the selected value.

      Type:

      func

      Signature:

      function(value: Array, getTagProps: function, ownerState: object) => ReactNode
      • value The value provided to the component.
      • getTagProps A tag props getter.
      • ownerState The state of the Autocomplete component.

      selectOnFocus

      If true, the input's text is selected on focus. It helps the user clear the selected value.

      Type:

      bool

      Default:

      !props.freeSolo

      size

      The size of the component.

      Type:

      'small' | 'medium' | string

      Default:

      'medium'

      slotProps

      The props used for each slot inside.

      Type:

      { clearIndicator?: object, paper?: object, popper?: object, popupIndicator?: object }

      Default:

      {}

      sx

      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

      value

      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

      The 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.


      CSS

      The following class names are useful for styling with CSS (the state classes are marked).
      To learn more, visit the component customization page.


      .MuiAutocomplete-rootroot

      Styles applied to the root element.


      .MuiAutocomplete-fullWidthfullWidth

      Styles applied to the root element if fullWidth={true}.


      .Mui-expandedexpandedSTATE

      State class applied to the root element if the listbox is displayed.


      .Mui-focusedfocusedSTATE

      State class applied to the root element if focused.


      .Mui-focusVisiblefocusVisibleSTATE

      Styles applied to the option elements if they are keyboard focused.


      .MuiAutocomplete-tagtag

      Styles applied to the tag elements, e.g. the chips.


      .MuiAutocomplete-tagSizeSmalltagSizeSmall

      Styles applied to the tag elements, e.g. the chips if size="small".


      .MuiAutocomplete-tagSizeMediumtagSizeMedium

      Styles applied to the tag elements, e.g. the chips if size="medium".


      .MuiAutocomplete-hasPopupIconhasPopupIcon

      Styles applied when the popup icon is rendered.


      .MuiAutocomplete-hasClearIconhasClearIcon

      Styles applied when the clear icon is rendered.


      .MuiAutocomplete-inputRootinputRoot

      Styles applied to the Input element.


      .MuiAutocomplete-inputinput

      Styles applied to the input element.


      .MuiAutocomplete-inputFocusedinputFocused

      Styles applied to the input element if the input is focused.


      .MuiAutocomplete-endAdornmentendAdornment

      Styles applied to the endAdornment element.


      .MuiAutocomplete-clearIndicatorclearIndicator

      Styles applied to the clear indicator.


      .MuiAutocomplete-popupIndicatorpopupIndicator

      Styles applied to the popup indicator.


      .MuiAutocomplete-popupIndicatorOpenpopupIndicatorOpen

      Styles applied to the popup indicator if the popup is open.


      .MuiAutocomplete-popperpopper

      Styles applied to the popper element.


      .MuiAutocomplete-popperDisablePortalpopperDisablePortal

      Styles applied to the popper element if disablePortal={true}.


      .MuiAutocomplete-paperpaper

      Styles applied to the Paper component.


      .MuiAutocomplete-listboxlistbox

      Styles applied to the listbox component.


      .MuiAutocomplete-loadingloading

      Styles applied to the loading wrapper.


      .MuiAutocomplete-noOptionsnoOptions

      Styles applied to the no option wrapper.


      .MuiAutocomplete-optionoption

      Styles applied to the option elements.


      .MuiAutocomplete-groupLabelgroupLabel

      Styles applied to the group's label elements.


      .MuiAutocomplete-groupUlgroupUl

      Styles applied to the group's ul elements.


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