如何在 MUI 网格项目中垂直居中输入标签?

How can I verically center InputLabel inside MUI Grid item?

我想在 MUI Grid 项目中垂直居中 InputLabel。 我试过以下:

import { FormControl, Grid, Input, InputLabel, TextField } from "@mui/material";

export default function App() {
  return (
    <Grid container>
      <Grid item xs={2}>
        <InputLabel htmlFor="name-input">First Name: </InputLabel>
      </Grid>
      <Grid item xs={10}>
        <TextField size="small"></TextField>
      </Grid>
      <Grid item xs={2}>
        <InputLabel sx={{ verticalAlign: "middle" }} htmlFor="name-input">
          First Name:{" "}
        </InputLabel>
      </Grid>
      <Grid item xs={10}>
        <TextField size="small"></TextField>
      </Grid>
    </Grid>
  );
}

但它没有垂直对齐:

codesandbox link

请注意,在第二个 InputLabel 中设置 sx={{ verticalAlign: "middle" }} 也无济于事。

如何(可能理想地)在 Grid 项目中垂直居中 InputLabel(或任何其他控件)?

如果我添加

display: flex;
align-items: center;

网格项目 div 有效。

我发现这是一个有用的 flexbox 解释器:https://css-tricks.com/snippets/css/a-guide-to-flexbox/

我已将它添加到您的沙盒中:https://codesandbox.io/s/peaceful-pascal-3rpokb?file=/src/App.js