"Short-term" variation not appearing within the Material-ui Drawer component

I am attempting to create a responsive drawer component using material-ui, where it is toggleable on smaller screens and remains open on desktop.

Following the mui documentation, I added the temporary variant to the drawer, but it does not display in desktop mode at all.

Here's the code for my drawer component:

import React from "react";
import ReactDOM from "react-dom";
import { useHistory } from "react-router-dom";

import { makeStyles, Typography, Drawer, Toolbar, Divider, List, ListItem, ListItemText, ListItemIcon, Container, Box } from "@material-ui/core";

import HomeOutlinedIcon from '@material-ui/icons/HomeOutlined';
import AlternateEmailOutlinedIcon from '@material-ui/icons/AlternateEmailOutlined';
import NotificationsNoneOutlinedIcon from '@material-ui/icons/NotificationsNoneOutlined';
import DashboardOutlinedIcon from '@material-ui/icons/DashboardOutlined';
import ArchiveOutlinedIcon from '@material-ui/icons/ArchiveOutlined';


const drawerWidth = 280

const useStyles = makeStyles((theme) => ({
    drawer : {
      width: drawerWidth,
    },
    drawerPaper : {
      width: drawerWidth,
    },
    list : {
      marginLeft: '24px',
      marginRight: '24px'
    },
    listItem : {
      padding: '8px',
      borderRadius: '5px',
    },
    text : {
      color: theme.palette.primary.light,
      fontWeight: '500',
      lineHeight: '2000'
    },
    title : {
      color: theme.palette.primary.light,
      textAlign: 'center',
      display: 'block',
      fontWeight: '500',
      fontSize: '20px',
      marginTop: '10px',
      marginBottom: '10px'
    }
}));

export default function LeftBar(){

  const classes = useStyles();
  const [mobileOpen, setMobileOpen] = React.useState(false);

  const handleDrawerToggle = () => {
    setMobileOpen(!mobileOpen);
  };

  const list = [
    {
      text : 'Home',
      icon : <HomeOutlinedIcon />,
      path : '/'
    },
    {
      text : 'Personal',
      icon : <AlternateEmailOutlinedIcon />,
      path : '/'
    },
    {
      text : 'Notifications',
      icon : <NotificationsNoneOutlinedIcon />,
      path : '/'
    },
    {
      text : 'Dashboard',
      icon : <DashboardOutlinedIcon />,
      path : '/'
    },
    {
      text : 'Archives',
      icon : <ArchiveOutlinedIcon />,
      path : '/'
    }
  ];

   return (
     <Box>
      <Drawer 
      className={classes.drawer} 
      anchor="left" classes={{
        paper: classes.drawerPaper
      }} 
      open={mobileOpen}
      onClose={handleDrawerToggle}
      ModalProps={{
        keepMounted: true, // Better open performance on mobile.
      }}
      sx={{
        display: { xs: 'block', sm: 'none' },
        flexShrink: 0,
        '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
      }} 
    >

        <Toolbar />
        <Container>
        <Typography variant="h5" component="h2" className={classes.title} gutterBottom>
        My Account
        </Typography>
        </Container>
        <Divider />

        <List className={classes.list}>
        { list.map((item) => (
        <ListItem key={item.text} className={classes.listItem} button>
          <ListItemIcon className={classes.icon}>
          {item.icon}
          </ListItemIcon>
          <ListItemText sx={{color: 'primary'}} primary={item.text} className={classes.text}/>
    
        </ListItem>
        ))}
        </List>

      </Drawer>
      </Box>
   );

};

Answer №1

Currently, the drawer you have set up is only visible for xs screens with

display: { xs: 'block', sm: 'none' }
. To make it visible for sm and larger screens, you'll need to create a separate drawer. The MUI documentation provides an example of how to add another drawer:

<Drawer
      variant="permanent"
      sx={{
        display: { xs: 'none', sm: 'block' },
        '& .MuiDrawer-paper': { boxSizing: 'border-box', width: drawerWidth },
      }}
      open
 >
      {content goes here}
 </Drawer>

You might also consider moving the Toolbar component outside of the Drawer component for better organization.

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

Ways to retrieve dictionary keys as an array in Angular

Here is an example of an Angular dictionary: { ARRAY1: [{...}, {...}, {...}] ARRAY2: [{...}, {...}, {...}] ARRAY3: [{...}, {...}] ARRAY4: [{...}] } I want to show all the keys of arrays from this dictionary on an HTML page. I attempted to do ...

How can you achieve text wrapping and responsiveness while making an image float to the right with Bootstrap?

I'm currently utilizing Bootstrap to create a web page showcasing an article with multiple images. The images that float left are working as expected. However, I am facing an issue when trying to make the image float to the right. I have attempted th ...

