Snackbar is using a <p> after upgrading to 3.2
See original GitHub issueI upgraded to 3.2 and set useNextVariants: true
and the Snackbar
component started using a <p>
element for its container, which throws a warning in the browser if you have a <div>
as a child.
- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
Snackbar
should use a <div>
as its container element.
Current Behavior
Snackbar
is using a <p>
as its container element.
Steps to Reproduce
Open the live example (https://codesandbox.io/s/82wp5l1jkl) and check the console logs. You’ll see
Warning: validateDOMNesting(...): <div> cannot appear as a descendant of <p>.
in div (created by App)
in div (created by SnackbarContent)
in p (created by Typography)
in Typography (created by WithStyles(Typography))
in WithStyles(Typography) (created by Paper)
in Paper (created by WithStyles(Paper))
in WithStyles(Paper) (created by SnackbarContent)
in SnackbarContent (created by WithStyles(SnackbarContent))
in WithStyles(SnackbarContent) (created by Snackbar)
in Transition (created by Slide)
in EventListener (created by Slide)
in Slide (created by WithTheme(Slide))
in WithTheme(Slide) (created by Snackbar)
in div (created by Snackbar)
in ClickAwayListener (created by Snackbar)
in Snackbar (created by WithStyles(Snackbar))
in WithStyles(Snackbar) (created by App)
in MuiThemeProvider (created by App)
in App
Here is the same example working with v3.1.2: https://codesandbox.io/s/32p389xr15
I’m guessing it has something to do with this line: https://github.com/mui-org/material-ui/blob/master/packages/material-ui/src/SnackbarContent/SnackbarContent.js#L55. I’m not passing in a variant for the Typography component, so I don’t think the headlineMapping
is getting applied.
I was able to work around this bug by doing:
<Snackbar
ContentProps={{
variant: `body1`,
}}
/>
Your Environment
Tech | Version |
---|---|
Material-UI | v3.2.0 |
React | 16.5.2 |
Browser | Chrome |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:19 (13 by maintainers)
Top GitHub Comments
While a fix in HEAD is good I failed to add a temporary workaround for everyone affected:
https://codesandbox.io/s/248j265l5r:
Basically add to
ContentProps
theheadlineMapping
conforming to the above shape.@brauliodiez Sorry I need to manage by sandboxes better. I had to delete everything recently because I reached the free usage limit.
Updated link: https://codesandbox.io/s/zz6wnqklzm (demo.js#71-74)