Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target backdrop color property of Material UI Dialog using styled components?

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;
  }
`;
like image 772
Carrein Avatar asked Sep 10 '19 20:09

Carrein


People also ask

How do I change the background color of container in material UI?

To set the background color of the Material UI drawer, we call the makeStyles function to create the styles. Then we can apply the styles with the useStyles hook returned by makeStyles . We call makeStyles with an object that has the properties set to objects with the styles.

How do you style material UI components with styled-components?

Use the styled() method to style your Material UI components. The styled() method from styled-components takes as input a React component and outputs another React component with a different style. It is useful as it enables you to style your component using the exact same syntax as in your typical CSS stylesheet.

What is backdrop in material UI?

The backdrop component is used to provide emphasis on a particular element or parts of it. The backdrop signals to the user of a state change within the application and can be used for creating loaders, dialogs, and more. In its simplest form, the backdrop component will add a dimmed layer over your application.


Video Answer


2 Answers

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

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

like image 185
07mm8 Avatar answered Oct 20 '22 06:10

07mm8


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

like image 35
Ryan Cogswell Avatar answered Oct 20 '22 06:10

Ryan Cogswell