Skip to content

Commit

Permalink
[Dialog] Fix broken styles if maxWidth is set to false (#32987)
Browse files Browse the repository at this point in the history
* Remove broken styles from MuiDialog-maxWidthFalse class

* Fix prettier formatting of Dialog component

* Add test that paperWidthFalse class is applied in Dialog when maxWidth is false

* Test Dialog paper styles when maxWidth={false}

* Fix prettier errors in Dialog tests

* improve tests

* test can be run in jsdom

* Yarn prettier changes to Dialog.test.js

Co-authored-by: ZeeshanTamboli <[email protected]>
  • Loading branch information
kmurgic and ZeeshanTamboli committed Jun 16, 2022
1 parent 67186bf commit de420be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/mui-material/src/Dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ const DialogPaper = styled(Paper, {
},
},
}),
...(ownerState.maxWidth !== 'xs' && {
maxWidth: `${theme.breakpoints.values[ownerState.maxWidth]}${theme.breakpoints.unit}`,
[`&.${dialogClasses.paperScrollBody}`]: {
[theme.breakpoints.down(theme.breakpoints.values[ownerState.maxWidth] + 32 * 2)]: {
maxWidth: 'calc(100% - 64px)',
...(ownerState.maxWidth &&
ownerState.maxWidth !== 'xs' && {
maxWidth: `${theme.breakpoints.values[ownerState.maxWidth]}${theme.breakpoints.unit}`,
[`&.${dialogClasses.paperScrollBody}`]: {
[theme.breakpoints.down(theme.breakpoints.values[ownerState.maxWidth] + 32 * 2)]: {
maxWidth: 'calc(100% - 64px)',
},
},
},
}),
}),
...(ownerState.fullWidth && {
width: 'calc(100% - 64px)',
}),
Expand Down
21 changes: 21 additions & 0 deletions packages/mui-material/src/Dialog/Dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,27 @@ describe('<Dialog />', () => {
);
expect(getByTestId('paper')).to.have.class(classes.paperWidthXs);
});

it('should use the right className when maxWidth={false}', () => {
render(
<Dialog open maxWidth={false} PaperProps={{ 'data-testid': 'paper' }}>
foo
</Dialog>,
);
expect(screen.getByTestId('paper')).to.have.class(classes.paperWidthFalse);
});

it('should apply the correct max-width styles when maxWidth={false}', () => {
render(
<Dialog open maxWidth={false} PaperProps={{ 'data-testid': 'paper' }}>
foo
</Dialog>,
);

expect(screen.getByTestId('paper')).toHaveComputedStyle({
maxWidth: 'calc(100% - 64px)',
});
});
});

describe('prop: fullWidth', () => {
Expand Down

0 comments on commit de420be

Please sign in to comment.