Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event target checker for EuiOverlayMask's onClick prop #3462

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added `utcOffset` prop to `EuiSuperDatePicker` ([#3436](https://github.com/elastic/eui/pull/3436))
- Added `partition` key to `EuiChartThemeType` for Partition chart support ([#3387](https://github.com/elastic/eui/pull/3387))
- Updated `EuiImage`'s `caption` prop type from `string` to `ReactNode` ([#3387](https://github.com/elastic/eui/pull/3387))
- Added event target checker for `EuiOverlayMask`'s `onClick` prop ([#3462](https://github.com/elastic/eui/pull/3462))

**Bug Fixes**

Expand Down
8 changes: 4 additions & 4 deletions src-docs/src/views/modal/confirm_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default () => {

if (isModalVisible) {
modal = (
<EuiOverlayMask>
<EuiOverlayMask onClick={closeModal}>
<EuiConfirmModal
TAYTS marked this conversation as resolved.
Show resolved Hide resolved
title="Do this thing"
onCancel={closeModal}
Expand All @@ -52,7 +52,7 @@ export default () => {

if (isDestroyModalVisible) {
destroyModal = (
<EuiOverlayMask>
<EuiOverlayMask onClick={closeDestroyModal}>
<EuiConfirmModal
title="Do this destructive thing"
onCancel={closeDestroyModal}
Expand All @@ -72,7 +72,7 @@ export default () => {

if (isEmptyModalVisible) {
emptyModal = (
<EuiOverlayMask>
<EuiOverlayMask onClick={closeEmptyModal}>
<EuiConfirmModal
title="Do this thing"
onCancel={closeEmptyModal}
Expand All @@ -89,7 +89,7 @@ export default () => {

if (isButtonDisabledModalVisible) {
buttonDisabledModal = (
<EuiOverlayMask>
<EuiOverlayMask onClick={closeButtonDisabledModal}>
<EuiConfirmModal
title="My button is disabled"
onCancel={closeButtonDisabledModal}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default () => {

if (isModalVisible) {
modal = (
<EuiOverlayMask>
<EuiOverlayMask onClick={closeModal}>
TAYTS marked this conversation as resolved.
Show resolved Hide resolved
<EuiModal onClose={closeModal} initialFocus="[name=popswitch]">
<EuiModalHeader>
<EuiModalHeaderTitle>Modal title</EuiModalHeaderTitle>
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/modal/overflow_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default () => {

if (isModalVisible) {
modal = (
<EuiOverlayMask>
<EuiOverlayMask onClick={closeModal}>
<EuiModal onClose={closeModal}>
<EuiModalHeader>
<EuiModalHeaderTitle>Overflow test</EuiModalHeaderTitle>
Expand Down
9 changes: 8 additions & 1 deletion src/components/overlay_mask/overlay_mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ export class EuiOverlayMask extends Component<Props> {
this.overlayMaskNode = document.createElement('div');
this.overlayMaskNode.className = classNames('euiOverlayMask', className);
if (onClick) {
this.overlayMaskNode.addEventListener('click', onClick);
this.overlayMaskNode.addEventListener(
'click',
(e: React.MouseEvent | MouseEvent) => {
if (e.target === this.overlayMaskNode) {
onClick();
}
}
);
}
keysOf(rest).forEach(key => {
if (typeof rest[key] !== 'string') {
Expand Down