fix(ui) - modal handle browser back button
This commit is contained in:
parent
7a299fabc0
commit
007993608f
1 changed files with 21 additions and 11 deletions
|
|
@ -1,16 +1,26 @@
|
|||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import ModalOverlay from './ModalOverlay';
|
||||
import { useHistory } from 'react-router';
|
||||
|
||||
export default function Modal({ component, props, hideModal }: any) {
|
||||
return component ? (
|
||||
ReactDOM.createPortal(
|
||||
<ModalOverlay hideModal={hideModal} left={!props.right} right={props.right}>
|
||||
{component}
|
||||
</ModalOverlay>,
|
||||
document.querySelector('#modal-root')
|
||||
)
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
const history = useHistory();
|
||||
|
||||
useEffect(() => {
|
||||
return history.listen((location) => {
|
||||
if (history.action === 'POP') {
|
||||
document.querySelector('body').style.overflow = 'visible';
|
||||
}
|
||||
});
|
||||
});
|
||||
return component ? (
|
||||
ReactDOM.createPortal(
|
||||
<ModalOverlay hideModal={hideModal} left={!props.right} right={props.right}>
|
||||
{component}
|
||||
</ModalOverlay>,
|
||||
document.querySelector('#modal-root')
|
||||
)
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue