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

[Dialog]correct behavior of esc-click for nested dialogs #4330

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ function getStyles(props, context) {
};
}

let topDialog = null; // record the top dialog that should be closed when ESC clicked.

class DialogInline extends Component {
static propTypes = {
actions: PropTypes.node,
Expand Down Expand Up @@ -249,9 +251,17 @@ class DialogInline extends Component {
this.requestClose(false);
};

handleKeyDown = (event) => {
if (keycode(event) === 'esc') {
topDialog = this;
}
};

handleKeyUp = (event) => {
if (keycode(event) === 'esc') {
this.requestClose(false);
if (topDialog === this) {
this.requestClose(false);
}
}
};

Expand Down Expand Up @@ -314,6 +324,7 @@ class DialogInline extends Component {
{open &&
<EventListener
target="window"
onKeyDown={this.handleKeyDown}
onKeyUp={this.handleKeyUp}
onResize={this.handleResize}
/>
Expand Down