From 5ee60ef0011cc6aad5255003fe1888bd6632553c Mon Sep 17 00:00:00 2001 From: Haseeb Adil Khan Date: Wed, 20 Dec 2023 00:08:15 -0700 Subject: [PATCH] fix modal scrolling behaviour --- src/components/Mapathons/InformationDialog.js | 68 +++++++++++++------ src/styles.js | 17 ----- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/components/Mapathons/InformationDialog.js b/src/components/Mapathons/InformationDialog.js index 4516688..87c9885 100644 --- a/src/components/Mapathons/InformationDialog.js +++ b/src/components/Mapathons/InformationDialog.js @@ -1,38 +1,64 @@ -import React from 'react' +import React, { useEffect } from 'react' import PropTypes from 'prop-types' import { intlShape } from 'react-intl' import styled from 'styled-components' - import Icon from '../Icon' import { colors, media } from '../../styles' -export default class Modal extends React.Component { - onClose = e => { - this.props.onClose && this.props.onClose(e) +const ModalWrapper = styled.div` + .modal { + background-color: rgba( 0, 0, 0, .35); + position: fixed; + width: 100%; + height: 100%; + z-index: 99999; + top: 0; + right: 0; + } + + .modal-container { + background-color: white; + padding: 20px; + margin: 40px 20px; + border-radius: 15px; + height: 90% + overflow: auto; } +` - render() { - if (!this.props.show) { - return null - } - return ( +const Modal = ({ onClose, show, children }) => { + useEffect( + () => { + const handleBodyOverflow = () => { + document.body.style.overflow = show ? 'hidden' : 'auto' + } + handleBodyOverflow() + return () => { + document.body.style.overflow = 'auto' + } + }, + [show] + ) + + if (!show) { + return null + } + + return