Looking for assistance with resolving spacing problems within MaterialUI Dialog Content?

Trying to create a summary page using a MUI Dialog.

This is the dialog setup I have:

However, I am struggling to align the two sides at the top without any space above "Title 2". It appears that the Typographys are being added from the bottom up, starting with the last one in each div. Here is the JSX code I'm using:

<Dialog className={classes.dialog} open={open} fullWidth maxWidth="md">
  <DialogTitle disableTypography className={classes.dialogTitle}>
    <Typography align="center" variant="h5">
      Summary
    </Typography>
  </DialogTitle>
  <DialogContent dividers>
    <div
      className={
        booleanVar === true ? classes.test1 : classes.test3
      }
    >
      <Typography
        align="center"
        variant="h6"
      >{`Title 1`}</Typography>
      <Typography align="left" variant="h6"& 
gt;{`Three`}</Typography>
      <Typography align="left" variant="h6">{`Line`}</Typography>
      <Typography align="left" variant="h6">{`Email:`}</Typography>
    </div>
    {booleanVar === true ? (
      <div className={classes.test2}>
        <Typography
          align="center"
          variant="h6"
        >{`Title 2`}</Typography>
        <Typography variant="h6">{`Two Line`}</Typography>
        <Typography variant= 
"h6">{`Example`}</Typography>
      </div>
    ) : null}
  </DialogContent>
</Dialog>

In addition to this, here is the CSS:

const useStyles = makeStyles((theme) => ({
  dialog: {
    borderRadius: "10px",
    height: "auto",
    justifyContent: "center",
    margin: "auto",
    width: "auto"
  },
  dialogTitle: {
    padding: "6px 24px 16px 24px",
    textAlign: "center"
  },
  test1: {
    width: "49%",
    margin: "auto",
    textAlign: "left",
    display: "inline-block",
    paddingRight: "5px"
  },
  test2: {
    width: "49%",
    margin:&q-ot;auto",
    textAlign: "center",
    display: "inline-block",
    borderLeft: "0.1em solid #e0e0e0",
    paddingLeft: "5px"
  },
  test3: {
    width: "100%",
    margin: "auto",
    textAlign: "center",
    display: "inline-block"
  }
}));

If you have a solution using CSS, it would be preferred, but I am open to any working solution!

Answer №1

The root cause of the issue remains unknown, but I successfully implemented the desired layout.

To achieve this, I made some adjustments to the myDialog.js file by removing the unnecessary margin: "auto" property from all three test classes - test1, test2, and test3.

In addition, I introduced a new Box component from Material UI:

import {
  Box, // added here
  Button,
  Typography,
  Dialog,
  DialogActions,
  DialogTitle,
  DialogContent,
  IconButton
} from "@material-ui/core";

I then wrapped the dialog content within the <Box> component and applied the display="flex" property to enable flexbox layout for the enclosed div like so:

<Box display="flex">
   <div
     className={
       booleanVar !== undefined ? classes.test1 : classes.test3
     }
   >
     <Typography align="center" variant="h6">{`Title 1`}</Typography>
     <Typography align="left" variant="h6">{`Three`}</Typography>
     <Typography align="left" variant="h6">{`Line`}</Typography>
     <Typography align="left" variant="h6">{`Example`}</Typography>
   </div>
   {booleanVar !== undefined ? (
   <div className={classes.test2}>
     <Typography align="center" variant="h6">{`Title 2`}</Typography>
     <Typography align="left" variant="h6">{`Two Line`}</Typography>
     <Typography align="left" variant="h6">{`Example`}</Typography>
   </div>
   ) : null}
</Box>

You can view the updated code on CodeSandbox at this link: https://codesandbox.io/s/still-https-71skf

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

Currently, I am attempting to figure out the Xpath or CSS necessary to locate and interact with an Add

Struggling to pinpoint the Add button on our website that I'm currently automating using Python and Webdriver. The Xpath provided by Selenium IDE is as follows: adminAdd_button = driver.find_element_by_xpath("//button[@type='button'])[33]") ...

Vitest does not currently support the experimental syntax 'jsx' in use

Currently utilizing Vite with the vitest package Error: Details: ...

Arranging divs parallelly while incorporating components within

Striving to create a layout with 3 divs side by side in an HTML document, my initial attempt resulted in this: https://i.stack.imgur.com/CpdLX.png However, I encountered an issue where the div would shift down whenever text or other objects were added: ...

Struggling to successfully deploy a React App to Azure through a Github Actions workflow due to encountering a TypeScript error

