1

I am currently working on react js dashboard and use Material-UI components. There is a problem with Appbar. When I scroll down the page I want the appBar to disappear. But the position = "sticky" props mentioned in the AppBar api does not work. Also, I tried useScrollTrigger() function call in my code but it doesn't work.

My code part is here,

<div className={classes.root}> { console.log("return")}
      <CssBaseline />
      <AppBar color="default" position="absolute" className={clsx(classes.appBar, open && classes.appBarShift)}>
        <Toolbar className={classes.toolbar}>
        <ThemeProvider theme={theme}>
          {<Typography component="h1" variant="h6" color="secondary" noWrap className={classes.title}>
            <HomeIcon fontSize="large" />
          </Typography>}
          <Typography style={{fontSize:"3vw"}} color="secondary" className={classes.title}>
          {newTime.split(' ', 5).join(' ')}
          </Typography>
          
          <IconButton onClick={handleLogout} color="secondary">

            <ExitToAppIcon fontSize="large" />

          </IconButton>
        </ThemeProvider>
        </Toolbar>
      </AppBar>
</div>
 appBar: {
    zIndex: theme.zIndex.drawer + 1,
    transition: theme.transitions.create(['width', 'margin'], {
      easing: theme.transitions.easing.sharp,
      duration: theme.transitions.duration.leavingScreen,
    }),
  },
  appBarShift: {
    marginLeft: drawerWidth,
    width: `calc(100% - ${drawerWidth}px)`,
    transition: theme.transitions.create(['width', 'margin'], {
      easing: theme.transitions.easing.sharp,
      duration: theme.transitions.duration.enteringScreen,
    }),
  },

I tried position="static" but the whole page content disappeared. Only a white blank screen remained with an appBar. What should I do? Is there any way to solve this problem? I couldn't find the reason. Thanks for your help!

noobinmath
  • 175
  • 2
  • 12
  • have you tried removing `position="absolute" `? and also share their styles for better refrence – Rajiv Feb 01 '21 at 19:19
  • yes, I have but nothing was changed. `` – noobinmath Feb 01 '21 at 19:32
  • It is little bit urgent, do you have any idea ? – noobinmath Feb 01 '21 at 22:42
  • It's look like by default the material-ui's AppBar is sticky I made a [sandbox](https://codesandbox.io/s/material-demo-forked-myquq) with a part of your code and removed all className props and it works.... may be an issue with your theme. – antoineso Feb 02 '21 at 08:57

0 Answers0