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.

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://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

Facing compatibility problems with JavaScript and Cascading Style Sheets in Google Chrome?

Welcome to the site . Let's address a couple of issues with JavaScript and CSS: Firstly, the JS code seems to be malfunctioning only in Chrome, throwing an error that reads: 'Uncaught TypeError: Object [object Object] has no method 'on prij ...

Button-Enhanced File Upload using Material-UI

I'm having some issues with creating a file upload feature triggered by a button click. <label> <input style={{ display: 'none' }} type="file" /> <Button variant="contained" color="defau ...

Tips for validating material-ui-phone-number using Yup

I am currently facing an issue with validating a material-ui-phone-number field using YUP. The problem arises when I add the inputRef prop to the component, as YUP throws an error stating TypeError: e is undefined. It appears that the material-ui-phone-num ...

Is it possible to invoke a React JS class using an onClick event handler within a different Component?

I am struggling with some code that resembles the following: import React from "react"; import Overlay from "./Overlay"; export default class TagListItem extends React.Component { render() { return( <div cla ...

The Gulp task is failing to generate the CSS file

Greetings! I have a task set up in my gulpfile.js as shown below: const gulp = require('gulp'); const sass = require('gulp-sass'); gulp.task('sass', function(){ return gulp.src('sass/*.scss') .pipe(sass()) ...

What is the correct way to implement fetch in a React/Redux/TS application?

Currently, I am developing an application using React, Redux, and TypeScript. I have encountered an issue with Promises and TypeScript. Can you assist me in type-defining functions/Promises? An API call returns a list of post IDs like [1, 2, ..., 1000]. I ...

Can Griddle be used to arrange a table column according to the chronological order of months?

I received a timestamp in this format: Fri Jun 30 2017 09:57:18 GMT+0100 (BST) and I modified it to appear like this : Jun 30, Fri 2017 09:57 However, when sorted in the Griddle, it is sorted alphabetically (apr,aug,dec,feb,jan,jul,jun,mar,may,nov,oct, ...

What is the best method to display a Component in React and reset its lifecycle whenever it is shown?

As a beginner in node.js and react, I decided to embark on the journey of creating a chat app using socket.io. I followed some tutorials on setting up rooms, joining/leaving them, and messaging within the rooms. To pass one socket instance, I utilized Reac ...

Difficulty with Material UI radio button group remaining unchanged after selection

I am encountering an issue with my React component that utilizes Material-UI for a button group implementation. Upon the initial page render, the default value of 5 is selected and the radio box displays as checked. However, when I attempt to select a di ...

Leverage the power of combining Bootstrap and Material-UI in a single project for enhanced

What are the potential effects on my website or web application if I combine both Bootstrap and Material-UI in a project? Thank you. ...

Encountering a React-timestamp problem with the error message "Unable to locate 'react' in the node modules directory."

My journey of creating an App using React was going smoothly until I decided to install react-timestamp via npm for converting unix time (https://www.npmjs.com/package/react-timestamp). However, now I'm encountering a compilation error that states: ...

use css to align multiple div elements

I am struggling to line up more than five div tags on the same line. Here is my CSS: <style> #yes { float: left; width: 18%; margin:1px; } </style> Example of HTML code: echo '<div id="yes">'.'<b>'.'Job T ...

Updating the state after receiving API results asynchronously following a function call

I am attempting to update the state asynchronously when my fetchWeather function is executed from my WeatherProvider component, which calls an axios request to a weather API. The result of this request should be mapped to a forecast variable within the fet ...

The use of JSON.stringify on ArrayData is not updating as expected within the useEffect hook in Next.js

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSearch, faAmbulance, faAnchor, faPlus, faFloppyDisk, } from '@fortawesome/free-solid-svg-icons'; import { Input, Table, Button, Modal, Moda ...

Transferring a PDF document to Next.js

I am facing an issue while trying to upload a PDF file (CV) on next js. Everything seems fine according to my expectations, but when I console.log(req.data) it displays [object:object] Please note: When I console.log the data in frontend, it works fi ...

React Material UI Drawer with dynamic href links

Hello! I'm looking to create a dynamic href based on team member names using React Material UI Drawer. Here's a snippet of the code: const sideList = ( <List> {['MemberA', 'MemberB', 'MemberC'].map((text, inde ...

Position the div within a flex container to the right side

How can I position the album cover div to the right within the card? I attempted using the align-self: end property, but it did not work. Can someone please assist? .card { border: 1px red solid; width: 450px; height: 150px; border-radius: 5px; ...

Encountering an Error while Setting Up NextJS on Vercel

Hello, I'm a newcomer to the world of web development. My current goal is to deploy my first NextJS app on Vercel, but I keep encountering an error. Error: SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (<anonymous>) ...

Steps to retain localStorage data while redirecting to another external webpage

Encountering an issue with saving localStorage data across redirects. See the code snippet below: // Invoke newSitelogin(). Save response(credentials) in localStorage. Redirect to new URL. newSitelogin({ uuid, password }) .then(() => { window.ope ...

The message sent by the postman returns an empty JSON response

When attempting to send a request to test the MongoDB connection, I am getting an empty object as a response. I have checked and suspect that my test.http file is being treated as text instead of JSON... despite using app.use(express.json()) for parsing. T ...