From 2f81d7cc3d0802d4ee03a51c26e5ceaaad5a7875 Mon Sep 17 00:00:00 2001
From: Asmaa EL MOKHTARI <100131224+AsmaaELM@users.noreply.github.com>
Date: Tue, 1 Mar 2022 12:02:19 +0100
Subject: [PATCH] fix modal position within table
---
src/lib/components/modal/Modal.component.js | 47 ++++++----
stories/modal.stories.js | 96 ++++++++++++++++++++-
2 files changed, 125 insertions(+), 18 deletions(-)
diff --git a/src/lib/components/modal/Modal.component.js b/src/lib/components/modal/Modal.component.js
index 2019ef282b..40b9beda2a 100644
--- a/src/lib/components/modal/Modal.component.js
+++ b/src/lib/components/modal/Modal.component.js
@@ -1,9 +1,10 @@
//@flow
-import React from 'react';
+import React, { useEffect } from 'react';
import styled from 'styled-components';
import * as defaultTheme from '../../style/theme';
import type { Node } from 'react';
import { getThemePropSelector } from '../../utils';
+import ReactDom from 'react-dom';
type Props = {
isOpen: boolean,
@@ -65,22 +66,34 @@ const ModalClose = styled.div`
`;
const Modal = ({ isOpen, close, title, children, footer, ...rest }: Props) => {
- return isOpen ? (
-
-
-
- {title}
-
-
-
-
- {children}
- {footer && (
- {footer}
- )}
-
-
- ) : null;
+ const modalContainer = document.createElement('div');
+
+ useEffect(() => {
+ document.body && document.body.appendChild(modalContainer);
+ return () => {
+ document.body && document.body.removeChild(modalContainer);
+ };
+ }, [modalContainer]);
+
+ return isOpen
+ ? ReactDom.createPortal(
+
+
+
+ {title}
+
+
+
+
+ {children}
+ {footer && (
+ {footer}
+ )}
+
+ ,
+ modalContainer,
+ )
+ : null;
};
export default Modal;
diff --git a/stories/modal.stories.js b/stories/modal.stories.js
index 4ed7d70552..51de009ec2 100644
--- a/stories/modal.stories.js
+++ b/stories/modal.stories.js
@@ -1,9 +1,10 @@
//@flow
-import React from 'react';
+import React, { useState } from 'react';
import Modal from '../src/lib/components/modal/Modal.component';
import Button from '../src/lib/components/button/Button.component';
import { action } from '@storybook/addon-actions';
import { Wrapper } from './common';
+import Table from '../src/lib/components/tablev2/Tablev2.component';
export default {
title: 'Components/Notification/Modal',
@@ -39,3 +40,96 @@ export const Default = () => {
);
};
+
+const Action = () => {
+ const [displayed, setDisplayed] = useState(false);
+ return (
+ <>
+