Creating a Mui v5 grid item that maximizes its height within a dialog box

I need help setting the height of a Grid Item to occupy all available space in a MUI dialog.

In the image below, I am trying to make the Left Side Panel, Main section, and Right Panel extend to fill the orange-colored dialog space.

https://i.sstatic.net/GPFjtYCQ.jpg

Here is the code on Codesandbox that I have been working on.

https://codesandbox.io/p/sandbox/dialog-with-grid-nx5kkc?file=%2Fdemo.js%3A71%2C78

UPDATE: I made changes to the layout as shown below, but setting an xs value for the 2nd or 3rd part doesn't seem to work properly.

https://i.sstatic.net/V05sC7Dt.png

https://codesandbox.io/p/sandbox/dialog-with-grid-new-xhrm69?file=%2Fdemo.js%3A75%2C36

import * as React from "react";
import Button from "@mui/material/Button";
import DialogTitle from "@mui/material/DialogTitle";
import DialogContent from "@mui/material/DialogContent";
import DialogActions from "@mui/material/DialogActions";
import Dialog from "@mui/material/Dialog";
import Grid from "@mui/material/Unstable_Grid2";
import Stack from "@mui/material/Stack";
import Divider from "@mui/material/Divider";
import Container from "@mui/material/Container";
import Box from "@mui/material/Box";

function ConfirmationDialogRaw(props) {
  const { onClose, ...other } = props;

  return (
    <Dialog
      maxWidth="96%"
      PaperProps={{
        sx: {
          width: "96%",
          height: "100%",
        },
      }}
      onClose={onClose}
      {...other}
    >
      <DialogContent>
        <Container sx={{ height: "100%" }}>
          <Box sx={{ height: "100%" }}>
            <Grid container direction="row" spacing={2} sx={{ height: "100%" }}>
              {/* ------------------------ */}

              <Grid item xs={10}>
                <Grid
                  container
                  direction="column"
                  sx={{ p: 0, height: "100%" }}
                  xs
                >
                  {/* ----- */}
                  <Grid item sx={{ backgroundColor: "yellow" }}>
                    <Stack
                      sx={{
                        height: "80px",
                        border: "1px solid black",
                        fontSize: 30,
                        textAlign: "center",
                      }}
                    >
                      1
                    </Stack>
                  </Grid>
                  {/* ----- */}
                  <Grid xs item sx={{ backgroundColor: "red", height: "100%" }}>
                    <Grid
                      container
                      direction="row"
                      spacing={0}
                      sx={{ height: "100%" }}
                      xs
                    >
                      <Grid item xs>
                        <Stack
                          sx={{
                            height: "100%",
                            border: "1px solid black",
                            fontSize: 30,
                            textAlign: "center",
                          }}
                        >
                          2
                        </Stack>
                      </Grid>
                      <Grid item xs>
                        <Stack
                          sx={{
                            height: "100%",
                            border: "1px solid black",
                            fontSize: 30,
                            textAlign: "center",
                          }}
                        >
                          3
                        </Stack>
                      </Grid>
                    </Grid>
                  </Grid>
                </Grid>
              </Grid>
              {/* --------------------- */}

              <Grid item xs={2}>
                <Stack
                  sx={{
                    height: "100%",
                    minHeight: 150,
                    border: "1px solid black",
                    fontSize: 30,
                    textAlign: "center",
                  }}
                >
                  4
                </Stack>
              </Grid>
            </Grid>
          </Box>
        </Container>
      </DialogContent>
      <DialogActions>
        <Button autoFocus onClick={onClose}>
          Cancel
        </Button>
        <Button onClick={onClose}>Ok</Button>
      </DialogActions>
    </Dialog>
  );
}

export default function Demo() {
  const [open, setOpen] = React.useState(false);
  return (
    <>
      <Button variant="contained" onClick={() => setOpen(true)}>
        Open dialog
      </Button>
      <ConfirmationDialogRaw
        id="ringtone-menu"
        keepMounted
        open={open}
        onClose={() => setOpen(false)}
      />
    </>
  );
}

Answer №1

To style your Container, you can implement the following code:

<Container sx={{ height: "100%", backgroundColor: "#f3a432", px: 0 }}>
. By default, the Mui Container comes with padding already applied.

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

Discover the process of incorporating secondary links into your dabeng organizational chart!

