繁体   English   中英

如何用带样式的组件覆盖 MUI PaperProps?

[英]How to override MUI PaperProps with styled components?

我正在使用 MUI,我想用样式化的组件覆盖菜单的宽度。

我试过这个:

const StyledMenu = styled(Menu)`
  && {
    width: 100%;
  }
`;

什么也没发生。

然后我发现 MUI 有 PaperProps 并且在应用时:

<StyledMenu
  id="menu-appbar"
  PaperProps={{
    style: {
      width: '100%',
    },
  }}
>

我得到了想要的结果,但我想通过 styled-components 来完成它,这可能吗?

您在PaperProps属性中编写的每个样式都会影响.MuiPaper-root class。因此您的代码可以是这样的:

const StyledMenu = styled(Menu)`
  && {
    & .MuiPaper-root {
      width: 100%;
    }
  }
`;

可以在 文档中找到更多见解。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM