11

I'm looking to change the color of the backdrop of the Dialog component of Material UI using styled-components.

I found this thread on how to do exactly that but I'm not sure how to apply this to styled-components.

I currently haved a StyledDialog as such:

const StyledDialog = styled(Dialog).attrs({

  classes: { paper: 'container' },
  keepMounted: true,
  'aria-labelledby': 'alert-dialog-slide-title',
  'aria-describedby': 'alert-dialog-slide-description'
})`
  .container {
    border-radius: 0;
  }
`;
Carrein
  • 3,231
  • 7
  • 36
  • 77

3 Answers3

19

<Dialog BackdropProps={{style: {backgroundColor: 'white'}}}/>

https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/Dialog/Dialog.js

07mm8
  • 2,702
  • 2
  • 8
  • 20
8

You can reference the backdrop via its global class ("MuiBackdrop-root") in the following manner:

const StyledDialog = styled(Dialog)`
  .MuiBackdrop-root {
    background-color: lightgreen;
  }
`;

Edit styled-components Dialog backdrop

Relevant Styled Components documentation: https://www.styled-components.com/docs/basics#pseudoelements-pseudoselectors-and-nesting

Ryan Cogswell
  • 75,046
  • 9
  • 218
  • 198
2

BackdropProps are now deprecated, you can use componentsProps.backdrop instead

<Dialog componentsProps={{ backdrop: { style: { backgroundColor: "transparent" } } }} />
htmn
  • 1,505
  • 2
  • 15
  • 26