Skip to content

Commit 23ed08e

Browse files
sai6855ZeeshanTamboli
authored andcommitted
[material-ui][Tab] Fix applying iconWrapper styles from theme and update its description (#42549)
Co-authored-by: ZeeshanTamboli <[email protected]>
1 parent 8417e42 commit 23ed08e

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

docs/pages/material-ui/api/tab.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
{
4343
"key": "iconWrapper",
4444
"className": "MuiTab-iconWrapper",
45-
"description": "Styles applied to the wrapper element of `icon` if `icon` is provided.",
45+
"description": "Styles applied to the `icon` HTML element if both `icon` and `label` are provided.",
4646
"isGlobal": false
4747
},
4848
{

docs/translations/api-docs/tab/tab.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
},
3939
"iconWrapper": {
4040
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
41-
"nodeName": "the wrapper element of <code>icon</code>",
42-
"conditions": "<code>icon</code> is provided"
41+
"nodeName": "the <code>icon</code> HTML element",
42+
"conditions": "both <code>icon</code> and <code>label</code> are provided"
4343
},
4444
"labelIcon": {
4545
"description": "Styles applied to {{nodeName}} if {{conditions}}.",

packages/mui-material/src/Tab/Tab.js

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ const TabRoot = styled(ButtonBase, {
4141
styles[`textColor${capitalize(ownerState.textColor)}`],
4242
ownerState.fullWidth && styles.fullWidth,
4343
ownerState.wrapped && styles.wrapped,
44+
{
45+
[`& .${tabClasses.iconWrapper}`]: styles.iconWrapper,
46+
},
4447
];
4548
},
4649
})(({ theme, ownerState }) => ({

packages/mui-material/src/Tab/Tab.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { spy } from 'sinon';
44
import { act, createRenderer, fireEvent } from '@mui-internal/test-utils';
55
import Tab, { tabClasses as classes } from '@mui/material/Tab';
66
import ButtonBase from '@mui/material/ButtonBase';
7+
import { ThemeProvider, createTheme } from '@mui/material/styles';
78
import describeConformance from '../../test/describeConformance';
89

910
describe('<Tab />', () => {
@@ -167,4 +168,32 @@ describe('<Tab />', () => {
167168
expect(style).to.have.property('alignText', 'center');
168169
});
169170
});
171+
172+
it('should apply iconWrapper styles from theme', function test() {
173+
if (/jsdom/.test(window.navigator.userAgent)) {
174+
this.skip();
175+
}
176+
177+
const theme = createTheme({
178+
components: {
179+
MuiTab: {
180+
styleOverrides: {
181+
iconWrapper: {
182+
backgroundColor: 'rgb(0, 0, 255)',
183+
},
184+
},
185+
},
186+
},
187+
});
188+
189+
const { getByRole } = render(
190+
<ThemeProvider theme={theme}>
191+
<Tab icon={<div>hello</div>} label="icon" />
192+
</ThemeProvider>,
193+
);
194+
const icon = getByRole('tab').querySelector(`.${classes.iconWrapper}`);
195+
expect(icon).toHaveComputedStyle({
196+
backgroundColor: 'rgb(0, 0, 255)',
197+
});
198+
});
170199
});

packages/mui-material/src/Tab/tabClasses.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface TabClasses {
2020
fullWidth: string;
2121
/** Styles applied to the root element if `wrapped={true}`. */
2222
wrapped: string;
23-
/** Styles applied to the wrapper element of `icon` if `icon` is provided. */
23+
/** Styles applied to the `icon` HTML element if both `icon` and `label` are provided. */
2424
iconWrapper: string;
2525
}
2626

0 commit comments

Comments
 (0)