Open tiuvi opened 2 years ago
It doesn't look like this bug report has enough info for one of us to reproduce it.
Please provide a CodeSandbox (https://material-ui.com/r/issue-template-latest), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem.
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve
Sorry I don't have time to fix this right now, just use defaultProps , and everything works fine. In the code it is clearly seen that you overwrite the variable by doing variantMapping = defaultVariantMapping, So here it doesn't read because defaultVariantMapping overwrites variantMapping, there's not much to prove. (paragraph ? 'p' : variantMapping[variant] || defaultVariantMapping[variant])
I think the docs should mention that the custom variantMapping
will replace the defaultVariantMapping
, so developers have to provide all of the default mapping + custom mapping.
https://mui.com/material-ui/react-typography/#changing-the-semantic-element
I think the expected behavior should be merging not replacing. I don't see any blockers if we want to improve this:
variantMapping
, it will override the default one anyway.diff --git a/packages/mui-material/src/Typography/Typography.js b/packages/mui-material/src/Typography/Typography.js
index 37d1d450cf..340294b8b0 100644
--- a/packages/mui-material/src/Typography/Typography.js
+++ b/packages/mui-material/src/Typography/Typography.js
@@ -99,9 +99,10 @@ const Typography = React.forwardRef(function Typography(inProps, ref) {
noWrap = false,
paragraph = false,
variant = 'body1',
- variantMapping = defaultVariantMapping,
+ variantMapping: variantMappingProp,
...other
} = props;
+ const variantMapping = { ...defaultVariantMapping, ...variantMappingProp };
const ownerState = {
...props,
@@ -116,10 +117,7 @@ const Typography = React.forwardRef(function Typography(inProps, ref) {
variantMapping,
};
- const Component =
- component ||
- (paragraph ? 'p' : variantMapping[variant] || defaultVariantMapping[variant]) ||
- 'span';
+ const Component = component || (paragraph ? 'p' : variantMapping[variant]) || 'span';
const classes = useUtilityClasses(ownerState);
Duplicates
Latest version
Current behavior 😯
variantMapping es sobreescrito por defaultVariantMapping estropeando la variantMapping propiedad.
https://github.com/mui/material-ui/blob/92a4866ce9a06769592cddc06cfa7455b4644544/packages/mui-material/src/Typography/Typography.js#L102
Se podrÃa cambiar esta linea por variantMapping["defaultVariantMapping"] = defaultVariantMapping,
En esta linea variantMapping[variant] no se lee nunca porque las propiedades quedan sobre escritas. https://github.com/mui/material-ui/blob/92a4866ce9a06769592cddc06cfa7455b4644544/packages/mui-material/src/Typography/Typography.js#L121
Expected behavior 🤔
Que variantMapping funcione de manera correcta, sin tener que usar la api de componentes.
Steps to reproduce 🕹
Crear un tema y probar las opciones de typography con diferentes api typography: {
},
components: { MuiTypography: {
/ Nofunciona variantMapping: { "mark": 'mark', }, / defaultProps: { variantMapping: { subtitle1: 'header', subtitle2: 'header', "mark": 'mark', "em": 'em', }, }, }, },
Context 🔦
Al ver porque usabais defaultProps me di cuenta de este error.
Your environment 🌎
No response