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

[List] Add support for list item container style overrides #25777

Merged
merged 13 commits into from
Apr 16, 2021
6 changes: 3 additions & 3 deletions packages/material-ui/src/ListItem/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const ListItemContainer = experimentalStyled(
{
name: 'MuiListItem',
slot: 'Container',
overridesResolver,
overridesResolver: (props, styles) => styles.container,
},
)({
position: 'relative',
Expand Down Expand Up @@ -263,13 +263,13 @@ const ListItem = React.forwardRef(function ListItem(inProps, ref) {
as={ContainerComponent}
className={clsx(classes.container, ContainerClassName)}
ref={handleRef}
styleProps={styleProps}
{...ContainerProps}
>
<Root
{...rootProps}
as={Component}
styleProps={styleProps}
{...(!isHostComponent(Root) && {
as: Component,
styleProps: { ...styleProps, ...rootProps.styleProps },
})}
{...componentProps}
Expand Down
32 changes: 32 additions & 0 deletions packages/material-ui/src/ListItem/ListItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
fireEvent,
queries,
} from 'test/utils';
import { ThemeProvider, createMuiTheme } from '@material-ui/core/styles';
import ListItemText from '@material-ui/core/ListItemText';
import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction';
import ListItem, { listItemClasses as classes } from '@material-ui/core/ListItem';
Expand Down Expand Up @@ -203,4 +204,35 @@ describe('<ListItem />', () => {
expect(button).to.have.class(classes.focusVisible);
});
});

it('container overrides should work', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const testStyle = {
marginTop: '13px',
};

const theme = createMuiTheme({
components: {
MuiListItem: {
styleOverrides: {
container: testStyle,
},
},
},
});

const { container } = render(
<ThemeProvider theme={theme}>
<ListItem>
Test<ListItemSecondaryAction>SecondaryAction</ListItemSecondaryAction>
</ListItem>
</ThemeProvider>,
);

const listItemContainer = container.getElementsByClassName(classes.container)[0];
expect(listItemContainer).to.toHaveComputedStyle(testStyle);
});
});