Skip to content

Commit

Permalink
OverlayMask onClick error (#261)
Browse files Browse the repository at this point in the history
* handle event handler properties

* attach onClick handler in less hacky way

* add onClick to propTypes, call removeEventListener in componentWillUnmount
  • Loading branch information
nreese authored Jan 4, 2018
1 parent d5c7c83 commit 84dadc5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/overlay_mask/overlay_mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class EuiOverlayMask extends Component {
const {
className,
children, // eslint-disable-line no-unused-vars
onClick,
...rest
} = this.props;

Expand All @@ -23,7 +24,13 @@ export class EuiOverlayMask extends Component {
'euiOverlayMask',
className
);
if (onClick) {
this.overlayMaskNode.addEventListener('click', onClick);
}
Object.keys(rest).forEach((key) => {
if (typeof rest[key] !== 'string') {
throw new Error(`Unhandled property type. EuiOverlayMask property ${key} is not a string.`);
}
this.overlayMaskNode.setAttribute(key, rest[key]);
});
}
Expand All @@ -36,6 +43,9 @@ export class EuiOverlayMask extends Component {
componentWillUnmount() {
document.body.classList.remove('euiBody-hasOverlayMask');

if (this.props.onClick) {
this.overlayMaskNode.removeEventListener('click', this.props.onClick);
}
document.body.removeChild(this.overlayMaskNode);
this.overlayMaskNode = null;
}
Expand All @@ -51,4 +61,5 @@ export class EuiOverlayMask extends Component {
EuiOverlayMask.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
onClick: PropTypes.func,
};

0 comments on commit 84dadc5

Please sign in to comment.