Skip to content

Commit 30484b8

Browse files
authored
[material-ui][CardActions][DialogActions] Apply margin for all children except for 1st child (#40168)
1 parent 12f773a commit 30484b8

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const AccordionActionsRoot = styled('div', {
3131
padding: 8,
3232
justifyContent: 'flex-end',
3333
...(!ownerState.disableSpacing && {
34-
'& > :not(:first-of-type)': {
34+
'& > :not(style) ~ :not(style)': {
3535
marginLeft: 8,
3636
},
3737
}),

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { createRenderer, describeConformance } from '@mui-internal/test-utils';
33
import AccordionActions, {
44
accordionActionsClasses as classes,
55
} from '@mui/material/AccordionActions';
6+
import Button from '@mui/material/Button';
7+
import { expect } from 'chai';
68

79
describe('<AccordionActions />', () => {
810
const { render } = createRenderer();
@@ -16,4 +18,29 @@ describe('<AccordionActions />', () => {
1618
testVariantProps: { disableSpacing: true },
1719
skip: ['componentProp', 'componentsProp'],
1820
}));
21+
22+
it('should apply margin to all children but the first one', function test() {
23+
if (/jsdom/.test(window.navigator.userAgent)) {
24+
this.skip();
25+
}
26+
27+
const { container } = render(
28+
<AccordionActions>
29+
<Button data-testid="child-1">Agree</Button>
30+
<Button data-testid="child-2" href="#">
31+
Agree
32+
</Button>
33+
<Button data-testid="child-3" component="span">
34+
Agree
35+
</Button>
36+
<div data-testid="child-4" />
37+
</AccordionActions>,
38+
);
39+
40+
const children = container.querySelectorAll('[data-testid^="child-"]');
41+
expect(children[0]).toHaveComputedStyle({ marginLeft: '0px' });
42+
expect(children[1]).toHaveComputedStyle({ marginLeft: '8px' });
43+
expect(children[2]).toHaveComputedStyle({ marginLeft: '8px' });
44+
expect(children[3]).toHaveComputedStyle({ marginLeft: '8px' });
45+
});
1946
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const CardActionsRoot = styled('div', {
3030
alignItems: 'center',
3131
padding: 8,
3232
...(!ownerState.disableSpacing && {
33-
'& > :not(:first-of-type)': {
33+
'& > :not(style) ~ :not(style)': {
3434
marginLeft: 8,
3535
},
3636
}),

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from 'react';
22
import { createRenderer, describeConformance } from '@mui-internal/test-utils';
33
import CardActions, { cardActionsClasses as classes } from '@mui/material/CardActions';
4+
import Button from '@mui/material/Button';
5+
import { expect } from 'chai';
46

57
describe('<CardActions />', () => {
68
const { render } = createRenderer();
@@ -14,4 +16,29 @@ describe('<CardActions />', () => {
1416
testVariantProps: { disableSpacing: true },
1517
skip: ['componentProp', 'componentsProp'],
1618
}));
19+
20+
it('should apply margin to all children but the first one', function test() {
21+
if (/jsdom/.test(window.navigator.userAgent)) {
22+
this.skip();
23+
}
24+
25+
const { container } = render(
26+
<CardActions>
27+
<Button data-testid="child-1">Agree</Button>
28+
<Button data-testid="child-2" href="#">
29+
Agree
30+
</Button>
31+
<Button data-testid="child-3" component="span">
32+
Agree
33+
</Button>
34+
<div data-testid="child-4" />
35+
</CardActions>,
36+
);
37+
38+
const children = container.querySelectorAll('[data-testid^="child-"]');
39+
expect(children[0]).toHaveComputedStyle({ marginLeft: '0px' });
40+
expect(children[1]).toHaveComputedStyle({ marginLeft: '8px' });
41+
expect(children[2]).toHaveComputedStyle({ marginLeft: '8px' });
42+
expect(children[3]).toHaveComputedStyle({ marginLeft: '8px' });
43+
});
1744
});

0 commit comments

Comments
 (0)