I need to incorporate dotted lines on this chart, such as connecting leaf level nodes with middle level nodes. import OrgChart from '../js/orgchart.min.js'; document.addEventListener('DOMContentLoaded', function () { Mock.mock(&apo ...

What is the best way to center a div vertically on the page?

I've utilized Bootstrap 3 to create this row: <div class="cart"> <div class="row border"> <div class="col-md-8 desc pad itemsheight"> <div class="col-md-12"> <!-- react-text: 141 -->Docos <!-- /react ...

Issue with string format in CSS arises while incorporating dynamic styles via react-jss

In my component's state, I have CSS styles saved like this: state = { value: 1, indicatorStyles: { indicator: { backgroundColor: "rgb(224, 174, 97)", } }, }; When attempting to use the injectSheet function from react- ...

Blank page issue with Electron and React-BoilerPlate

While my app works flawlessly in Dev mode, it fails to function properly in Production. My folder structure is organized as follows: (build,dist,node_modules,public,src). build dist node_modules public Main.js index.html src index.tsx Within my packa ...

How to disable the ripple effect of a parent button in Material UI when clicking on a nested child button?

Attempting to nest one button within another (IconButton inside ListItem with the button prop) is proving challenging. The issue lies in the fact that the ripple animation of the ListItem is triggered even when clicking on the IconButton. Ideally, I would ...

"Enhance your UI with Material design borders on hover effect

Looking for some assistance with setting a border on hover for a text field in material UI. I'm new to this and struggling with the code. Can anyone help me figure this out? Here's my code snippet: import React from 'react'; import Box ...

Tips for designing a customizable color scheme for your website

Are you looking to implement a changeable color scheme for your website? Getting started can be daunting, especially if you're unfamiliar with sass. Would appreciate it if anyone could share some helpful tutorials or links? For example: example ...

Alter the class following modifications to the list

https://i.stack.imgur.com/QZob0.pngIn my dual list, the data is displayed in a ul li format fetched from a JSON file. Users can move items between the two lists. However, I am facing an issue where I want to apply a property that only displays content with ...

The rating and comment section is failing to adapt to smaller screens, creating a terrible user experience

I am a beginner with Sass and CSS. I wanted to create a rating and comment section which looks fine on a laptop screen, but appears off on smaller screens. It seems like the layout might be incorrect or maybe I didn't follow grid layout guidelines pro ...

The error message indicates that the 'aboutData' property is not found within the 'never[]' data type

What is the correct method for printing array elements without encountering the error message "Property 'post_title' does not exist on type 'never[]'?" How can interfaces be used to define variables and utilize them in code for both ab ...

Running a Node.js child process upon clicking an HTML button

I need to create a basic webpage where clicking a button will open the command prompt. This is my goal. Below are the HTML and Node.js code snippets. test.html <html> <head> </head> <body> <p>guru</p> <form a ...

Enhance performance with React.memo and seamlessly navigate between routes

Seeking a way to prevent my component from re-rendering on specific paths, I am attempting to achieve this by utilizing React.memo and checking the current path with the withRouter HOC. However, I have encountered an issue where the compare function in Re ...

Column that adjusts to different screen sizes

In the realm of responsive web design, what methods are suggested to achieve the specified CSS display? My main requirement is to have a maximum of three columns. The content should be divided evenly among these three columns. I prefer using SCSS and wel ...

Stylish Radial Hover Effect for Images Using CSS

I am looking to create a unique effect where upon hovering over an image, color will be applied in a radial shape on a grayscaled image within a div that is pointed by the cursor Below you can see the desired outcome compared to what I currently have. The ...

Enhancing class names in production mode with Material UI, Webpack, and React to optimize and minimize code size

webpack - v4.5+ material ui - v4.9.7 react - v16.12.1 Ordinarily, all classes should follow the pattern of the last one in the first example. However, for some unknown reason, many classes remain unchanged in production mode. Any thoughts on this issue? ...

After updating from version 0.9 to 1, the getMuiTheme function from Material-UI seems to

An error was encountered: Module build failed due to the following reason - Error: ENOENT: no such file or directory, open '/Users/leongaban/projects/go/src/github.com/pizzahutdigital/mythor/node_modules/material-ui/styles/getMuiTheme.js' Curren ...

Position an image in the center and add a div below it

I am seeking guidance regarding two specific questions. My objective is to showcase an image in its true size while positioning it at the horizontal center of the screen (not the exact center), followed by a div containing text directly underneath the imag ...

Instructions on utilizing the CSSStyleSheet.insertRule() method for modifying a :root attribute

Is it possible to dynamically set the background color of the :root CSS property in an HTML file based on a hash present in the URL? The code provided does change the background color, but unfortunately, the hash value doesn't persist as users navigat ...

Fetch function call results in an undefined value - Using Express and React

Struggling with an issue while following the stripe tutorial directly from the official stripe documentation. I keep receiving an undefined value from my server on a post request. Can someone help me identify where I am going wrong? When the user clicks t ...

Creating a responsive navigation menu using Bootstrap 4 by merging data from various MySQL tables

I am struggling to create a bootstrap 4 nav-menu using the provided SQL query and code snippets. Below are the tables: TABLE menu -------------------------------------- | id | title | url | | 1 | Home | index.php | | 2 | M ...