-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update EuiOverlayMask to use react portal (#254)
* update EuiOverlayMask to use react portal * change log * updates from cj review
- Loading branch information
Showing
4 changed files
with
33 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
src/components/overlay_mask/__snapshots__/overlay_mask.test.js.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,54 @@ | ||
import React, { | ||
Component, | ||
} from 'react'; | ||
/** | ||
* NOTE: We can't test this component because Enzyme doesn't support rendering | ||
* into portals. | ||
*/ | ||
|
||
import { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { createPortal } from 'react-dom'; | ||
import classNames from 'classnames'; | ||
|
||
export class EuiOverlayMask extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const { | ||
className, | ||
children, // eslint-disable-line no-unused-vars | ||
...rest | ||
} = this.props; | ||
|
||
this.overlayMaskNode = document.createElement('div'); | ||
this.overlayMaskNode.className = classNames( | ||
'euiOverlayMask', | ||
className | ||
); | ||
Object.keys(rest).forEach((key) => { | ||
this.overlayMaskNode.setAttribute(key, rest[key]); | ||
}); | ||
} | ||
|
||
componentDidMount() { | ||
document.body.classList.add('euiBody-hasOverlayMask'); | ||
document.body.appendChild(this.overlayMaskNode); | ||
} | ||
|
||
componentWillUnmount() { | ||
document.body.classList.remove('euiBody-hasOverlayMask'); | ||
|
||
document.body.removeChild(this.overlayMaskNode); | ||
this.overlayMaskNode = null; | ||
} | ||
|
||
render() { | ||
const { | ||
...rest | ||
} = this.props; | ||
|
||
return ( | ||
<div | ||
className="euiOverlayMask" | ||
{...rest} | ||
/> | ||
return createPortal( | ||
this.props.children, | ||
this.overlayMaskNode | ||
); | ||
} | ||
} | ||
|
||
EuiOverlayMask.propTypes = { | ||
className: PropTypes.string, | ||
children: PropTypes.node, | ||
}; |
This file was deleted.
Oops, something went wrong.