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

[material-ui][Dialog] Fix broken scrolling in full screen mode #43626

Merged
merged 9 commits into from
Sep 7, 2024
Merged
1 change: 1 addition & 0 deletions packages/mui-material/src/Dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const DialogPaper = styled(Paper, {
memoTheme(({ theme }) => ({
margin: 32,
position: 'relative',
overflowY: 'auto',
'@media print': {
overflowY: 'visible',
boxShadow: 'none',
Expand Down
29 changes: 29 additions & 0 deletions packages/mui-material/src/Dialog/Dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,35 @@ describe('<Dialog />', () => {
);
expect(getByTestId('paper')).not.to.have.class(classes.paperFullScreen);
});

it('scrolls if overflown on the Y axis', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const ITEM_HEIGHT = 100;
const ITEM_COUNT = 10;

const { getByTestId } = render(
<Dialog
open
fullScreen
PaperProps={{ 'data-testid': 'paper', sx: { height: ITEM_HEIGHT } }}
>
{Array.from(Array(ITEM_COUNT).keys()).map((item) => (
<div key={item} style={{ flexShrink: 0, height: ITEM_HEIGHT }}>
{item}
</div>
))}
</Dialog>,
);
const paperElement = getByTestId('paper');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the future, it should be

Suggested change
const paperElement = getByTestId('paper');
const paperElement = screen.getByTestId('paper');

per point 2 of mui/mui-public#173.

expect(paperElement.scrollTop).to.equal(0);
expect(paperElement.clientHeight).to.equal(ITEM_HEIGHT);
expect(paperElement.scrollHeight).to.equal(ITEM_HEIGHT * ITEM_COUNT);
fireEvent.scroll(paperElement, { target: { scrollTop: ITEM_HEIGHT } });
expect(paperElement.scrollTop).to.equal(ITEM_HEIGHT);
});
});

describe('prop: PaperProps.className', () => {
Expand Down