From 645ceb4fdd725d700d8893bc8ad3c9dbfc4e563d Mon Sep 17 00:00:00 2001 From: Michael LoTurco Date: Fri, 23 Feb 2018 14:23:38 -0500 Subject: [PATCH] feat(modal): use portals render modal at top-level in dom via a portal instead of inside parent component BREAKING CHANGE: Modal now renders through a Portal, this may cause failures in tests or styling rules that expect the modal in specific places in the dom tree --- .storybook/Storyshots.test.js | 5 +- .../__snapshots__/Storyshots.test.js.snap | 770 +----------------- src/Modal/Modal.stories.jsx | 53 ++ src/Modal/Modal.test.jsx | 57 +- src/Modal/README.md | 3 + src/Modal/index.jsx | 103 ++- 6 files changed, 213 insertions(+), 778 deletions(-) diff --git a/.storybook/Storyshots.test.js b/.storybook/Storyshots.test.js index 386a84488a..d116e2972b 100644 --- a/.storybook/Storyshots.test.js +++ b/.storybook/Storyshots.test.js @@ -7,7 +7,10 @@ jest.mock("react-dom", () => { render: () => null, unmountComponentAtNode: () => null, findDOMNode: () => null, + createPortal: () => null, }; }); -initStoryshots(); +initStoryshots({ + storyKindRegex: /^((?!.*?Modal).)*$/, +}); diff --git a/.storybook/__snapshots__/Storyshots.test.js.snap b/.storybook/__snapshots__/Storyshots.test.js.snap index b8c121b48a..4f403fed5e 100644 --- a/.storybook/__snapshots__/Storyshots.test.js.snap +++ b/.storybook/__snapshots__/Storyshots.test.js.snap @@ -20734,710 +20734,6 @@ exports[`Storyshots MailtoLink with subject and body 1`] = ` `; -exports[`Storyshots Modal basic usage 1`] = ` -
-
-
-
-

- Modal title. -

- -
-
-

- Modal body. -

-
-
- -
-
-
-
-`; - -exports[`Storyshots Modal configurable buttons 1`] = ` -
-
-
-
-

- Modal title. -

- -
-
-

- Modal body. -

-
-
- - - - -
-
-
-
-`; - -exports[`Storyshots Modal configurable buttons that perform actions 1`] = ` -
-
-
-
-

- Modal title. -

- -
-
-

- Modal body. -

-
-
- - -
-
-
-
-`; - -exports[`Storyshots Modal configurable close button 1`] = ` -
-
-
-
-

- Modal title. -

- -
-
-

- Modal body. -

-
-
- -
-
-
-
-`; - -exports[`Storyshots Modal configurable title and body 1`] = ` -
-
-
-
-

- Custom title! -

- -
-
-

- Custom body! -

-
-
- - -
-
-
-
-`; - -exports[`Storyshots Modal modal invoked via a button 1`] = ` -
-
-
-
-
-

- I am the modal! -

- -
-
-

- I was invoked by a button! -

-
-
- -
-
-
-
- -
-`; - -exports[`Storyshots Modal modal with element body 1`] = ` -
-
-
-
-

- Modal title. -

- -
-
-
-

- Enter your e-mail address to receive free cat facts! -

-
- - -
- -
-
- -
-
-
- -
-
-
-
-`; - -exports[`Storyshots Modal modal with warning variant 1`] = ` -
-
-
-
-

- Warning Modal -

- -
-
-
-
-
-
-

- Be careful! It is dangerous ahead. -

-
-
-
-
- -
-
-
-
-
-
- - -
-
-
-
-`; - -exports[`Storyshots Modal modal without a close button in the header 1`] = ` -
-
-
-
-

- Modal title. -

-
-
-

- Modal body. -

-
-
- -
-
-
-
-`; - exports[`Storyshots Paragon Welcome 1`] = `
  • @@ -25768,9 +25064,9 @@ exports[`Storyshots Tabs basic usage 1`] = `
    @@ -25779,9 +25075,9 @@ exports[`Storyshots Tabs basic usage 1`] = `
    @@ -25806,8 +25102,8 @@ exports[`Storyshots Textarea label as element 1`] = ` "", ] } - htmlFor="asInput48" - id="label-asInput48" + htmlFor="asInput37" + id="label-asInput37" >