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

[Modal] Take into account the body margin #7666

Merged
merged 1 commit into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/internal/modalManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ function bodyIsOverflowing(node) {
const doc = ownerDocument(node);
const win = isWindow(doc);

return doc.body.clientWidth < win.innerWidth;
// Takes in account potential non zero margin on the body.
const style = window.getComputedStyle(doc.body);
const marginLeft = parseInt(style.getPropertyValue('margin-left'), 10);
const marginRight = parseInt(style.getPropertyValue('margin-right'), 10);

return marginLeft + doc.body.clientWidth + marginRight < win.innerWidth;
}

// The container shouldn't be used on the server.
Expand Down Expand Up @@ -57,13 +62,14 @@ function createModalManager(

if (bodyIsOverflowing(container)) {
prevPaddings = [getPaddingRight(container)];
container.style.paddingRight = `${prevPaddings[0] + getScrollbarSize()}px`;
const scrollbarSize = getScrollbarSize();
container.style.paddingRight = `${prevPaddings[0] + scrollbarSize}px`;

const fixedNodes = document.querySelectorAll('.mui-fixed');
for (let i = 0; i < fixedNodes.length; i += 1) {
const paddingRight = getPaddingRight(fixedNodes[i]);
prevPaddings.push(paddingRight);
fixedNodes[i].style.paddingRight = `${paddingRight + getScrollbarSize()}px`;
fixedNodes[i].style.paddingRight = `${paddingRight + scrollbarSize}px`;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/internal/modalManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('internal/modalManager', () => {
fixedNode.classList.add('mui-fixed');
fixedNode.style.padding = '14px';
window.document.body.appendChild(fixedNode);
window.innerWidth += 1; // simulate a scrollbar
});

afterEach(() => {
Expand Down