Skip to content

[Dialog] does not respect breakpoint units #21476

@JasonTolliver

Description

@JasonTolliver
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

The Dialog component's maxWidth property has very unexpected results when you have customize breakpoints in the theme to us em as a unit. For example, say you use the following theme:

const theme = createMuiTheme({
  breakpoints: {
    unit: "em",
    values: {
      xs: 0,
      sm: 30,
      md: 48,
      lg: 78,
      xl: 120
    }
  }
});

and you compose a <Dialog maxWidth={'sm'}>Content</Dialog>, the dialog will end up being 30px wide vs 30em wide.

Screen Shot 2020-06-16 at 3 55 24 PM

It looks like the offending bits of code live here:
https://github.com/mui-org/material-ui/blob/ff6bde2063ce9106ca30a037b7dc46aa4a48083a/packages/material-ui/src/Dialog/Dialog.js#L84-L118

Whereas the maxWidth should probably be calculated as:

- maxWidth: theme.breakpoints.values.sm,
+ maxWidth: `${theme.breakpoints.values.sm}${theme.breakpoints.unit}`,

I am unsure how '&$paperScrollBody' works, otherwise I might have just submitted this as a PR.

Expected Behavior 🤔

With the given theme, I expect <Dialog maxWidth={'sm'}>Content</Dialog> to be 30em wide

Steps to Reproduce 🕹

https://codesandbox.io/s/agitated-edison-l10fk

Steps:

  1. Set up breakpoints with a unit of em
  2. Use a Dialog component with a maxWidth
  3. The dialog will use px instead of em with the breakpoint value.

Context 🔦

I am using MUI components alongside another system that handles the layout. That system uses em and I need it to match.

Your Environment 🌎

Tech Version
Material-UI latest
React latest
Browser all

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready to takeHelp wanted. Guidance available. There is a high chance the change will be acceptedscope: dialogChanges related to the dialog.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions