I try to create AppBar clipped to the page top and hovering over other Drawer with React Hooks and Material Ui using class name. All as described in: https://material-ui.com/demos/drawers/#clipped-under-the-app-bar
So we have
const useStyles = makeStyles(theme => ({
root: {
display: 'flex',
height: '100%',
},
drawer: {
width: drawerWidth,
flexShrink: 0,
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
},
menuButton: {
marginRight: 20,
[theme.breakpoints.up('md')]: {
display: 'none',
},
},
}));
And reder:
<div className={classes.root}>
<CssBaseline/>
<LoadingResults showLoading={showLoadingSpinner}/>
<AppBar position="fixed" className={classes.appBar} >
...
</AppBar>
....
Problem is that the style applied with className is added last of the element so its not overriding the orignal style:
class="MuiPaper-root-12 MuiPaper-elevation4-18 MuiAppBar-root-3 MuiAppBar-positionFixed-4 MuiAppBar-colorPrimary-10 mui-fixed Hook-appBar-1b6f20g"
I know I can use inline styles but wonder to know if I can override styles using classNames with hooks as it was with "legacy" component approach ?
Here is sandbox: https://codesandbox.io/s/w7njqorzy7?fontsize=14
What happens is that in sandbox the code works ok (appbar over lefthand side container)
But when the same project is downloaded and compiled it's not ok:
Looking at the debuger the styles are inline. In the sandbox hooks are at the bottom:
In the browser when app is run via "run start" its on top:
So this is the difference, but why and how to fix this ?
class
property has no bearing on the resulting styles. The order that matters is the order in which the CSS class definitions occur (e.g. the order of the style elements<style>...</style>
). Please show a CodeSandbox that reproduces the problem you are having. – Ryan Cogswell@material-ui/styles
you need to perform the bootstrap step (material-ui.com/css-in-js/basics/…) – Josh Wooding