Pular para o conteúdo

Select API

Documentação da API para o componente React Select . Aprenda sobre as propriedades disponíveis e a API CSS.

Importação

import Select from '@mui/material/Select';
// ou
import { Select } from '@mui/material';
Você pode aprender sobre a diferença lendo este guia sobre como minimizar o tamanho do pacote.

Nome do componente

The name MuiSelect can be used when providing default props or style overrides in the theme.

Propriedades

Props of the OutlinedInput component are also available.

NomeTipoPadrãoDescrição
autoWidthboolfalse
If true, the width of the popover will automatically be set according to the items inside the menu, otherwise it will be at least the width of the select input.
childrennode
The option elements to populate the select with. Can be some MenuItem when native is false and option when native is true.
⚠️The MenuItem elements must be direct descendants when native is false.
classesobject{}
Sobrescreve ou extende os estilos aplicados para o componente. Veja a API CSS abaixo para maiores detalhes.
defaultValueany
The default input value. Use when the component is not controlled.
displayEmptyboolfalse
If true, a value is displayed even if no items are selected.
In order to display a meaningful value, a function can be passed to the renderValue prop which returns the value to be displayed when no items are selected.
⚠️ When using this prop, make sure the label doesn't overlap with the empty displayed value. The label should either be hidden or forced to a shrunk state.
IconComponentelementTypeArrowDropDownIcon
The icon that displays the arrow.
idstring
The id of the wrapper element or the select element when native.
inputelement
An Input element; does not have to be a material-ui specific Input.
inputPropsobject
Attributes applied to the input element. When native is true, the attributes are applied on the select element.
labelnode
labelIdstring
The ID of an element that acts as an additional label. The Select will be labelled by the additional label and the selected value.
MenuPropsobject
Props applied to the Menu element.
multipleboolfalse
If true, value must be an array and the menu will support multiple selections.
nativeboolfalse
If true, the component uses a native select element.
onChangefunc
Callback fired when a menu item is selected.

Signature:
function(event: object, child?: object) => void
event: The event source of the callback. You can pull out the new value by accessing event.target.value (any). Warning: This is a generic event not a change event.
child: The react element that was selected when native is false (default).
onClosefunc
Callback fired when the component requests to be closed. Use in controlled mode (see open).

Signature:
function(event: object) => void
event: The event source of the callback.
onOpenfunc
Callback fired when the component requests to be opened. Use in controlled mode (see open).

Signature:
function(event: object) => void
event: The event source of the callback.
openboolfalse
Control select open state. You can only use it when the native prop is false (default).
renderValuefunc
Render the selected value. You can only use it when the native prop is false (default).

Signature:
function(value: any) => ReactNode
value: The value provided to the component.
SelectDisplayPropsobject
Props applied to the clickable div element.
sxfunc
| object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.
valueany
The input value. Providing an empty string will select no options. This prop is required when the native prop is false (default). Set to an empty string '' if you don't want any of the available options to be selected.
If the value is an object it must have reference equality with the option in order to be selected. If the value is not an object, the string representation must match with the string representation of the option in order to be selected.
variant'filled'
| 'outlined'
| 'standard'
'outlined'
A variante a usar.

O ref é encaminhado para o elemento raiz.

Herança

Embora não explicitamente documentado acima, as propriedades do componente OutlinedInput também estão disponíveis em Select. Você pode tirar vantagem disso para manipular componentes aninhados.

CSS

Nome da regraClasse globalDescrição
root.MuiSelect-rootEstilos aplicados ao elemento raiz.
select.MuiSelect-selectEstilos aplicados a the select component `select` class.
filled.MuiSelect-filledEstilos aplicados para the select component se variant="filled".
outlined.MuiSelect-outlinedEstilos aplicados para the select component se variant="outlined".
standard.MuiSelect-standardEstilos aplicados para the select component se variant="standard".
disabled.Mui-disabledPseudo-class applied to the select component `disabled` class.
icon.MuiSelect-iconEstilos aplicados a the icon component.
iconOpen.MuiSelect-iconOpenEstilos aplicados para the icon component se the popup is open.
iconFilled.MuiSelect-iconFilledEstilos aplicados para the icon component se variant="filled".
iconOutlined.MuiSelect-iconOutlinedEstilos aplicados para the icon component se variant="outlined".
iconStandard.MuiSelect-iconStandardEstilos aplicados para the icon component se variant="standard".
nativeInput.MuiSelect-nativeInputEstilos aplicados a the underlying native input component.

Você pode sobrescrever o estilo do componente usando uma dessas opções de customização:

Demonstrações