Textfield Select default value in Material-ui

Asked

Viewed 61 times

-1

It’s a basic question, I’m trying to leave the default value empty, but it always ends up filling with the first item:

<TextField
        select
        id="letter"
        name="letter"
        label="Letra"
        defaultValue=""
        SelectProps={{
          native: true
        }}
        variant="outlined"
        margin="normal"
        fullWidth
      >
        <option key={1} value={1}>
          A
        </option>
        <option key={3} value={2}>
          B
        </option>
        <option key={3} value={3}>
          C
        </option>
</TextField>

Follow the codesandbox with the cited example https://codesandbox.io/s/material-ui-select-2jw0c?file=/src/App.js

1 answer

0


I don’t know if it’s the best way, but I added it and it worked here:

<option disabled selected value={""}></option>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.