试图让Material-UI剪裁的抽屉在flex布局中工作

时间:2018-05-09 23:02:54

标签: material-ui drawer

我开始使用剪切的抽屉示例代码并尝试围绕它构建。当在样品中插入组件时(即,替换'{'您认为水移动速度快?您应该看到冰。'}与其他内容),内容受到抽屉高度的限制。当试图在样本之外插入内容时,一切都从抽屉下面开始。

预期行为:将内容放置在抽屉周围的任何位置的能力。根据抽屉菜单选择,我有不同的组件隐藏/变得可见

我最初从永久抽屉示例开始,一切正常,但我需要将抽屉放在应用栏下方。

1 个答案:

答案 0 :(得分:4)

布局包含一个包含Drawer和主要内容区域的Flex容器。内容区域(.appContent)展开以填充抽屉右侧(或左侧)的空间。您的所有内容都应放在此元素中。

已更新:修复了适用于IE 11的样式

基本结构:

<div className={classes.root}>
  <AppBar position="fixed" className={classes.appBar} />
  <Drawer 
    variant="permanent"
    className={classes.drawer}
    classes={{ paper: classes.drawerPaper }} 
  />
  <main className={classes.appContent}>
    {/* Page content goes here */}
  </main>
</div>

样式

const styles = theme => ({
  // The main flex container for the app's layout. Its min-height
  // is set to `100vh` so it always fill the height of the screen.
  root: {
    display: "flex",
    minHeight: "100vh",
    zIndex: 1,
    position: "relative",
    overflow: "hidden",
  },
  appBar: {
    zIndex: theme.zIndex.drawer + 1
  },
  // Styles for the root `div` element in the `Drawer` component.
  drawer: {
    width: theme.layout.drawerWidth
  },
  // Styles for the `Paper` component rendered by `Drawer`.
  drawerPaper: {
    width: "inherit",
    paddingTop: 64  // equal to AppBar height (on desktop)
  },
  // Styles for the content area. It fills the available space
  // in the flex container to the right (or left) of the drawer.
  appContent: theme.mixins.gutters({
    // https://github.com/philipwalton/flexbugs#flexbug-17
    flex: '1 1 100%', // Updated to fix IE 11 issue
    maxWidth: "100%",
    paddingTop: 80,   // equal to AppBar height + 16px
    margin: '0 auto',
    // Set the max content width for large screens
    [theme.breakpoints.up('lg')]: {
      maxWidth: theme.breakpoints.values.lg,
    },
  })

实例(代码框)

Permanent Drawer - clipped below appbar

Permanent Drawer - full height