The Material UI Drawer appears to be stuck and unresponsive when trying to move it beneath the

I am working on designing an interface with an Appbar and a drawer below it. Each component contains three divs with Bootstrap, housing groups of buttons.

The issue I am facing is that the Drawer is covering the Appbar and I am struggling to reposition it.

Below is the code snippet I am currently using:

<div className="App">

        <AppBar position="static">
          <Toolbar>
              <IconButton color="inherit" aria-label="Menu">
                <MenuIcon />
              </IconButton>
              <Typography variant="title" color="inherit" aria-label="Menu">
                title
              </Typography>
          </Toolbar>
        </AppBar>

        <Drawer
          variant="permanent"
          style={{width: '100%', zIndex: '1400', position:'absolute'}}
        >
          <Button>1</Button>
          <Button>2</Button>
          <Divider />
          <Button>1</Button>
          <Button>2</Button>
        </Drawer>
        <br />
        <div className="container-full">
          <div className="row">
            <div class="col-sm-6">  
              <GridList cellHeight={50} className={styles.gridList} cols={5}>

                <Button style={{width: '150px', border: '1px solid'}} variant="raised" color="primary">
                  <div 
                  style={{fontSize:'12px', display: 'flex', justifyContent: 'center', textAlign:'center'}}>
                    Mohnweckerl Wiener Gouda
                  </div>
                </Button>

Following the first bootstrap column, there is another "col-sm-4" and then a "col-sm-2". All the buttons are placed in a GridList.

For a visual representation, you can check out the image here.

The Drawer should ideally start where the arrows intersect. Any suggestions on how to achieve this?

Answer №1

The documentation for Material-UI refers to this as a Drawer that is positioned beneath the app bar. In order to achieve this effect, you must first assign a specific z-index value to your AppBar within the styles object:

const styles = theme => ({
  appBar: {
    // Ensure the app bar z-index is one level above the drawer
    zIndex: theme.zIndex.drawer + 1,
  },
});

This custom styling should then be applied to the AppBar component like so:

<AppBar position="absolute" className={classes.appBar}>

To prevent content in the drawer from being hidden under the app bar, you will need to adjust its positioning on the screen using the theme.mixins.toolbar. First, define the styles for the toolbar:

const styles = theme => ({
  appBar: {
    zIndex: theme.zIndex.drawer + 1,
  },
  toolbar: theme.mixins.toolbar,
});

Next, insert the following div at the beginning of your drawer's content:

<Drawer>
  <div className={classes.toolbar} />
  
  // Add other content for the drawer here as needed
</Drawer>

The toolbar style incorporates information about the app bar height from the current theme, ensuring that the content remains visible above the app bar.

A complete code example can be found here.

Answer №2

With the release of MUI v5, there have been changes to the default zIndex values:

const zIndex = {
  mobileStepper: 1000,
  fab: 1050,
  speedDial: 1050,
  appBar: 1100,
  drawer: 1200,
  modal: 1300,
  snackbar: 1400,
  tooltip: 1500,
};

This adjustment is significant as it clarifies why the drawer overlaps the appBar.

To address this issue in a different way using ThemeProvider, one can simply switch these values in Typescript:

// ./theme/index.tsx

import {
  ThemeProvider as MUIThemeProvider,
  createTheme,
} from "@mui/material/styles";
import { ReactNode } from "react";

interface ThemeProviderProps {
  children: ReactNode;
}

export const ThemeProvider = ({ children }: ThemeProviderProps) => {
  const theme = createTheme({ zIndex: { appBar: 1200, drawer: 1100 } });
  return (
    <MUIThemeProvider theme={theme}>
      {children}
    </MUIThemeProvider>
  );
};
// ./App.tsx

import { ThemeProvider } from "./theme";

