Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Typography] Color prop check for primitive type #39071

Merged
merged 8 commits into from
Oct 5, 2023
Merged
16 changes: 16 additions & 0 deletions packages/mui-material/src/Typography/Typography.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, describeConformance } from 'test/utils';
import Typography, { typographyClasses as classes } from '@mui/material/Typography';
import sinon from 'sinon';

describe('<Typography />', () => {
const { render } = createRenderer();
Expand Down Expand Up @@ -112,6 +113,21 @@ describe('<Typography />', () => {
});
});

describe('prop: color', () => {
it('should check for invalid color value', () => {
const consoleErrorStub = sinon.stub(console, 'error');

render(
<Typography variant="h6" color="background">
Hello
</Typography>,
);

sinon.assert.called(consoleErrorStub);
consoleErrorStub.restore();
});
});

it('combines system properties with the sx prop', () => {
const { container } = render(<Typography mt={2} mr={1} sx={{ marginRight: 5, mb: 2 }} />);

Expand Down
8 changes: 8 additions & 0 deletions packages/mui-system/src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export function getStyleValue(themeMapping, transform, propValueFinal, userValue
value = transform(value, userValue, themeMapping);
}

if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
DarhkVoyd marked this conversation as resolved.
Show resolved Hide resolved
// Log an error in development mode
if (process.env.NODE_ENV !== 'production') {
console.error(`Invalid value "${value}" for property "${userValue}"`);
}
value = userValue;
}

return value;
}

Expand Down