Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
mui v5 styled Dialog not accepting styled width

I have mui v5 dialog that I am not able to set its width using style() component.

import {
  Dialog,
  DialogContent,
  DialogTitle,
  Paper,
  Typography,
} from "@mui/material";
import { Close } from "@mui/icons-material";
import { styled } from "@mui/material/styles";
import ActionButton from "./ActionButton";

import React from "react";

const StyledDialog = styled(Dialog)(({ theme }) => ({
  fullWidth: true, // it's not taking effect
  maxWidth: "lg",  // it's not taking effect
  padding: theme.spacing(2),
  position: "absolute",
  top: theme.spacing(5),
  "& MuiDialog-paper": {
    padding: theme.spacing(2),
    position: "absolute",
    top: theme.spacing(5),
  },
  "& .MuiTypography-h6": {
    paddingRight: "0px",
  },
}));

export default function Popup(props) {
  const { title, children, openPopup, setOpenPopup } = props;
  return (
    <StyledDialog open={openPopup} onClose={() => setOpenPopup(false)}>
      <DialogTitle>
        <div style={{ display: "flex" }}>
          <Typography variant="h6" component="div" style={{ flexGrow: 1 }}>
            {title}
          </Typography>
          <ActionButton
            color="secondary"
            onClick={() => setOpenPopup(false)}
          >
            <Close />
          </ActionButton>
        </div>
      </DialogTitle>
      <DialogContent dividers>{children}</DialogContent>
    </StyledDialog>

However, if I listed the props directly inside the it works.

<StyledDialog fullWidth="true" maxWidth="lg">

</StyledDialog>

What is the correct way of setting up the width and maxWidth.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try this on the styledDialog declaration:

const StyledDialog = styled((props) => (
    <Dialog
        fullWidth={true}
        maxWidth={'lg'}
        {...props}
    />
))(({ theme }) => ({
    // Your code to style the dialog goes here
}));

The problem on your code is that you arent passing the properties fullWidth and maxWidth to the component.

about 4 years ago · Juan Pablo Isaza Report

0

You are trying to use maxWidth: lg and fullWidth: true like css, but they are only for the Dialog API.

So you could use maxWidth in the component as an API like

<Dialog maxWidth="lg" fullWidth ... >

or you can add it as css style using theme.

const StyledDialog = styled(Dialog)(({ theme }) => ({
  maxWidth: theme.breakpoints.values.lg, // there's no styling such fullWidth
  ...
}));

You could have a look at the default theme.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!