Skip to content

Commit

Permalink
BUGFIX: Limit click-outside handling for dialogs to their semi-transp…
Browse files Browse the repository at this point in the history
…arent overlay
  • Loading branch information
grebaldi committed May 12, 2023
1 parent ef72c79 commit f7918ca
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/react-ui-components/src/Dialog/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import mergeClassNames from 'classnames';
import React, {PureComponent, ReactNode} from 'react';
import enhanceWithClickOutside from '../enhanceWithClickOutside/index';
import CloseOnEscape from 'react-close-on-escape';
import {Portal} from 'react-portal';

Expand Down Expand Up @@ -129,10 +128,6 @@ export class DialogWithoutEscape extends PureComponent<DialogProps> {
this.ref = ref;
}

public readonly handleClickOutside = () => {
this.props.onRequestClose();
}

public readonly componentDidMount = (): void => {
document.addEventListener('keydown', (event : KeyboardEvent) => this.handleKeyPress(event));
const {autoFocus} = this.props;
Expand All @@ -158,8 +153,6 @@ export class DialogWithoutEscape extends PureComponent<DialogProps> {
}
}

const EnhancedDialogWithoutEscapeWithClickOutside = enhanceWithClickOutside(DialogWithoutEscape);

// tslint:disable-next-line:max-classes-per-file
class DialogWithEscape extends PureComponent<DialogProps> {
public render(): JSX.Element | null {
Expand Down Expand Up @@ -198,8 +191,8 @@ class DialogWithEscape extends PureComponent<DialogProps> {
return (
<CloseOnEscape onEscape={this.onEscape}>
<Portal>
<section {...rest} className={sectionClassName} role="dialog" tabIndex={0}>
<EnhancedDialogWithoutEscapeWithClickOutside {...this.props}/>
<section {...rest} className={sectionClassName} role="dialog" tabIndex={0} onClick={this.handleOverlayClick}>
<DialogWithoutEscape {...this.props}/>
</section>
</Portal>
</CloseOnEscape>
Expand All @@ -209,6 +202,12 @@ class DialogWithEscape extends PureComponent<DialogProps> {
private readonly onEscape = () => {
this.props.onRequestClose();
}

private readonly handleOverlayClick = (ev: React.MouseEvent) => {
if (ev.target === ev.currentTarget) {
this.props.onRequestClose();
}
}
}

export default DialogWithEscape;

0 comments on commit f7918ca

Please sign in to comment.