How do I eliminate excess space following the resizing of the Material UI Drawer component?

I adjusted the size of my MUI drawer to a specific width and now I am facing an issue where there is extra space left after resizing. This results in a margin-like space between the drawer and the Lorem Ipsum text content. My goal is to eliminate this remaining space and have the text close to the drawer even after resizing it. I'm unsure about where to make changes in the box or containers to achieve this.

Resized MUI drawer:

https://i.sstatic.net/63VWs.png

The highlighted lines show the extra space that needs to be removed (highlighted lines by Pesticide chrome extension): https://i.sstatic.net/Ig2aO.png

Sample source code for the drawer:

import * as React from "react";
import Box from "@mui/material/Box";
import Drawer from "@mui/material/Drawer";
import CssBaseline from "@mui/material/CssBaseline";
import AppBar from "@mui/material/AppBar";
import Toolbar from "@mui/material/Toolbar";
import List from "@mui/material/List";
import Typography from "@mui/material/Typography";
import Divider from "@mui/material/Divider";
import ListItem from "@mui/material/ListItem";
import ListItemButton from "@mui/material/ListItemButton";
import ListItemIcon from "@mui/material/ListItemIcon";
import ListItemText from "@mui/material/ListItemText";
import InboxIcon from "@mui/icons-material/MoveToInbox";
import MailIcon from "@mui/icons-material/Mail";

// Rest of the sample code remains unchanged

<p>CSS code to resize the drawer:</p>
<pre><code>.MuiDrawer-paper {
 width: 10% !important;
 }

Your insights on resolving this issue with the MUI drawer would be greatly appreciated. Thank you!

Answer №1

Kindly delete the CSS:

.MuiDrawer-paper {
  width: 10% !important;
}

Also, modify this specific line:

const drawerWidth = 240;

You can choose to use either "200px" or "10%", depending on your requirements.

Answer №2

Upon closer inspection of the elements, you will notice

<div class="MuiDrawer-root MuiDrawer-docked css-1f2xuhi-MuiDrawer-docked">
  <div class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiDrawer-paper MuiDrawer-paperAnchorLeft MuiDrawer-paperAnchorDockedLeft css-12i7wg6-MuiPaper-root-MuiDrawer-paper">

The .MuiDrawer-paper class does not impact the width of its parent element, which remains at 240px

.css-1f2xuhi-MuiDrawer-docked {
  -webkit-flex: 0 0 auto;
  -ms-flex: 0 0 auto;
  flex: 0 0 auto;
  width: 240px;
  -webkit-flex-shrink: 0;
  -ms-flex-negative: 0;
  flex-shrink: 0;
}

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

Enhancing Material UI DataGrid row using Dialog Popup for updating with Edit-Form in Material UI version 5

I am seeking a solution for updating a row in a Material UI DataGrid table using a Dialog Popup with an Edit-Form that opens when the Edit Button of a row is clicked, instead of inline Row-Editing. How can this be achieved without any examples or document ...

Unlock the potential of displaying similar object values side by side in JavaScript, React, and ES6 - here's how!