Convert the easeInExpo function from jQuery easing to vanilla JavaScript and CSS

Currently, I am in the process of converting a piece of code from jQuery to plain JavaScript and CSS. The specific code snippet I am focusing on involves creating easing functions without relying on jQuery. const customEasing = { easeInExpo: function ( ...

Ways to align a Unordered List (ul) in the middle

I have a list of items with some elements floated to the left. Currently, it looks like this: | A | B | C | D | E < empty space> | I would like it to appear as: | A | B | C | D | E | Centered on the page with centered contents as well. HTML < ...

modification of class into hooks, receiving error message 'then' property is not found in type '(dispatch: any) => Promise<void>'

As a newcomer to React hooks, I have been converting code from class components to hooks. However, I am encountering an error message when trying to use 'then' in hooks that says 'Property 'then' does not exist on type '(dispa ...

Cut off a string from the start

I'm using the text-overflow: ellipsis property in a div to shorten lengthy text values. Since there is no white space in the URL, I want to prevent the overflow from increasing the width of the div. What I want to achieve is to display the following: ...

Ways to obscure a React component or JSX file

Looking for a way to share a GitHub repository without exposing my React components. I need to obfuscate JSX files that include functional components, styled-components, and axios. However, I still want "npm start" or "npm run dev" to work in React/Next. ...

How can I position a form next to a title when utilizing the Bootstrap Panel feature?

I have experimented with multiple solutions found on various sources, but unfortunately none have been successful. I came close to achieving the desired result, but encountered an issue with the panel's default background color not displaying properly ...

Using jQuery to calculate mathematical operations in a form

I've been working on creating a form that calculates the total cost based on selected options. So far, I've managed to get it working for three options, but I'm stuck on how to calculate the subtotal by adding the variables "vpageprice" and ...

The gltf model fails to load on Chrome for Android when using Threejs

I encountered an issue while attempting to showcase a basic GLTF 3d model on my website. Surprisingly, it functions smoothly on desktop Mac and Windows, as well as on iOS in Safari and Firefox. However, it fails to load on Android's Chrome browser. St ...

Having an issue with TypeScript and React where the onChange event on the <select> element is only setting the previous value instead of the current value when using the useState hook

I'm currently developing a scheduling web tool. One of the key features I'm working on involves calculating the total hours between two selected times, startTime and endTime. These times are chosen via a form and stored using the useState hook: ...

Stop the page from scrolling when a modal is displayed in React

I've encountered an issue with my custom modal component where the background stops scrolling when the modal is open. Initially, I attempted to solve this by using the following code: componentDidMount() { document.body.style.overflow = 'hi ...

Step-by-step guide on incorporating a Material-UI form with Steppers into a React Admin Create Component

My React-Admin app has a lengthy form that I want to convert into a stepper for better user experience. I found an example of Steppers in Material-UI here I need help with the following: Adding components like to the stepper's functionality g ...

What is the process for extracting HTML code from a website and converting it into a string for use in VB?

Storing the page source in the variable HTML is known to me. Dim Client As New WebClient URL = Console.Readline HTML = Client.DownloadString(New Uri(URL)) However, it has been observed that not all elements from a website are saved using this method. For ...

Experiencing challenges accessing information from the useEffect hook in React

I'm facing some issues with my useEffect hook and I can't seem to figure out why it's not working. I've been trying to make a call to an endpoint, but it seems like I'm not getting any response back. Any help would be greatly appr ...

Attempting to position a centrally aligned div block containing images towards the left side

I'm having an issue with aligning multiple images on my webpage. I want them to be left justified when the page is resized, while still keeping the div block centered. Currently, they are all being centered: See below: Here is the HTML and CSS code ...

Stop text from being selected across all browsers in Firefox

My current CSS includes: *{ -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } If you visit http://jsfiddle.net/KyF5x/ and click be ...

Configuration object for Webpack is not valid

I encountered an error while using webpack that says: Invalid configuration object. Webpack has been initialized with a configuration object that does not conform to the API schema. - configuration.resolve has an unknown property 'extension&ap ...

Tips for inserting a rotated image using CSS

I've created the following code snippet. However, there is a new requirement stating that the image needs to be rotated by 180 degrees. How can I make this happen? #cell { background-image: url("../images/logo.PNG"); background-attachment: fixed; b ...

Verify the authenticity of a date using the locale parameter in the Intl API

Seeking advice for validating inputfield based on locale argument. How to format dates differently depending on the specified locale? For example, if locale is 'en-uk' then date should be in mm/dd/yyyy format, but if locale is 'de-ch' i ...