-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AppBar offset component when it's fixed #16844
Comments
@rhuanbarreto Do you have an example where the app bar fails to live up its expectations? |
When the appbar is fixed, you always need this offset, so the content initially doesn't get under the bar. In material UI website main page this is made by a div with a class called jss3 where it adds a paddingTop of 64px. But this value is variable and depends on the viewport. So it's not straightforward to do this. So this offset must be set programatically. Link for codesanbox showing the problem: https://codesandbox.io/s/material-demo-ejxmq. There is a text hidden under the bar. |
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>
);
} |
Great! Using the |
I agree about the documentation aspect. It's the same pattern we use in these demos: https://material-ui.com/components/app-bar/#scrolling. What do you think of a |
I think this could be good! This will probably help lot's of people once a fixed appbar is very common usage. And explaining all the ways to do this is the best that can be done. |
Can I document this feature for usage of & theme.mixins.toolbar for Appbar position fixed demo? 😅 |
@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. |
How to use Two appbar in same page? The Proposed solution is only for one AppBar. |
On material design react components repo they have a component that helps when the top bar is fixed:
I've made one based on material UI that helps, so you could integrate it.
Use as:
The text was updated successfully, but these errors were encountered: