Skip to content

Commit

Permalink
Prevent body from scrolling when a modal is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Feb 4, 2017
1 parent 7db22db commit 6369b15
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/web/containers/Workspace/WidgetManager/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ export const getInactiveWidgets = () => {

// @param {string} targetContainer The target container: primary|secondary
export const show = (callback) => {
const body = document.querySelector('body');
const bodyStyle = {
overflowY: ''
};
const el = document.body.appendChild(document.createElement('div'));
const handleClose = (e) => {
body.style.overflowY = bodyStyle.overflowY;

ReactDOM.unmountComponentAtNode(el);
setTimeout(() => {
el.remove();
}, 0);
};

// Prevent body from scrolling when a modal is opened
bodyStyle.overflowY = body.style.overflowY;
body.style.overflowY = 'hidden';

ReactDOM.render(<WidgetManager onSave={callback} onClose={handleClose} />, el);
};

0 comments on commit 6369b15

Please sign in to comment.