question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AppBar offset component when it's fixed

See original GitHub issue

On material design react components repo they have a component that helps when the top bar is fixed:

Use the <TopAppBarFixedAdjust /> component to give your content top-padding, so it isn’t hidden on page render.

I’ve made one based on material UI that helps, so you could integrate it.

import React from "react";
import { makeStyles } from "@material-ui/styles";

const useStyles = makeStyles(theme => ({
  offset: {
    ...theme.mixins.toolbar,
    flexGrow: 1
  }
}))

export default function AppBarOffset() {
  const classes = useStyles();
  return <div className={classes.offset} />;
}

Use as:

<AppBar position="fixed" />
<AppBarOffset />
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
oliviertassinaricommented, Aug 1, 2019

What’s wrong with the Toolbar component?

import React from "react";
import {
  Box,
  CssBaseline,
  AppBar,
  Toolbar,
  Typography,
  Button,
  IconButton,
} from "@material-ui/core";
import MenuIcon from "@material-ui/icons/Menu";

export default function ButtonAppBar() {
  return (
    <div>
      <CssBaseline />
      <AppBar position="fixed">
        <Toolbar>
          <Box mr={2}>
            <IconButton edge="start" color="inherit" aria-label="menu">
              <MenuIcon />
            </IconButton>
          </Box>
          <Typography variant="h6">News</Typography>
          <Box flexGrow={1} />
          <Button color="inherit">Login</Button>
        </Toolbar>
      </AppBar>
      <Toolbar />
      Text to be shown.
    </div>
  );
}

https://codesandbox.io/s/material-demo-bnlpz

2reactions
oliviertassinaricommented, Oct 14, 2019

@adeelibr Yes, I think that it would be great to document the placement issue. For instance, I have seen @jlengstorf hit by this problem in a recent video.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AppBar offset component when it's fixed · Issue #16844 - GitHub
When the appbar is fixed, you always need this offset, so the content initially doesn't get under the bar. In material UI website...
Read more >
Content beneath fixed AppBar - Stack Overflow
And I want the mui.Paper content appear beneath the AppBar, and not hidden by it. Is there a component I'm missing somewhere?
Read more >
App Bar React component - Material UI - MUI
When you render the app bar position fixed, the dimension of the element doesn't impact the rest of the page. This can cause...
Read more >
App Bar - Demos - react-md
#Fixed with Offset ... App bars are generally great for using in your main layout, so there is also the ability to fix...
Read more >
Material UI AppBar - React Navbar Examples
This seems to be why using the Toolbar component as the first component works, because it is offset by 8px, so the start...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found