Skip to content

Commit

Permalink
[material-ui][Tab] Fix applying iconWrapper styles from theme and u…
Browse files Browse the repository at this point in the history
…pdate its description (#42549)

Co-authored-by: ZeeshanTamboli <zeeshan.tamboli@gmail.com>
  • Loading branch information
2 people authored and web-flow committed Jun 8, 2024
1 parent 8417e42 commit 23ed08e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
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 @@ -41,6 +41,9 @@ const TabRoot = styled(ButtonBase, {
styles[`textColor${capitalize(ownerState.textColor)}`],
ownerState.fullWidth && styles.fullWidth,
ownerState.wrapped && styles.wrapped,
{
[`& .${tabClasses.iconWrapper}`]: styles.iconWrapper,
},
];
},
})(({ theme, ownerState }) => ({
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

0 comments on commit 23ed08e

Please sign in to comment.