简体   繁体   English

MUI v5:失败的道具类型:`Grid` 的道具`direction` 只能与`container` 道具一起使用

[英]MUI v5: Failed prop type: The prop `direction` of `Grid` can only be used together with the `container` prop

I'm styling a MUI v5 Grid as follows:我正在对 MUI v5 Grid样式设置,如下所示:

const SettingsGrid = styled(Grid)(({ theme }) => ({
    width: `calc(100% - calc(${Number(theme.spacing(2))} * 2))`,
    margin: theme.spacing(2),

    '& .MuiCard-root + .MuiTypography-subtitle1': {
        marginTop: theme.spacing(4),
    },
}))

Then, I'm using it as follows:然后,我使用它如下:

<Box m={1} overflow="auto">
  <SettingsGrid
      container
      direction="row"
      justifyContent="center"
  >
      <Grid
          direction="column"
          style={{ minWidth: '35em', maxWidth: '60em' }}
      >
          <!-- ... -->
      </Grid>
    </SettingsGrid>
</Box>

This now throws this console warning at runtime:现在在运行时抛出这个控制台警告:

Failed prop type: The prop `direction` of `Grid` can only be used together with the `container` prop.

I've tried with container={true} but this doesn't help.我试过container={true}但这没有帮助。 It seems as if the container property gets lost in styled() .似乎container属性在styled()丢失了。 How can I fix this?我怎样才能解决这个问题? I'm at a loss.我不知所措。

EDITH: https://codesandbox.io/s/gritty-styled-grid-7l04g伊迪丝: https ://codesandbox.io/s/gritty-styled-grid-7l04g

The direction prop of your Grid is only valid if the container prop is set to true , so add the missing container prop in your inner Grid .您的Griddirection道具仅在container道具设置为true时才有效,因此在您的内部Grid添加缺少的container道具。 Internally, a container Grid has the display set to flex , and the direction is mapped to flex-direction , flex-direction is meaningless if the layout is not flex:在内部,一个容器Grid将 display 设置为flex ,并且direction映射到flex-direction ,如果布局不是 flex 则flex-direction没有意义:

<Grid container direction='column'

Just to add to what NearHuscarl has mentioned, this is the place where you are missing the container prop.补充一下 NearHuscarl 提到的内容,这是您缺少container道具的地方。


<Box m={1} overflow="auto">
  <SettingsGrid
      container
      direction="row"
      justifyContent="center"
  >
      <Grid
          container  <<<------------------ you are missing this 
          direction="column"
          style={{ minWidth: '35em', maxWidth: '60em' }}
      >
          <!-- ... -->
      </Grid>
    </SettingsGrid>
</Box>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 失败的道具类型:必须在容器上使用 Grid 的道具 justify - Failed prop type: The prop justify of Grid must be used on container 道具类型失败:提供给“字段”的道具“组件”无效。 安装 mui v4 后 - Failed prop type: Invalid prop `component` supplied to `Field`. after installing mui v4 如何在 MUI v5 sx prop 中实现条件样式 - How to implement conditional styles in MUI v5 sx prop 响应式道具值在 MUI v5 中不起作用 - Responsive prop value doesn't work in MUI v5 在 MUI v5 中使用 sx 道具的最佳方式是什么? - What is the best way to use sx prop in MUI v5? 如何修复“失败的道具类型:`grid` 的属性`spacing` 必须用于`container`? - How to fix "Failed prop type: The property `spacing` of `grid` must be used on `container`? 失败的道具类型:提供给“ForwardRef(Grid)”的无效道具“children” - Failed prop type: Invalid prop `children` supplied to `ForwardRef(Grid)` 失败的道具类型:提供给“ForwardRef(Grid)”的无效道具“lg” - Failed prop type: Invalid prop `lg` supplied to `ForwardRef(Grid)` MUI 失败的道具类型:提供给 `ForwardRef(Link)` 的价值为 `#ff9800` 的无效道具`color`, - MUI Failed prop type: Invalid prop `color` of value `#ff9800` supplied to `ForwardRef(Link)`, 失败的道具类型:提供给“重定向”的无效道具“到” - Failed prop type: Invalid prop `to` supplied to `Redirect`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM