Material-ui: No overlay with Drawer

Created on 12 Apr 2018  路  6Comments  路  Source: mui-org/material-ui


I'm trying to use the Drawer component, it works, but without the Overlay.

I'm using it in a very simple component.

class AppMenu extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      isOpen: true,
    };

    this.handleCloseDrawer = this.handleCloseDrawer.bind(this);
  }

  handleCloseDrawer() {
    this.setState({
      isOpen: false,
    });
  }

  render() {
    const { isOpen } = this.state;

    return (
      <div>
        <Drawer
          anchor="left"
          open={this.state.isOpen}
          onClose={this.handleCloseDrawer}
          variant="persistent"
        >
          <div
            tabIndex={0}
            role="button"
            onClick={this.handleCloseDrawer}
            onKeyDown={this.handleCloseDrawer}
          >
            <MenuItem>Menu Item</MenuItem>
          </div>
        </Drawer>
      </div>
    );
  }
}

  • [ x ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior


The Drawer, when open, should render a div tag to display an overlay which can be clicked to close the Drawer.

Current Behavior

The menu is created, without an overlay, so I can't close the menu by clicking outside of it.

Steps to Reproduce (for bugs)

Very simple usage: https://codesandbox.io/s/n51myz595l

Context


I'm trying to have a Drawer like the demos.

Your Environment

The bug are here and on my Mac High Sierra with Google chome: https://codesandbox.io/s/n51myz595l

question

Most helpful comment

You are using variant="persistent", which doesn't have an overlay because it is persistent. If you want a temporary drawer with an overlay that can close, use variant="temporary" (the default value for variant).

All 6 comments

You are using variant="persistent", which doesn't have an overlay because it is persistent. If you want a temporary drawer with an overlay that can close, use variant="temporary" (the default value for variant).

You're not seeing an overlay because you're using a persistent draw. Try removing the variant prop.

Thank you guys, very sorry about that.

Oops, we both replied at the same time. Jinx!

We also have a backdrop component. It's not documented yet but it's public:
https://github.com/mui-org/material-ui/blob/b338fa3c285b54fa2d3d322bd1b4ab0de61f163d/src/index.js#L48

You're not seeing an overlay because you're using a persistent draw. Try removing the variant prop.

This was how I put a backdrop behind a persistent drawer eventually, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

ghost picture ghost  路  3Comments

sys13 picture sys13  路  3Comments

revskill10 picture revskill10  路  3Comments

ghost picture ghost  路  3Comments