Saltar al contenido

Select API

API documentation for the React Select component. Learn about the available props, and the CSS API.

Import

import Select from '@material-ui/core/Select';
// o
import { Select } from '@material-ui/core';
You can learn about the difference by reading this guide on minimizing bundle size.

Component name

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

Props

NombreTipoPor defectoDescripción
autoWidthboolfalseIf 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.
childrennodeThe 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.
classesobjectOverride or extend the styles applied to the component. See CSS API below for more details.
defaultValueanyThe default input value. Use when the component is not controlled.
displayEmptyboolfalseIf 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.
IconComponentelementTypeArrowDropDownIconThe icon that displays the arrow.
idstringThe id of the wrapper element or the select element when native.
inputelementAn Input element; does not have to be a material-ui specific Input.
inputPropsobjectAttributes applied to the input element. When native is true, the attributes are applied on the select element.
labelnodeSee OutlinedInput#label
labelIdstringThe ID of an element that acts as an additional label. The Select will be labelled by the additional label and the selected value.
labelWidthnumber0See OutlinedInput#label
MenuPropsobjectProps applied to the Menu element.
multipleboolfalseIf true, value must be an array and the menu will support multiple selections.
nativeboolfalseIf true, the component uses a native select element.
onChangefuncCallback 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).
child: The react element that was selected when native is false (default).
onClosefuncCallback 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.
onOpenfuncCallback 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.
openboolfalseControl select open state. You can only use it when the native prop is false (default).
renderValuefuncRender 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.
SelectDisplayPropsobjectProps applied to the clickable div element.
valueanyThe 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'
'standard'The variant to use.

The ref is forwarded to the root element.
Any other props supplied will be provided to the root element (Input).

Inheritance

While not explicitly documented above, the props of the Input component are also available on Select. You can take advantage of this to target nested components.

CSS

Rule nameGlobal classDescripción
root.MuiSelect-rootStyles applied to the select component `root` class.
select.MuiSelect-selectStyles applied to the select component `select` class.
filled.MuiSelect-filledStyles applied to the select component if variant="filled".
outlined.MuiSelect-outlinedStyles applied to the select component if variant="outlined".
selectMenu.MuiSelect-selectMenuStyles applied to the select component `selectMenu` class.
disabled.Mui-disabledPseudo-class applied to the select component `disabled` class.
icon.MuiSelect-iconStyles applied to the icon component.
iconOpen.MuiSelect-iconOpenStyles applied to the icon component if the popup is open.
iconFilled.MuiSelect-iconFilledStyles applied to the icon component if variant="filled".
iconOutlined.MuiSelect-iconOutlinedStyles applied to the icon component if variant="outlined".
nativeInput.MuiSelect-nativeInputStyles applied to the underlying native input component.

You can override the style of the component using one of these customization options: If that isn't sufficient, you can check the implementation of the component for more detail.

Demos