Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
feat(Modal): Only renders modal in DOM when visible (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewmorris authored Jan 8, 2020
1 parent 81e7057 commit 94e73c0
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Transition } from 'react-transition-group';
import { FocusOn } from 'react-focus-on';
import Portal from '../Portal';
import Flex from '../Flex';
import Box from '../Box';
import Icon from '../Icon';
import Button from '../Button';
import { createComponent, themeGet } from '../utils';

const ModalContext = createContext({});
Expand Down Expand Up @@ -103,7 +103,7 @@ export function Modal({ children, title, animationDuration, showClose, onClose,
return (
<ModalContext.Provider value={{ handleClose }}>
<Portal>
<Transition in={isOpen} timeout={animationDuration} onEntering={scrollToTop}>
<Transition in={isOpen} timeout={animationDuration} onEntering={scrollToTop} mountOnEnter unmountOnExit appear>
{state => (
<FocusOn onEscapeKey={handleClose} enabled={isOpen}>
<Backdrop ref={modalRef} transitionState={state} onClick={handleBackdropClick}>
Expand Down Expand Up @@ -185,27 +185,21 @@ Modal.Header = ({ title, children, showClose = true }) => {
<ModalHeader>
<ModalHeaderInner>
<Flex alignItems="center">
{title && (
<Modal.Title role="heading" tabIndex="0">
{title}
</Modal.Title>
)}
{title && <Modal.Title role="heading">{title}</Modal.Title>}
{children}

{showClose && (
<Box ml="auto">
<Icon
name="close"
color="greyDarkest"
style={{ cursor: 'pointer' }}
size={24}
onClick={handleClose}
onKeyDown={handleKeyDown}
role="button"
aria-label="Close Modal"
tabIndex="0"
/>
</Box>
<Button
variant="grey"
size="sm"
style={{ marginLeft: 'auto', border: 'none' }}
onClick={handleClose}
onKeyDown={handleKeyDown}
aria-label="Close Modal"
type="button"
tabIndex="-1">
<Icon name="close" color="greyDarkest" size={24} />
</Button>
)}
</Flex>
</ModalHeaderInner>
Expand Down

0 comments on commit 94e73c0

Please sign in to comment.