代码之家  ›  专栏  ›  技术社区  ›  bc291

React.js-抽屉盖页面内容

  •  1
  • bc291  · 技术社区  · 6 年前

    我决定在我的react项目的material ui库中实现Drawer组件,如下所示:

    class RightDrawer extends React.Component {
      state = {
        open: false,
      };
    
      handleDrawerOpen = () => {
        this.setState({ open: true });
      };
    
      handleDrawerClose = () => {
        this.setState({ open: false });
      };
    
      render() {
        const { classes, children, theme } = this.props;
    
        return (
          <div className={classes.root}>
            <AppBar
              position="absolute"
              className={classNames(classes.appBar, this.state.open && classes.appBarShift)}
            >
              <Toolbar disableGutters={!this.state.open}>
                <IconButton
                  color="inherit"
                  aria-label="Open drawer"
                  onClick={this.handleDrawerOpen}
                  className={classNames(classes.menuButton, this.state.open && classes.hide)}
                >
                  <MenuIcon />
                </IconButton>
                <Typography variant="title" color="inherit" noWrap>
                  Mini variant drawer
                </Typography>
              </Toolbar>
            </AppBar>
            <Drawer
              variant="permanent"
              classes={{
                paper: classNames(classes.drawerPaper, !this.state.open && classes.drawerPaperClose),
              }}
              open={this.state.open}
            >
              <div className={classes.toolbar}>
                <IconButton onClick={this.handleDrawerClose}>
                  {theme.direction === 'rtl' ? <ChevronRightIcon /> : <ChevronLeftIcon />}
                </IconButton>
              </div>
              <Divider />
    
                <List>{mailFolderListItems}</List>
            </Drawer>
            <main className={classes.content}>
              <div className={classes.toolbar} />
              {children}
            </main>
          </div>
        );
      }
    }
    
    RightDrawer.propTypes = {
      classes: PropTypes.object.isRequired,
      theme: PropTypes.object.isRequired,
    };
    
    export default withStyles(styles, { withTheme: true })(RightDrawer);
    

    {children} . 最终结果是: enter image description here

    enter image description here

    我应该直接将Drawer插入App.js,而不是将每个组件包装在里面吗?可能是因为 className={classes.root} ?

    1 回复  |  直到 6 年前
        1
  •  3
  •   El.    6 年前

    您提供的问题描述和代码不足以回答此问题。 我发现,如果你想要一个全高的抽屉,你可以加上 height 例如:

    root: {
        height: '100vh',
    }