Autocomplete API
Documentação da API para o componente React Autocomplete . Aprenda sobre as propriedades disponíveis e a API CSS.
Importação
import Autocomplete from '@mui/material/Autocomplete';
// ou
import { Autocomplete } from '@mui/material';
Nome do componente
The nameMuiAutocomplete
can be used when providing default props or style overrides in the theme.Propriedades
Props of the nativo component are also available.
Nome | Tipo | Padrão | Descrição |
---|---|---|---|
options* | array | Array of options. | |
renderInput* | func | Render the input. Signature: function(params: object) => ReactNode | |
autoComplete | bool | false | 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. |
autoHighlight | bool | false | If true , the first option is automatically highlighted. |
autoSelect | bool | false | 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. |
blurOnSelect | 'mouse' | 'touch' | bool | false | 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. |
ChipProps | object | Props applied to the Chip element. | |
classes | object | Sobrescreve ou extende os estilos aplicados para o componente. Veja a API CSS abaixo para maiores detalhes. | |
clearIcon | node | <ClearIcon fontSize="small" /> | The icon to display in place of the default clear icon. |
clearOnBlur | bool | !props.freeSolo | 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 his search. |
clearOnEscape | bool | false | If true , clear all values when the user presses escape and the popup is closed. |
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. |
componentsProps | object | {} | |
defaultValue | any | props.multiple ? [] : null | The default input value. Use when the component is not controlled. |
disableClearable | bool | false | If true , the input can't be cleared. |
disableCloseOnSelect | bool | false | If true , the popup won't close when a value is selected. |
disabled | bool | false | Se true , o componente está desabilitado. |
disabledItemsFocusable | bool | false | If true , will allow focus on disabled items. |
disableListWrap | bool | false | If true , the list box in the popup will not wrap focus. |
disablePortal | bool | false | If true , the Popper content will be under the DOM hierarchy of the parent component. |
filterOptions | func | A filter function that determines the options that are eligible. Signature: function(options: T[], state: object) => T[] options: The options to render. state: The state of the component. | |
filterSelectedOptions | bool | false | If true , hide the selected options from the list box. |
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. |
fullWidth | bool | false | If true , the input will take up the full width of its container. |
getLimitTagsText | func | (more) => `+${more}` | The label to display when the tags are truncated ( limitTags ).Signature: function(more: 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).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. | |
handleHomeEndKeys | bool | !props.freeSolo | 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. |
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 true , the highlight can move to the input. |
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. |
ListboxComponent | elementType | 'ul' | The component used to render the listbox. |
ListboxProps | object | Props applied to the Listbox element. | |
loading | bool | false | If true , the component is in a loading state. |
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. |
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: object, value: T | 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: object, 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: object, 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: object, 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: object) => void event: The event source of the callback. | |
open | bool | false | Control the popup` open state. |
openOnFocus | bool | false | If true , the popup will open on input focus. |
openText | string | 'Open' | Override the default text for the open popup icon button. For localization purposes, you can use the provided translations. |
PaperComponent | elementType | Paper | The component used to render the body of the popup. |
PopperComponent | elementType | Popper | The component used to position the popup. |
popupIcon | node | <ArrowDropDownIcon /> | The icon to display in place of the default popup icon. |
renderGroup | func | Render the group. Signature: function(option: any) => ReactNode option: 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: T[], getTagProps: function) => ReactNode value: The value provided to the component.getTagProps: A tag props getter. | |
selectOnFocus | bool | !props.freeSolo | If true , the input's text is selected on focus. It helps the user clear the selected value. |
size | 'small' | 'medium' | string | 'medium' | The size of the autocomplete. |
sx | func | object | The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details. | |
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. |
O
ref
é encaminhado para o elemento raiz.CSS
Nome da regra | Classe global | Descrição |
---|---|---|
root | .MuiAutocomplete-root | Estilos aplicados ao elemento raiz. |
fullWidth | .MuiAutocomplete-fullWidth | Estilos aplicados para o elemento raiz se fullWidth={true} . |
focused | .Mui-focused | Pseudo-class aplicada a o elemento raiz se focused. |
tag | .MuiAutocomplete-tag | Estilos aplicados para the tag elements, e.g. the chips. |
tagSizeSmall | .MuiAutocomplete-tagSizeSmall | Estilos aplicados para the tag elements, e.g. the chips if size="small" . |
tagSizeMedium | .MuiAutocomplete-tagSizeMedium | Estilos aplicados para the tag elements, e.g. the chips if size="medium" . |
hasPopupIcon | .MuiAutocomplete-hasPopupIcon | Styles applied when the popup icon is rendered. |
hasClearIcon | .MuiAutocomplete-hasClearIcon | Styles applied when the clear icon is rendered. |
inputRoot | .MuiAutocomplete-inputRoot | Estilos aplicados a the Input element. |
input | .MuiAutocomplete-input | Estilos aplicados a the input element. |
inputFocused | .MuiAutocomplete-inputFocused | Estilos aplicados para the input element se tag focused. |
endAdornment | .MuiAutocomplete-endAdornment | Estilos aplicados a the endAdornment element. |
clearIndicator | .MuiAutocomplete-clearIndicator | Estilos aplicados a the clear indicator. |
popupIndicator | .MuiAutocomplete-popupIndicator | Estilos aplicados a the popup indicator. |
popupIndicatorOpen | .MuiAutocomplete-popupIndicatorOpen | Estilos aplicados para the popup indicator se the popup is open. |
popper | .MuiAutocomplete-popper | Estilos aplicados a the popper element. |
popperDisablePortal | .MuiAutocomplete-popperDisablePortal | Estilos aplicados para the popper element se disablePortal={true} . |
paper | .MuiAutocomplete-paper | Estilos aplicados a the Paper component. |
listbox | .MuiAutocomplete-listbox | Estilos aplicados a the listbox component. |
loading | .MuiAutocomplete-loading | Estilos aplicados a the loading wrapper. |
noOptions | .MuiAutocomplete-noOptions | Estilos aplicados a the no option wrapper. |
option | .MuiAutocomplete-option | Estilos aplicados a the option elements. |
groupLabel | .MuiAutocomplete-groupLabel | Estilos aplicados a the group's label elements. |
groupUl | .MuiAutocomplete-groupUl | Estilos aplicados a the group's ul elements. |
Você pode sobrescrever o estilo do componente usando uma dessas opções de customização:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.