Material ui 材质UI:无法在网格方向=列对齐项目=”内调整网格项目的大小;中心“;

Material ui 材质UI:无法在网格方向=列对齐项目=”内调整网格项目的大小;中心“;,material-ui,Material Ui,当我用direction=column和alignItems=“center”创建网格时。我的子网格项具有固定大小,我无法使用xs={…}更改它。下面的代码生成具有相同宽度的文本字段。删除“方向”或“对齐”项会将栅格调整为指定的xs。 我希望有更宽的文本字段,并且仍然将它们放在中间 <Grid container spacing={2} direction="column" alignItems="center"> <Grid item xs={4}>

当我用direction=column和alignItems=“center”创建网格时。我的子网格项具有固定大小,我无法使用xs={…}更改它。下面的代码生成具有相同宽度的文本字段。删除“方向”或“对齐”项会将栅格调整为指定的xs。 我希望有更宽的文本字段,并且仍然将它们放在中间

<Grid container spacing={2} direction="column" alignItems="center">
          <Grid item xs={4}>
            <TextField
              name="username"
              variant="outlined"
              required
              fullWidth
              id="username"
              label="Username"
              autoFocus
              value="peter"
            />
          </Grid>
          <Grid item xs={6}>
            <TextField
              variant="outlined"
              required
              fullWidth
              id="shortDescription"
              label="Short Description"
              name="shortDescription"
              value="I create awesome games"
            />
          </Grid>
</Grid>

我不确定这是一个bug还是材质ui的预期行为。也许任何人都知道使用方向或对齐项的解决方法


您可以在

上查看和测试该问题,谢谢。我已经用多个容器重写了代码

import React, { Component } from "react";
import Grid from "@material-ui/core/Grid";
import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import { withStyles } from "@material-ui/core/styles";
import Avatar from "@material-ui/core/Avatar";
import Button from "@material-ui/core/Button";
import Container from "@material-ui/core/Container";

const styles = theme => ({
  debug: {
    border: "1px grey solid"
  },
  root: {
    marginTop: 32
  },
  fieldName: {},
  avatar: {
    width: 200,
    height: 200
  },
  submitButton: {}
});

class EditProfile extends Component {
  render() {
    const { classes } = this.props;

    return (
      <Container maxWidth="xs">
        <Grid container className={classes.root} justify="center">
          <Grid item>
            <Avatar
              item
              alt="Remy Sharp"
              src="https://picsum.photos/300/300"
              className={classes.avatar}
            />
          </Grid>
          <Grid item>
            <Typography variant="h5" align="center">
              Change Profile Photo
            </Typography>
          </Grid>
        </Grid>
        <Grid container spacing="2" className={classes.root}>
          <Grid item xs={12}>
            <TextField
              name="username"
              variant="outlined"
              required
              fullWidth
              id="username"
              label="Username"
              autoFocus
              value="jingyi4"
            />
          </Grid>
          <Grid item xs={12}>
            <TextField
              variant="outlined"
              required
              fullWidth
              id="shortDescription"
              label="Short Description"
              name="shortDescription"
              value="I create awesome games"
            />
          </Grid>
          <Grid item xs={12}>
            <TextField
              variant="outlined"
              required
              fullWidth
              id="longDescription"
              label="Long Description"
              name="longDescription"
              value={`One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me?" he thought. It wasn't a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer. Gregor then turned to look out the window at the dull weather. Drops "`}
              multiline
            />
          </Grid>
          <Grid container justify="center" className={classes.root}>
            <Button
              type="submit"
              variant="contained"
              color="primary"
              className={classes.submitButton}
              disabled
            >
              Submit
            </Button>
          </Grid>
        </Grid>
      </Container>
    );
  }
}

export default withStyles(styles)(EditProfile);
import React,{Component}来自“React”;
从“@material ui/core/Grid”导入网格;
从“@material ui/core/TextField”导入TextField;
从“@material ui/core/Typography”导入排版;
从“@material ui/core/styles”导入{withStyles}”;
从“@material ui/core/Avatar”导入化身;
从“@物料界面/核心/按钮”导入按钮;
从“@material ui/core/Container”导入容器;
常量样式=主题=>({
调试:{
边框:“1px灰色实心”
},
根目录:{
玛金托普:32
},
字段名:{},
化身:{
宽度:200,
身高:200
},
submitButton:{}
});
类EditProfile扩展组件{
render(){
const{classes}=this.props;
返回(
更改个人资料照片
这是预期的行为:。