I want my drawer component to open UNDER the AppBar Component, not covering it. But this was never awsered for this new version of @Material-Ui/core.
Any idea of how can I do that?
Currently, it's opening in a way that covers AppBar. That is not what I want, I want the drawer to open UNDER the appBar component, like any normal app.
Here is my code:
const styles = theme => ({
root: {
flexGrow: 1,
},
flex: {
flex: 1,
},
menuButton: {
marginLeft: -12,
marginRight: 20,
},
list: {
width: 250,
},
});
class ClippedDrawer extends React.Component {
constructor(props){
super(props);
this.state={
open: false,
}
}
toggleDrawer(){
this.setState({
open: !this.state.open,
});
};
render(){
const { classes } = this.props;
return(
<div className={classes.root}>
<AppBar position="relative" className={classes.appBar}>
<Toolbar>
<IconButton className={classes.menuButton} onClick={()=>this.toggleDrawer()} color="inherit" aria-label="Menu">
<MenuIcon />
</IconButton>
<Typography variant="title" color="inherit" className={classes.flex}>
Title
</Typography>
<Button color="inherit">Login</Button>
</Toolbar>
</AppBar>
<Drawer className={classes.drawer} open={this.state.open} onClose={()=>this.toggleDrawer()}>
<div
tabIndex={0}
role="button"
onClick={()=>this.toggleDrawer()}
onKeyDown={()=>this.toggleDrawer()}
>
<div className={classes.list}>
<List>ola</List>
<Divider />
<List>xau</List>
</div>
</div>
</Drawer>
</div>
);
}
}
ClippedDrawer.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(ClippedDrawer);
Just use position="sticky" instead of position="fixed" for your AppBar.
To set the background color of the Material UI drawer, we call the makeStyles function to create the styles. Then we can apply the styles with the useStyles hook returned by makeStyles . We call makeStyles with an object that has the properties set to objects with the styles.
Often referred to as a NavBar, the AppBar will help you include page title, logo and navigation items to offer sleek, customizable app navigation. Part of the KendoReact library along with 100+ professional UI components built with React for React, from the ground up.
Set the AppBar's position to relative:
appBar: {
...
position: 'relative',
zIndex: theme.zIndex.drawer + 1,
},
If it doesn't work then you may also need to set the zIndex explicitly to 1400.
You will have to set CSS z-index property for the appBar class in styles
[theme.breakpoints.up("sm")]: {
width: "100%"
},
zIndex: theme.zIndex.drawer + 1
}
This appBar class in default class for AppBar component
In your case there might be a marginLeft for the appBar and for theme.breakpoints.up("sm") width might be calc(100% - (drawerWidth))
replace it with width 100%
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With