summaryrefslogtreecommitdiffhomepage
path: root/gui/src
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-04-06 17:37:31 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-04-06 20:40:45 +0200
commit12232927114272cfef87c64840d7ed0642da9659 (patch)
treeb9dca1459dac83a2fa2ed13421c9fd0d7355b126 /gui/src
parentfaaa5d91fe49f7b104d21dd868ad649b26fd0f98 (diff)
downloadmullvadvpn-12232927114272cfef87c64840d7ed0642da9659.tar.xz
mullvadvpn-12232927114272cfef87c64840d7ed0642da9659.zip
Render ModalAlert into element which is appended on mount
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/renderer/components/Modal.tsx22
1 files changed, 18 insertions, 4 deletions
diff --git a/gui/src/renderer/components/Modal.tsx b/gui/src/renderer/components/Modal.tsx
index b4c6ace833..c00a1be466 100644
--- a/gui/src/renderer/components/Modal.tsx
+++ b/gui/src/renderer/components/Modal.tsx
@@ -105,15 +105,29 @@ interface IModalAlertProps {
}
export class ModalAlert extends Component<IModalAlertProps> {
- public render() {
+ private element = document.createElement('div');
+ private modalContainer?: Element;
+
+ public componentDidMount() {
const modalContainer = document.getElementById(MODAL_CONTAINER_ID);
- if (modalContainer !== null) {
- return ReactDOM.createPortal(this.renderModal(), modalContainer);
+ if (modalContainer) {
+ this.modalContainer = modalContainer;
+ modalContainer.appendChild(this.element);
} else {
- throw Error('Modal container not found when rendering modal');
+ throw Error('Modal container not found when mounting modal');
+ }
+ }
+
+ public componentWillUnmount() {
+ if (this.modalContainer) {
+ this.modalContainer.removeChild(this.element);
}
}
+ public render() {
+ return ReactDOM.createPortal(this.renderModal(), this.element);
+ }
+
private renderModal() {
return (
<ModalBackground>