I have been searching extensively on SO for the past few days, trying different methods but I just can't seem to make this work. This is not my usual area of expertise as I am a .Net developer and I inherited this project. To get where I am now, I fo ...

What is the best way to include a borderTop in a React Material UI Table component?

https://i.sstatic.net/RIViY.png Is there a way to add a top border to the table above? I attempted const styles = theme => { root : { borderTopWidth: 1, borderColor: 'red'} } ... class TableComponent ... { classes } = this.props; & ...

Which route should I take - creating a dedicated Express server or managing all API requests within my Next.js application?

When designing my website, I plan to utilize CRUD operations with MongoDB and Firebase storage+auth. What are the benefits of creating a distinct Express server rather than integrating everything within my Next.js app? Despite being able to accomplish it ...

What is the best way to create a CSS selector for a button with two classes within a .less file?

Here is my current CSS: button { background: @button-background; color: @text; &.focus { background-image: linear-gradient(#79d858, #569e3d); border-color: #4a993e; color: white; ...

Encountering a hiccup while trying to install dependencies, neither the --force nor --legacy-peer-deps flags have been

Embarking on a new project with React, I encountered an error while attempting to install the dependencies outlined in the tutorial video I am following. Unfortunately, I'm uncertain how to resolve this issue on my own. The list of dependencies and c ...

Here is a unique rewrite:"Adjusting the prop of a Material UI Button component depending on screen size breakpoints can be achieved by utilizing

While using the Material UI Button component, I encountered an issue with conditionally determining the variant of the button based on screen size. Specifically, I want the variant to be 'outlined' on medium and larger screens, and no variant at ...

Managing Multiple File Inputs in React Using useRef Array Results in an Undefined Value

In the process of developing a React application, I encountered an issue where multiple file input elements were dynamically rendered using the Swiper component and Dropzone. However, upon attempting to retrieve all the selected files from these inputs dur ...

When the CSS class of a DIV is set to X in jQuery, the script will hide all other DIVs with a

Just starting to explore jQuery and still fresh on JS knowledge, I have the desire to craft a jQuery script. To begin with, here is my HTML snippet: <div id="user-controls"> <div class="choice" id="choice-all" onclick="showAll();">All< ...

Mat dialog title is failing to fill the entire width of the container

My mat dialog doesn't seem to expand the width of the container as I expected. <div mat-dialog-title class="blue-gradient">Confirm</div> <div mat-dialog-content> {{information}} </div> <div mat-dialog-actions alig ...

Reduce the size of your CSS files using Gulp through the .pipe method

Is it feasible to incorporate a plugin like clean-css to minify CSS every time a page is refreshed or saved? How can I chain it through pipes to ensure that the minified file ends up in the dist folder? Thank you for any assistance! Presented below is the ...

What is the best way to customize the appearance of a non-current month cell within the date picker?

I'm currently in the process of developing a registration form for my JavaFX application. I am faced with an issue where I need to disable certain cells in the date picker when they do not belong to the displayed month. Let's take a look at my cu ...

Error in React JS: TypeError - Attempting to extend a class with an undefined value, which is not a

I am new to React and experimenting with a code example on https://jscomplete.com/repl. Currently, my code appears as follows: let data = [ { name:"Paul O’Shannessy", avatar_url:"https://avatars1.githubusercontent.com/u/8445?v=4", c ...

File bootstrap.min.css is currently experiencing compatibility issues

I am currently working on a website where I have two images that are displaying vertically. However, I would like these images to be displayed horizontally with animation. I attempted to use Bootstrap to achieve this horizontal layout, but when I include ...

Background color for the DIV is not displaying properly when it is set to the

While trying to set the background color of a div to light blue #2390bb, I encountered an issue. Even though I have already set the body background color to Light Grey#D6D6D6, the light blue color doesn't display in the div. Can anyone help me figure ...

Adjacent components

I have a query regarding the utilization of Angular. I aim to align the sentences side by side. These are two distinct components that I developed. I wish for recipe-list and recipes-details to function properly, with both statements displayed alongside ...

What steps should I take to resolve an unhandled promise error in a React TypeScript application while making an axios POST request?

I am currently working on a .tsx file to implement adding an enterprise feature. Although I can input data, clicking the submit button does not trigger any action. My application includes a page that has a button for adding a new enterprise. Upon clickin ...

Show off HTML groups with personalized attributes using react-map-gl (Mapbox)

I have been experimenting with adapting the Display HTML clusters with custom properties example for react-map-gl. I managed to get basic clusters without custom styling working by modifying the example from Create and style clusters: <ReactMapGL ref={ ...