0

I have the following code:

<Grid
  container
  spacing={0}
  direction="column"
  alignItems="center"
  justify="center"
  style={{ minHeight: "100vh" }}
>
  <FormControl>
    <TextField
      label="email"
      fullWidth
      type="email"
      value={email}
      onChange={e => setEmail(e.target.value)}
    ></TextField>
    <TextField
      label="body"
      type="body"
      fullWidth
      value={body}
      onChange={e => setBody(e.target.value)}
      multiline={true}
    ></TextField>
  </FormControl>
</Grid>

And this renders:

img

The reason I'm using Grid is because I wanted to center the form, as suggested from the answers here.

No matter what I do, I can't get the TextField to change width. I've added it into a Container, I've added the width style, nothing works. What am I doing wrong here?

Mike K
  • 7,621
  • 14
  • 60
  • 120

1 Answers1

2

According to Material-UI TextField docs, fullWidth prop:

If true, the input will take up the full width of its container.

The TextField container in this case is FormControl, and the FormControl width is calculated to contain it's children.
If you set FormControl to fullWidth as well, you will get what you want:

  <FormControl fullWidth>
Ido
  • 5,363
  • 2
  • 21
  • 30