-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Description
Steps to reproduce
In our own theme we augment an extra prop to Button, called dense
. But the issue is on all elements where we add an extra prop.
declare module '@mui/material/Button' {
interface ButtonOwnProps {
dense?: boolean
}
Now that totally works, we can use the prop in our styleOverride when creating our theme (using createTheme
). But in the end it also lands in its DOM. Because in MUI components only MUI specifics per component are guarded to not end up there. In our example for Button MUI prevents:
https://github.com/mui/material-ui/blob/master/packages/mui-material/src/Button/Button.js#L78-L82
const ButtonRoot = styled(ButtonBase, {
shouldForwardProp: (prop) => rootShouldForwardProp(prop) || prop === 'classes',
function slotShouldForwardProp(prop: string) {
return prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as';
}
Current behavior
It passes newly added props directly to the DOM. Because MUI leans on Emotion. And Emotion doesn't like the transcient prop setup Styled Components is using, where we can use $
to filter these out.
Expected behavior
Maybe MUI can support the concept of a transcient prop, or at least tell which prop to not forward. Since externally we do not want a prop to be named $dense
but dense
:)
Context
We want to be as close as possible to MUI. We create its theme and use all existing props and additions. Which makes MUI very flexible. But the price we pay is that attributes get all the way to its DOM node itself. For which we should get a solution. Is ownerState the only solution?
Your environment
in all versions of MUI same behaviour
Search keywords: shouldforward, emotion