html - 100% 高度不适用于抽屉,Material Design React

标签 html css reactjs material-design

我正在使用 React Material UI 中的响应式抽屉([文档][1])

我正在尝试更改它,以便抽屉的高度始终为 100%。为此,我尝试更改当前设置为 430 的根类的高度。但是,当我将其设置为百分比时,它只是默认为可能的最小高度。

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { withStyles } from 'material-ui/styles';
import Drawer from 'material-ui/Drawer';
import AppBar from 'material-ui/AppBar';
import Toolbar from 'material-ui/Toolbar';
import List from 'material-ui/List';
import { MenuItem } from 'material-ui/Menu';
import TextField from 'material-ui/TextField';
import Typography from 'material-ui/Typography';
import Divider from 'material-ui/Divider';
import { mailFolderListItems, otherMailFolderListItems } from './tileData';

const drawerWidth = 240;

const styles = theme => ({
  root: {
    width: '100%',
    height: 430,
    marginTop: theme.spacing.unit * 3,
    zIndex: 1,
    overflow: 'hidden',
  },
  appFrame: {
    position: 'relative',
    display: 'flex',
    width: '100%',
    height: '100%',
  },
  appBar: {
    position: 'absolute',
    width: `calc(100% - ${drawerWidth}px)`,
  },
  'appBar-left': {
    marginLeft: drawerWidth,
  },
  'appBar-right': {
    marginRight: drawerWidth,
  },
  drawerPaper: {
    position: 'relative',
    height: '100%',
    width: drawerWidth,
  },
  drawerHeader: theme.mixins.toolbar,
  content: {
    backgroundColor: theme.palette.background.default,
    width: '100%',
    padding: theme.spacing.unit * 3,
    height: 'calc(100% - 56px)',
    marginTop: 56,
    [theme.breakpoints.up('sm')]: {
      height: 'calc(100% - 64px)',
      marginTop: 64,
    },
  },
});

class PermanentDrawer extends React.Component {
  state = {
    anchor: 'left',
  };

  handleChange = event => {
    this.setState({
      anchor: event.target.value,
    });
  };

  render() {
    const { classes } = this.props;
    const { anchor } = this.state;

    const drawer = (
      <Drawer
        type="permanent"
        classes={{
          paper: classes.drawerPaper,
        }}
        anchor={anchor}
      >
        <div className={classes.drawerHeader} />
        <Divider />
        <List>{mailFolderListItems}</List>
        <Divider />
        <List>{otherMailFolderListItems}</List>
      </Drawer>
    );

    let before = null;
    let after = null;

    if (anchor === 'left') {
      before = drawer;
    } else {
      after = drawer;
    }

    return (
      <div className={classes.root}>
        <TextField
          id="permanent-anchor"
          select
          label="Anchor"
          value={anchor}
          onChange={this.handleChange}
          margin="normal"
        >
          <MenuItem value="left">left</MenuItem>
          <MenuItem value="right">right</MenuItem>
        </TextField>
        <div className={classes.appFrame}>
          <AppBar className={classNames(classes.appBar, classes[`appBar-${anchor}`])}>
            <Toolbar>
              <Typography type="title" color="inherit" noWrap>
                Permanent drawer
              </Typography>
            </Toolbar>
          </AppBar>
          {before}
          <main className={classes.content}>
            <Typography type="body1">
              {'You think water moves fast? You should see ice.'}
            </Typography>
          </main>
          {after}
        </div>
      </div>
    );
  }
}

PermanentDrawer.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(PermanentDrawer);


  [1]: https://material-ui-next.com/demos/drawers/

最佳答案

您可能已经解决了这个问题,但我遇到了同样的问题。我有一种预感,高度问题出在 #root id 之内。所以我将我的根 div id 更改为另一个(我使用了 application)并像这样设置高度:

appFrame: {
    ...
    height: '100vh',
}

它奏效了。所以一个疯狂的猜测是他们已经为#root id 定义了一个样式。我会在有时间的时候尝试找出这是否正确

关于html - 100% 高度不适用于抽屉,Material Design React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47519393/

相关文章:

javascript - 在 React 应用程序上实现 Google map API

javascript - 溢出-y : scroll causing issues with JQuery

javascript - 防止 HTML5 输入上的智能引号

javascript - 当我点击播出或关闭按钮时,我想让一组客户在线。我也想全部展示;播出和播出

css - 什么渲染速度更快、预定义图像 alpha 或不透明度?

html - 是否可以针对不同的屏幕分辨率调整网页大小,同时保持由给定高度和宽度设置的预设纵横比?

node.js - `npm start` 给出生命周期错误并以状态 9 退出

javascript - HTML/JS 调试器

javascript - 将键值对传递给 JavaScript 文件

javascript - 函数类型的无状态函数组件 prop 不会更新