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] Get AppBar height

See original GitHub issue

AppBar height dynamically changes depending on the browser window width. How can I get its height to set margin for the content when AppBar is absolutely positioned?

Tech Version
Material-UI 1.0.0-beta.37
React 16.2.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

27reactions
pganstercommented, Dec 27, 2021

A hook I’ve created to get the app bar height that replicates the height SxProps setting of the AppBar:

import { useMediaQuery, useTheme } from '@mui/material';

type MinHeight = {
  minHeight: number,
};

export default function useAppBarHeight(): number {
  const {
    mixins: { toolbar },
    breakpoints,
  } = useTheme();
  const toolbarDesktopQuery = breakpoints.up('sm');
  const toolbarLandscapeQuery = `${breakpoints.up('xs')} and (orientation: landscape)`;
  const isDesktop = useMediaQuery(toolbarDesktopQuery);
  const isLandscape = useMediaQuery(toolbarLandscapeQuery);
  let currentToolbarMinHeight;
  if (isDesktop) {
    currentToolbarMinHeight = toolbar[toolbarDesktopQuery];
  } else if (isLandscape) {
    currentToolbarMinHeight = toolbar[toolbarLandscapeQuery];
  } else {
    currentToolbarMinHeight = toolbar;
  }
  return (currentToolbarMinHeight as MinHeight).minHeight;
}

3reactions
oliviertassinaricommented, Mar 20, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get AppBar height in Flutter - Stack Overflow
AppBar has a fixed height of 56. You should create your own appbar implementing PreferredSizeWidget class ...
Read more >
How to Get AppBar Height In Flutter?
Firstly declare the AppBar widget that you will use in your Scaffold. ... Now you can get the height of your appBar using...
Read more >
How to Set Height of AppBar on Flutter - Flutter Campus
In this example, we are going to show you the easiest way to set the height of AppBar on Flutter app. We will...
Read more >
toolbarHeight property - AppBar class - material library - Dart API
Defines the height of the toolbar component of an AppBar. By default, the value of toolbarHeight is kToolbarHeight. Implementation. final double?
Read more >
Flutter: Get the Heights of AppBar and CupertinoNavigationBar
This article is about the heights of the AppBar (material app bar) and CupertinoNavigationBar (iOS-style app bar) in Flutter. Height of a ...
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