function App() {
  return (
    <div className="App">
      <ThemeProvider>
        // your component(s)
      </ThemeProvider>
    </div>
  );
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

HTML 5 functions properly when loaded directly as a .html file, but encounters issues when hosted on either a Django or Node

I'm having trouble getting a video to play on a webpage. Initially, I followed a standard example I found online by using the following code: <video src='video.mp4' controls></video> When I open the .html file in Safari and dou ...

Acquire a handle on the object being hovered over in three.js using react

Currently, I am utilizing the react-three-fiber library to render a scene containing numerous smaller objects. My goal is to make all of these objects hoverable within the scene. Additionally, I aim to have access to the hovered objects so that I can manip ...

Every time I attempt to maintain an object's state, TypeScript keeps throwing this error at me

interface Data { petname: string, petprice: string, category: string, pettype: string, gender: string, short: string, details: string } const [petdata, setPetdata] = useState<Data>({}); const [img, setImg] = useSt ...

Utilizing Bootstrap to arrange table cells in a shifted manner

I'm new to utilizing bootstrap in web development. I've been exploring various examples of bootstrap templates that include tables, and I noticed that when I resize my browser window, the table adjusts accordingly. Now, I'm curious to know ...

Changing Ionic Column Widths Based on Content Length

In my dynamic ionic 2 grid system, I am facing a layout issue. <div> <ion-row> <ion-col > ; <ion-card-header class="card-header"> {{hunt.title}} </ion-card-header> </ion-col> <ion-col *ngIf="!hunt. ...

Role in HTML/CSS

I'm currently facing an issue with getting my footer to stick to the bottom of the page. In Internet Explorer, it appears centered under the rest of the content instead of at the very bottom. When I try to view it in Chrome, it ends up positioned next ...

In a React Redux application, I struggle with typing in the input fields and making changes

Can someone help me with a problem I'm having with this code? When I try to type on the inputs, nothing happens. Here is the link to the code: https://stackblitz.com/edit/react-hghsyk?file=reducers%2Findex.js ...

Is it possible to dynamically change the primary and secondary color of the Material UI theme palette during runtime?

Our application has default theme palette colors, but for white labeling purposes, I retrieve the theme primary and secondary colors from an API. Is there a way to update these colors at runtime after receiving the values from the API? I am using the MUI ...

Execute Django code post webpage loading

Looking for a way to have the python code on the web page update every second if the database has changed, but currently it only runs on page load due to django functionality. function refresh(){ //Clear info boxes {% for TrackedObject in ...

Install legacy React together with semantic-ui and Gulp using npm

I'm currently facing an issue while trying to set up a React legacy project. The problem seems to be coming from the semantic-ui 2.2.13 library that the project is using. When I attempt npm install --legacy-peer-deps, I encounter the following error ...

What mechanisms do chat apps use to detect when a user sends a message and trigger a re-render of the chat

Do I need to implement websockets for my React chat app using MySQL? I'm facing an issue where the app doesn't re-render when I open it in a new tab and type a message. Should I consider using websockets for real-time updates, or are there any ot ...

"Discrepancy in column display across various resolutions in Bootstrap 5.3 causing issues

My goal is to have 4 divs that change in width at different resolutions, but for some reason it's not working. I am looking for: When the resolution is ≥992px, the divs should be in the same line (3 columns) When the resolution is ≥768px, the di ...

Issue with Paypal Express Checkout page appearance in Firefox browser

After completing the integration of PayPal Express Checkout on my client's website, I encountered an issue while testing its features and checking for browser compatibility. When going through the checkout process in Firefox, the PayPal Checkout Page ...

The problem I am encountering with particles.js

Having an issue with the particles.js library where the particles are displaying beneath the elements despite setting the Z-index. I have tried various solutions from CSS, Stack Overflow, Google, and YouTube but none have been effective. Here is my code s ...

What are the steps for importing a file into a React app that is built using Create React App as plain text?

Objectives I aim to showcase code snippets from the project itself for reference. I intend to keep the displayed code up-to-date with its implementation. I prefer not to remove myself from create-react-app This React project, built using create-react-ap ...

Error with jquery.mobile-1.4.5.min.css in Android webview following recent Marshmallow update has caused compatibility issue

Creating a web page using JQuery was successful and the page loaded correctly on an Android device (Nexus 5) through WebView. However, after updating the Nexus 5 to Android Marshmallow, the web page could no longer be viewed properly on the WebView. Inste ...

DaisyUI special design for managing inactive buttons

I have encountered an issue while creating a reddit Single Sign-On (SSO) button. The problem I'm facing is that the custom theme I designed for the Reddit button appears secondary-grey when it's disabled. Below is my theme configuration in the t ...

While React remounts every component during development, it is puzzling that the screen only shows the UI snapshot of a single component

Participating in this React challenge presents a curious scenario. Even though the UI of DOM is only displayed on the screen once, the Counter component is being re-mounted during development. This behavior causes the setInterval function to run twice af ...

Tips for designing an Ionic app with a Pinterest-inspired layout

Recently stepping into the world of Ionic development, I find myself facing a challenge in creating a Pinterest-inspired layout using Ionic. Specifically, I am struggling to achieve a two-wide list of items with varying heights. Can anyone offer guidance ...

Issue with React hook state persistence in recursive function

I implemented a recursion custom hook that utilizes a setTimeout function to provide 3 chances for an operation. Once the chances run out, the recursion should stop. However, I encountered an issue where the setTimeout function is not properly decrementin ...