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

[ListItemText] Fix variant mapping in primaryTypography #33880

Merged
merged 6 commits into from Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mui-material/src/ListItemText/ListItemText.js
Expand Up @@ -84,7 +84,7 @@ const ListItemText = React.forwardRef(function ListItemText(inProps, ref) {
<Typography
variant={dense ? 'body2' : 'body1'}
className={classes.primary}
component="span"
component={primaryTypographyProps?.variant ? undefined : 'span'}
display="block"
{...primaryTypographyProps}
>
Expand Down
21 changes: 21 additions & 0 deletions packages/mui-material/src/ListItemText/ListItemText.test.js
Expand Up @@ -155,6 +155,27 @@ describe('<ListItemText />', () => {
expect(texts[1]).have.text('This is the secondary text');
});

it('should use variant if provided', () => {
const { getByText } = render(
<ListItemText
primary="This is the primary text"
primaryTypographyProps={{ variant: 'h3' }}
secondary="This is the secondary text"
secondaryTypographyProps={{ variant: 'h4' }}
/>,
);
expect(getByText('This is the primary text')).to.have.tagName('h3');
expect(getByText('This is the secondary text')).to.have.tagName('h4');
});

it('should fall back to the default tag name if no variant provided', () => {
const { getByText } = render(
<ListItemText primary="This is the primary text" secondary="This is the secondary text" />,
);
expect(getByText('This is the primary text')).to.have.tagName('span');
expect(getByText('This is the secondary text')).to.have.tagName('p');
});

it('should pass primaryTypographyProps to primary Typography component', () => {
const { container } = render(
<ListItemText
Expand Down