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][Tab] Fix applying iconWrapper styles from theme and update its description #42549

Merged
merged 12 commits into from
Jun 8, 2024
2 changes: 1 addition & 1 deletion docs/pages/material-ui/api/tab.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{
"key": "iconWrapper",
"className": "MuiTab-iconWrapper",
"description": "Styles applied to the wrapper element of `icon` if `icon` is provided.",
"description": "Styles applied to the `icon` HTML element if both `icon` and `label` are provided.",
"isGlobal": false
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/translations/api-docs/tab/tab.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
},
"iconWrapper": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the wrapper element of <code>icon</code>",
"conditions": "<code>icon</code> is provided"
"nodeName": "the <code>icon</code> HTML element",
"conditions": "both <code>icon</code> and <code>label</code> are provided"
},
"labelIcon": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
Expand Down
3 changes: 3 additions & 0 deletions packages/mui-material/src/Tab/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const TabRoot = styled(ButtonBase, {
styles[`textColor${capitalize(ownerState.textColor)}`],
ownerState.fullWidth && styles.fullWidth,
ownerState.wrapped && styles.wrapped,
{
[`& .${tabClasses.iconWrapper}`]: styles.iconWrapper,
},
];
},
})(({ theme }) => ({
Expand Down
29 changes: 29 additions & 0 deletions packages/mui-material/src/Tab/Tab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { spy } from 'sinon';
import { act, createRenderer, fireEvent } from '@mui/internal-test-utils';
import Tab, { tabClasses as classes } from '@mui/material/Tab';
import ButtonBase from '@mui/material/ButtonBase';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import describeConformance from '../../test/describeConformance';

describe('<Tab />', () => {
Expand Down Expand Up @@ -167,4 +168,32 @@ describe('<Tab />', () => {
expect(style).to.have.property('alignText', 'center');
});
});

it('should apply iconWrapper styles from theme', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const theme = createTheme({
components: {
MuiTab: {
styleOverrides: {
iconWrapper: {
backgroundColor: 'rgb(0, 0, 255)',
},
},
},
},
});

const { getByRole } = render(
<ThemeProvider theme={theme}>
<Tab icon={<div>hello</div>} label="icon" />
</ThemeProvider>,
);
const icon = getByRole('tab').querySelector(`.${classes.iconWrapper}`);
expect(icon).toHaveComputedStyle({
backgroundColor: 'rgb(0, 0, 255)',
});
});
});
2 changes: 1 addition & 1 deletion packages/mui-material/src/Tab/tabClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface TabClasses {
fullWidth: string;
/** Styles applied to the root element if `wrapped={true}`. */
wrapped: string;
/** Styles applied to the wrapper element of `icon` if `icon` is provided. */
/** Styles applied to the `icon` HTML element if both `icon` and `label` are provided. */
iconWrapper: string;
}

Expand Down