Material-ui: SelectField has no defaultValue

Created on 26 Sep 2016  路  7Comments  路  Source: mui-org/material-ui

This is very annoying.
You can't set the value by props, and intercept the new value selected to set it in the state...

Can you fix that, all the other form field have this "defaultValue" props.

Most helpful comment

@Kornflexx I am not sure I understand what you mean. I have the same problem, I need to use a SelectField as uncontrolled component, and SelectFields should support the defaultValue attribute, according to React's docs, which it currently does not. Unless I am mistaken, could you re-open this issue ?

All 7 comments

SelectField seems to can switch between uncontroled and controled value without throwing an error.
My bad sorry.

@Kornflexx I am not sure I understand what you mean. I have the same problem, I need to use a SelectField as uncontrolled component, and SelectFields should support the defaultValue attribute, according to React's docs, which it currently does not. Unless I am mistaken, could you re-open this issue ?

Google brought me here.. I also want to use an uncontrolled SelectField.

Any chances?

Me too!

Can anyone please tell me how to use defaultValue on an uncontrolled SelectField?

@Zregnateews if you are using "next" version you can do the following:

<Select native defaultValue={30}}> <option value="" /> <option value={10}>Ten</option> <option value={20}>Twenty</option> <option value={30}>Thirty</option> </Select>
https://material-ui-next.com/demos/selects/

Hope it helps you!.

Ran into this issue myself i will just leave this here for the next dev who runs into this issue

  1. pass in a displayEmpty prop to the Select component , this prop is a boolean so it must be set to true.
  2. pass in a renderValue prop which is a function that returns the value that should be displayed.

ie :

<Select displayEmpty defaultValue="value" renderValue={ () => dashboardState.month} onChange={e => handleChange(e.target.value) } > { ...options } </Select>

Was this page helpful?
0 / 5 - 0 ratings