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

标签 material-ui drawer

我从剪辑的抽屉示例代码开始,并尝试围绕它进行构建。在示例中插入组件时(即,用其他内容替换“{'你认为水移动得很快?你应该看到冰。'}”),内容受抽屉高度的限制。尝试在示例之外插入内容时,一切都从抽屉下方开始。

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

我最初是从永久抽屉示例开始的,除了我需要将抽屉定位在应用栏下方之外,一切正常。

最佳答案

布局由一个 flex 容器组成,其中包含 Drawer 和主要内容区域。内容区域 (.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,
    },
  })

实例(codesandbox)

Permanent Drawer - clipped below appbar

Permanent Drawer - full height

关于material-ui - 试图让 Material-UI 裁剪抽屉在 flex 布局中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50263230/

相关文章:

Flutter抽屉和按钮导航问题

navigation - 如何 - 带有持久子屏幕的 Flutter Drawer

javascript - 我们如何设置由 ReactJS 中的 material-ui 创建的 DOM 的样式?

reactjs - MUI-Autocomplete 不会在选择时更新值

javascript - React 初学者问题 : Textfield Losing Focus On Update

reactjs - 使用 MUI 自定义输入

javascript - 在顶部 Material UI <Textfield/> 上垂直对齐文本

ios - iPad 的 SplitView 和 iPhone 的菜单抽屉

java - 启动时打开抽屉导航