Autocomplete

The autocomplete is a normal text input enhanced by a panel of suggested options.

() => {
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994, group: 'Movie' },
{ label: 'The Godfather', year: 1972, group: 'Movie' },
{ label: 'The Godfather: Part II', year: 1974, group: 'Movie' },
{ label: 'The Dark Knight', year: 2008, group: 'Movie' },
{ label: '12 Angry Men', year: 1957, group: 'Movie' },
{ label: "Schindler's List", year: 1993, group: 'Series' },
{ label: 'Pulp Fiction', year: 1994, group: 'Series' },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
group: 'Series',
},
{ label: 'The Good, the Bad and the Ugly', year: 1966, group: 'Series' },
{ label: 'Fight Club', year: 1999, group: 'Series' },
{ label: 'End Game', year: 1999, group: '' },
];
return (
<Autocomplete
disablePortal
id="combo-box-demo1"
options={top100Films}
label="Entertainment"
/>
);
};

Props

PropTypeDefaultDescription
optionsArrayArray of options.
renderInput() => voidRender the input.
defaultValuebooleanIf true, the Popper content will be under the DOM hierarchy of the parent component.
childrenReactNodeThe content of the component.
classesobjectOverride or extend the styles applied to the component.
groupBy() => voidIf 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.
renderGroup() => voidRender the group.
renderOption() => voidRender the option, use getOptionLabel by default.
renderTags() => voidRender the selected value.
disabledbooleanIf true, the component is disabled.
disablePortalbooleanIf true, the Popper content will be under the DOM hierarchy of the parent component.
openbooleanIf true, the component is shown.
getOptionLabel() => void(option) => option.label ?? optionUsed 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.
getChipOptionLabel() => void(option) => option.label ?? optionUsed 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, for multiple options selected

The ref is forwarded to the root element.

Examples

Autocomplete with groupBy

() => {
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994, group: 'Movie' },
{ label: 'The Godfather', year: 1972, group: 'Movie' },
{ label: 'The Godfather: Part II', year: 1974, group: 'Movie' },
{ label: 'The Dark Knight', year: 2008, group: 'Movie' },
{ label: '12 Angry Men', year: 1957, group: 'Movie' },
{ label: "Schindler's List", year: 1993, group: 'Series' },
{ label: 'Pulp Fiction', year: 1994, group: 'Series' },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
group: 'Series',
},
{ label: 'The Good, the Bad and the Ugly', year: 1966, group: 'Series' },
{ label: 'Fight Club', year: 1999, group: 'Series' },
{ label: 'End Game', year: 1999, group: '' },
];
return (
<Autocomplete
groupBy={(option) => option.group}
disablePortal
id="combo-box-demo2"
options={top100Films}
label="Entertainment"
/>
);
};

Autocomplete with mutliple select options

() => {
const top100Films = [
{ label: 'The Shawshank Redemption', year: 1994, group: 'Movie' },
{ label: 'The Godfather', year: 1972, group: 'Movie' },
{ label: 'The Godfather: Part II', year: 1974, group: 'Movie' },
{ label: 'The Dark Knight', year: 2008, group: 'Movie' },
{ label: '12 Angry Men', year: 1957, group: 'Movie' },
{ label: "Schindler's List", year: 1993, group: 'Series' },
{ label: 'Pulp Fiction', year: 1994, group: 'Series' },
{
label: 'The Lord of the Rings: The Return of the King',
year: 2003,
group: 'Series',
},
{ label: 'The Good, the Bad and the Ugly', year: 1966, group: 'Series' },
{ label: 'Fight Club', year: 1999, group: 'Series' },
{ label: 'End Game', year: 1999, group: '' },
];
return (
<Autocomplete
multiple
disablePortal
id="combo-box-demo3"
options={top100Films}
label="Entertainment"
/>
);
};