Currently, I am dealing with an object called segregatedData which is being passed as props. Among its several properties, we are interested in segregatedData.type1. This particular property is essentially an array of strings similar to this: ['water& ...

Encountering difficulties when attempting to run initial React Native app

Struggling with my journey of learning react-native, I encountered a roadblock while trying to run the application. Here is the error log. I'm hopeful for some assistance from anyone who can lend a hand. The development server returned response erro ...

Issue: Connection Problem in React, Express, Axios

I've encountered an issue while attempting to host a website on an AWS EC2 instance using React, Express, and Axios. The specific problem I'm facing is the inability to make axios calls to the Express back-end that is running on the same instanc ...

Looking for a way to extract a dynamic URL from a website's div element?

Is there a way for my app to load dynamically by extracting and reading the changing URL from a webpage? //webpage <div style="display:none" id="urladdress"> //dynamic url **https://freeuk30.listen2myradio.co ...

Customized properties on the file object

I am looking for a way to store files on a server with custom File properties. I have added some properties on the client side like so: let file = new File([blob], 'flower.jpg') file.custom = "another properties" This outputs the following: c ...

Executing commands in the package.json file

Currently navigating a sizable codebase, my aim is to execute scripts from the package.json file exemplified below: https://i.stack.imgur.com/a1Rvu.png Whenever the command "npm start" is initiated, it defaults to the dev script resulting in an ...

The best practices for utilizing getStaticProps with Firebase

I am completely new to Next.js and am struggling to make the getStaticProps function work properly. import firebase from '../firebase' export default function Home({ posts }) { return ( <div> <h1>All Posts</h1> ...

What are the steps to create a button with similar design using css3?

How can I create a button with the same lower part as shown in this picture? I've already achieved 50% of it with border-radius, but need help expanding the lower part to match. Any suggestions? https://i.sstatic.net/3ZJFS.jpg .list{ height: 280px; ...

Saving the previous component's DOM in a React application

Understanding the Root.js File const Root = () => ( <HashRouter> <div> <Route exact path="/" component={Main}/> <Route path="/main/:page" component={Main}/> <Route path="/detail ...

Guide to repairing a CSS ball animation

I am attempting to create a simulation where a ball moves in the following pattern: bottom right -> top center -> bottom (/) left. However, my animation seems to be moving from top right -> bottom center -> top left (/). #stage { height:300 ...

Acquiring the applicable CSS for a JavaFX 8 widget

While working on JavaFX styling with CSS, I encountered a challenge in understanding which CSS properties are directly affecting the appearance of a GUI widget. It reminded me of using Firefox web developer tools to inspect elements and view the specific s ...

What is the best way to transmit data from a react form to a backend API and receive a response in return?

I'm in the process of developing a login and sign-up system for my website, but I've hit a roadblock. I've implemented a state variable that toggles the page layout between displaying the login form when true and the sign-up form when false ...

Can React Socket.IO-Client be used with NodeJS (express) WebSockets?

I'm currently facing an issue with the emits from my React client app not reaching a localhost socket server. I've customized PuppyJS to accept client events through a socket, using a modified version available at https://github.com/BlackConure/p ...

Encountering a problem when trying to map a List with a button in ReactJS

As I map results from a GET request, everything displays correctly - each User's picture, name, and the correct label on the button. However, the issue arises when I try to access specific user information by clicking on the button; instead of retriev ...

Struggling with pagination problems in Bootstrap 4 and looking to integrate QR code functionality into your blade template?

I am currently facing an issue with generating a batch of QR codes using the SimpleQR code generator in Laravel blade template on the fly for printing. The problem arises when a page break occurs, as it breaks the QR code. I attempted to use the break-insi ...

Svelte's feature prevents users from inputting on Mapbox

My goal is to prevent user input when the variable cssDisableUserInput is set to true. Here's what I have within my main tags: <div id=userinput disabled={cssDisableUserInput}> <div id="map"> </div> Within my CSS, I&a ...

Steps to create a clickable button wrapper label in React

Contained within the components below: <CheckboxGroupLabel htmlFor={option.label}> <FormCheckbox onClick={() => onChange} key={option.label} defaultChecked={defaultChecked} {...rest} /> {option.value} ...

Revamping array elements in React

Once I added an element to the array, I needed to update this array by doubling all elements except for the one that was just added. Despite trying setArray([]) before retrieving the array from the database, it didn't seem to work... const [array, se ...

How come the inclusion of a DOCTYPE tag impacts the styling of my CSS?

I am puzzled why the code below renders correctly without any issues until I add a doctype declaration: <body style="margin:0; padding:0; background-color:#eeeeee"></body> <div id="HeaderContainer" style="background-color:#eeeeee; color:Bl ...