Select Select components are used for collecting user provided information from a list of options.
Basic select Menus are positioned under their emitting elements, unless they are close to the bottom of the viewport.
Press Enter to start editing
Advanced features The Select component is meant to be interchangeable with a native <select>
element.
If you are looking for more advanced features, like combobox, multiselect, autocomplete, async or creatable support, head to the Autocomplete
component .
It's meant to be an improved version of the "react-select" and "downshift" packages.
Props The Select component is implemented as a custom <input>
element of the InputBase .
It extends the text field components sub-components, either the OutlinedInput , Input , or FilledInput , depending on the variant selected.
It shares the same styles and many of the same props. Refer to the respective component's API page for details.
Filled and standard variants Note that when using FormControl with the outlined variant of the Select, you need to provide a label in two places: in the InputLabel component and in the label
prop of the Select component (see the above demo).
Auto width Native select As the user experience can be improved on mobile using the native select of the platform,
we allow such pattern.
Press Enter to start editing
TextField The TextField
wrapper component is a complete form control including a label, input and help text.
You can find an example with the select mode in this section .
Customization Here are some examples of customizing the component.
You can learn more about this in the overrides documentation page .
The first step is to style the InputBase
component.
Once it's styled, you can either use it directly as a text field or provide it to the select input
prop to have a select
field.
Notice that the "standard"
variant is easier to customize, since it does not wrap the contents in a fieldset
/legend
markup.
🎨 If you are looking for inspiration, you can check MUI Treasury's customization examples .
Multiple select The Select
component can handle multiple selections.
It's enabled with the multiple
prop.
Like with the single selection, you can pull out the new value by accessing event.target.value
in the onChange
callback. It's always an array.
Default Controlling the open state You can control the open state of the select with the open
prop. Alternatively, it is also possible to set the initial (uncontrolled) open state of the component with the defaultOpen
prop.
With a dialog While it's discouraged by the Material Design guidelines, you can use a select inside a dialog.
Grouping Display categories with the ListSubheader
component or the native <optgroup>
element.
If you wish to wrap the ListSubheader in a custom component, you'll have to annotate it so Material UI can handle it properly when determining focusable elements.
You have two options for solving this:
Option 1: Define a static boolean field called muiSkipListHighlight
on your component function, and set it to true
:
< span class = " token keyword" > function </ span> < span class = " token function" > MyListSubheader</ span> < span class = "token punctuation" > ( </ span> props< span class = "token operator" > : </ span> ListSubheaderProps< span class = "token punctuation" > ) </ span> < span class = " token punctuation" > { </ span>
< span class = " token keyword" > return </ span> < span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > ListSubheader</ span> </ span> < span class = " token spread" > < span class = "token punctuation" > { </ span> < span class = "token operator" > ... </ span> props< span class = "token punctuation" > } </ span> </ span> < span class = " token punctuation" > / > </ span> </ span> < span class = "token punctuation" > ; </ span>
< span class = " token punctuation" > } </ span>
MyListSubheader< span class = "token punctuation" > . </ span> muiSkipListHighlight < span class = " token operator" > = </ span> < span class = " token boolean" > true </ span> < span class = "token punctuation" > ; </ span>
< span class = " token keyword" > export </ span> < span class = " token keyword" > default </ span> MyListSubheader< span class = "token punctuation" > ; </ span>
< span class = " token comment" >
< span class = " token keyword" > return </ span> < span class = " token punctuation" > ( </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > Select</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = "token punctuation" >> </ span> </ span> Group < span class = " token number" > 1 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 1 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 1 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 2 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 2 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = "token punctuation" >> </ span> </ span> Group < span class = " token number" > 2 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 3 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 3 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 4 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 4 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token punctuation" > { </ span> < span class = "token comment" > </ span> < span class = "token punctuation" > } </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < / </ span> < span class = "token class-name" > Select</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
Copy (or $keyC)
Option 2: Place a muiSkipListHighlight
prop on each instance of your component.
The prop doesn't have to be forwarded to the ListSubheader, nor present in the underlying DOM element.
It just has to be placed on a component that's used as a subheader.
< span class = " token keyword" > export </ span> < span class = " token keyword" > default </ span> < span class = " token keyword" > function </ span> < span class = " token function" > MyListSubheader</ span> < span class = "token punctuation" > ( </ span>
props< span class = "token operator" > : </ span> ListSubheaderProps < span class = " token operator" > & </ span> < span class = " token punctuation" > { </ span> muiSkipListHighlight< span class = "token operator" > : </ span> boolean < span class = " token punctuation" > } </ span> < span class = "token punctuation" > , </ span>
< span class = " token punctuation" > ) </ span> < span class = " token punctuation" > { </ span>
< span class = " token keyword" > const </ span> < span class = " token punctuation" > { </ span> muiSkipListHighlight< span class = "token punctuation" > , </ span> < span class = " token operator" > ... </ span> other < span class = " token punctuation" > } </ span> < span class = " token operator" > = </ span> props< span class = "token punctuation" > ; </ span>
< span class = " token keyword" > return </ span> < span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > ListSubheader</ span> </ span> < span class = " token spread" > < span class = "token punctuation" > { </ span> < span class = "token operator" > ... </ span> other< span class = "token punctuation" > } </ span> </ span> < span class = " token punctuation" > / > </ span> </ span> < span class = "token punctuation" > ; </ span>
< span class = " token punctuation" > } </ span>
< span class = " token comment" >
< span class = " token keyword" > return </ span> < span class = " token punctuation" > ( </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > Select</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = " token attr-name" > muiSkipListHighlight</ span> < span class = "token punctuation" >> </ span> </ span> Group < span class = " token number" > 1 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 1 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 1 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 2 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 2 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = " token attr-name" > muiSkipListHighlight</ span> < span class = "token punctuation" >> </ span> </ span> Group < span class = " token number" > 2 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MyListSubheader</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 3 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 3 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = "token script language-javascript" > < span class = " token script-punctuation punctuation" > = </ span> < span class = "token punctuation" > { </ span> < span class = "token number" > 4 </ span> < span class = "token punctuation" > } </ span> </ span> < span class = "token punctuation" >> </ span> </ span> Option < span class = " token number" > 4 </ span> < span class = "token tag" > < span class = " token tag" > < span class = "token punctuation" > < / </ span> < span class = "token class-name" > MenuItem</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token punctuation" > { </ span> < span class = "token comment" > </ span> < span class = "token punctuation" > } </ span>
< span class = " token tag" > < span class = "token tag" > < span class = " token punctuation" > < / </ span> < span class = "token class-name" > Select</ span> </ span> < span class = "token punctuation" >> </ span> </ span>
< span class = " token punctuation" > ) </ span> < span class = "token punctuation" > ; </ span>
Copy (or $keyC)
We recommend the first option as it doesn't require updating all the usage sites of the component.
Keep in mind this is only necessary if you wrap the ListSubheader in a custom component.
If you use the ListSubheader directly, no additional code is required .
Accessibility To properly label your Select
input you need an extra element with an id
that contains a label.
That id
needs to match the labelId
of the Select
e.g.
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > InputLabel</ span> </ span> < span class = " token attr-name" > id</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>label<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Age< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > InputLabel</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > Select</ span> </ span> < span class = " token attr-name" > labelId</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>label<span class=" token punctuation">" </ span> </ span> < span class = " token attr-name" > id</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>select<span class=" token punctuation">" </ span> </ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>20<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>10<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Ten< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>20<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Twenty< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > Select</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
Copy (or $keyC)
Alternatively a TextField
with an id
and label
creates the proper markup and
ids for you:
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > TextField</ span> </ span> < span class = " token attr-name" > id</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>select<span class=" token punctuation">" </ span> </ span> < span class = " token attr-name" > label</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>Age<span class=" token punctuation">" </ span> </ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>20<span class=" token punctuation">" </ span> </ span> < span class = " token attr-name" > select</ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>10<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Ten< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>20<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Twenty< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > MenuItem</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > TextField</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
Copy (or $keyC)
For a native select , you should mention a label by giving the value of the id
attribute of the select element to the InputLabel
's htmlFor
attribute:
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > InputLabel</ span> </ span> < span class = " token attr-name" > htmlFor</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>select<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Age< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > InputLabel</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> < span class = " token class-name" > NativeSelect</ span> </ span> < span class = " token attr-name" > id</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>select<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> option</ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>10<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Ten< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> option</ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < </ span> option</ span> < span class = " token attr-name" > value</ span> < span class = " token attr-value" > < span class = " token punctuation attr-equals" > = </ span> < span class = " token punctuation" > "</span>20<span class=" token punctuation">" </ span> </ span> < span class = " token punctuation" > > </ span> </ span> Twenty< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> option</ span> < span class = " token punctuation" > > </ span> </ span>
< span class = " token tag" > < span class = " token tag" > < span class = " token punctuation" > < / </ span> < span class = " token class-name" > NativeSelect</ span> </ span> < span class = " token punctuation" > > </ span> </ span>
Copy (or $keyC)
Unstyled Base UI provides a headless ("unstyled") version of this React Select component . Try it if you need more flexibility in customization and a smaller bundle size.
API See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.