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>
);
}
}
The Drawer, when open, should render a div
tag to display an overlay which can be clicked to close the Drawer.
The menu is created, without an overlay, so I can't close the menu by clicking outside of it.
Very simple usage: https://codesandbox.io/s/n51myz595l
I'm trying to have a Drawer like the demos.
The bug are here and on my Mac High Sierra with Google chome: https://codesandbox.io/s/n51myz595l
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!
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, usevariant="temporary"
(the default value forvariant
).