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

[Card] Fix CardActions spacing for different button components #31885

Open
wants to merge 10 commits into
base: next
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const AccordionActionsRoot = styled('div', {
{
props: (props) => !props.disableSpacing,
style: {
'& > :not(style) ~ :not(style)': {
marginLeft: 8,
},
gap: 8,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { createRenderer } from '@mui/internal-test-utils';
import AccordionActions, {
accordionActionsClasses as classes,
} from '@mui/material/AccordionActions';
import Button from '@mui/material/Button';
import { expect } from 'chai';
import describeConformance from '../../test/describeConformance';

Expand All @@ -20,28 +19,13 @@ describe('<AccordionActions />', () => {
skip: ['componentProp', 'componentsProp'],
}));

it('should apply margin to all children but the first one', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const { container } = render(
it('should render a children element', function test() {
const { queryByTestId } = render(
<AccordionActions>
<Button data-testid="child-1">Agree</Button>
<Button data-testid="child-2" href="#">
Agree
</Button>
<Button data-testid="child-3" component="span">
Agree
</Button>
<div data-testid="child-4" />
<div data-testid="test-children" />
</AccordionActions>,
);

const children = container.querySelectorAll('[data-testid^="child-"]');
expect(children[0]).toHaveComputedStyle({ marginLeft: '0px' });
expect(children[1]).toHaveComputedStyle({ marginLeft: '8px' });
expect(children[2]).toHaveComputedStyle({ marginLeft: '8px' });
expect(children[3]).toHaveComputedStyle({ marginLeft: '8px' });
expect(queryByTestId('test-children')).not.to.equal(null);
});
});
4 changes: 1 addition & 3 deletions packages/mui-material/src/CardActions/CardActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ const CardActionsRoot = styled('div', {
{
props: { disableSpacing: false },
style: {
'& > :not(style) ~ :not(style)': {
marginLeft: 8,
},
gap: 8,
},
},
],
Expand Down
24 changes: 4 additions & 20 deletions packages/mui-material/src/CardActions/CardActions.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { createRenderer } from '@mui/internal-test-utils';
import CardActions, { cardActionsClasses as classes } from '@mui/material/CardActions';
import Button from '@mui/material/Button';
import { expect } from 'chai';
import describeConformance from '../../test/describeConformance';

Expand All @@ -18,28 +17,13 @@ describe('<CardActions />', () => {
skip: ['componentProp', 'componentsProp'],
}));

it('should apply margin to all children but the first one', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const { container } = render(
it('should render a children element', function test() {
const { queryByTestId } = render(
<CardActions>
<Button data-testid="child-1">Agree</Button>
<Button data-testid="child-2" href="#">
Agree
</Button>
<Button data-testid="child-3" component="span">
Agree
</Button>
<div data-testid="child-4" />
<div data-testid="test-children" />
</CardActions>,
);

const children = container.querySelectorAll('[data-testid^="child-"]');
expect(children[0]).toHaveComputedStyle({ marginLeft: '0px' });
expect(children[1]).toHaveComputedStyle({ marginLeft: '8px' });
expect(children[2]).toHaveComputedStyle({ marginLeft: '8px' });
expect(children[3]).toHaveComputedStyle({ marginLeft: '8px' });
expect(queryByTestId('test-children')).not.to.equal(null);
});
});
4 changes: 1 addition & 3 deletions packages/mui-material/src/DialogActions/DialogActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ const DialogActionsRoot = styled('div', {
{
props: ({ ownerState }) => !ownerState.disableSpacing,
style: {
'& > :not(style) ~ :not(style)': {
marginLeft: 8,
},
gap: 8,
},
},
],
Expand Down
24 changes: 4 additions & 20 deletions packages/mui-material/src/DialogActions/DialogActions.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { createRenderer } from '@mui/internal-test-utils';
import DialogActions, { dialogActionsClasses as classes } from '@mui/material/DialogActions';
import Button from '@mui/material/Button';
import { expect } from 'chai';
import describeConformance from '../../test/describeConformance';

Expand All @@ -18,28 +17,13 @@ describe('<DialogActions />', () => {
skip: ['componentProp', 'componentsProp'],
}));

it('should apply margin to all children but the first one', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const { container } = render(
it('should render a children element', function test() {
const { queryByTestId } = render(
<DialogActions>
<Button data-testid="child-1">Agree</Button>
<Button data-testid="child-2" href="#">
Agree
</Button>
<Button data-testid="child-3" component="span">
Agree
</Button>
<div data-testid="child-4" />
<div data-testid="test-children" />
</DialogActions>,
);

const children = container.querySelectorAll('[data-testid^="child-"]');
expect(children[0]).toHaveComputedStyle({ marginLeft: '0px' });
expect(children[1]).toHaveComputedStyle({ marginLeft: '8px' });
expect(children[2]).toHaveComputedStyle({ marginLeft: '8px' });
expect(children[3]).toHaveComputedStyle({ marginLeft: '8px' });
expect(queryByTestId('test-children')).not.to.equal(null);
});
});
19 changes: 19 additions & 0 deletions test/regressions/fixtures/Accordion/AccordionActionsGap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import { AccordionActions, Button } from '@mui/material';

function AccordionActionsGap() {
return (
<AccordionActions>
<Button data-testid="child-1">Agree</Button>
<Button data-testid="child-2" href="#">
Agree
</Button>
<Button data-testid="child-3" component="span">
Agree
</Button>
<div data-testid="child-4" />
</AccordionActions>
);
}

export default AccordionActionsGap;
19 changes: 19 additions & 0 deletions test/regressions/fixtures/Card/CardActionsGap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import { CardActions, Button } from '@mui/material';

function CardActionsGap() {
return (
<CardActions>
<Button data-testid="child-1">Agree</Button>
<Button data-testid="child-2" href="#">
Agree
</Button>
<Button data-testid="child-3" component="span">
Agree
</Button>
<div data-testid="child-4" />
</CardActions>
);
}

export default CardActionsGap;
19 changes: 19 additions & 0 deletions test/regressions/fixtures/Dialog/DialogActionsGap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import { DialogActions, Button } from '@mui/material';

function DialogActionsGap() {
return (
<DialogActions>
<Button data-testid="child-1">Agree</Button>
<Button data-testid="child-2" href="#">
Agree
</Button>
<Button data-testid="child-3" component="span">
Agree
</Button>
<div data-testid="child-4" />
</DialogActions>
);
}

export default DialogActionsGap;