[Divider] Non-integer values passed to theme.spacing in MuiDivider wrapper result in error when spacing is an array #29479
Labels
new feature
New feature or request
package: material-ui
Specific to @mui/material
ready to take
Help wanted. Guidance available. There is a high chance the change will be accepted
Summary: Non-integer values are provided to the
theme.spacing()
function, when styling the DividerWrapper component. When the default theme spacing has been overridden with an array, these non-integer values are not valid indexes, and result in an error.Current Behavior 😯
I have defined a custom theme with my own spacing rules, overriding the default spacing with a custom array, i.e.:
I mounted a
<Divider />
component with children, e.g.:At first, it seemed the child text content rendered correctly, inside a "wrapper" element within the divider:
.
However, you may notice that, unlike the example in the MUI Docs, there is no padding around the child content wrapper. In the browser's developer console, I was greeted with the following error:
There are two factors contributing to this problem.
In the default styling for the
DividerWrapper
(see here: https://github.com/mui-org/material-ui/blob/master/packages/mui-material/src/Divider/Divider.js#L166), non-integer values are being passed to thetheme.spacing()
function. The following excerpt is lines 158-163 in Divider.js:However, as I mentioned above, I have overridden the default spacing with a custom array. As a result, values passed to
theme.spacing()
must now be valid indexes of that array, and are therefore limited to integers. When theDividerWrapper
styles attempt to calltheme.spacing(1.2)
, the above error occurs.Expected Behavior 🤔
DividerWrapper
styles, and any spacing values passed to style rules therein, should work correctly regardless of whether the theme spacing is an integer coefficient or a custom array. If it's absolutely necessary for the default value to be "something x 1.2", then we ought to do it this way:Steps to Reproduce 🕹
View this CodeSandbox for a simple reproduction of this issue:
https://codesandbox.io/s/frosty-matsumoto-4fpgj?file=/src/Demo.tsx
Open the "Console" tab to see the console error
Context 🔦
N/A -- See CodeSandbox link above
Your Environment 🌎
I am running
@mui/material
version 5.0.6The text was updated successfully, but these errors were encountered: