Fixing Dialog Escape keypress behavior (#831)

* Replacing dialog keypress target

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding explanatory comments

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev authored and GitHub committed 2020-09-10 09:31:23 +03:00
1 parent 8d1f0efe80
commit e11cbc19fe
4 files changed
+6 -5

No files matched your search

+3 -2
View File
@@ -92,7 +92,8 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
this.props.onOpen();
if (!this.props.pinned) {
if (this.elem) this.elem.addEventListener('click', this.onClickOutside);
window.addEventListener('keydown', this.onEscapeKey);
// Using document.body target to handle keydown event before Drawer does
document.body.addEventListener('keydown', this.onEscapeKey);
}
}
@@ -100,7 +101,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
this.props.onClose();
if (!this.props.pinned) {
if (this.elem) this.elem.removeEventListener('click', this.onClickOutside);
window.removeEventListener('keydown', this.onEscapeKey);
document.body.removeEventListener('keydown', this.onEscapeKey);
}
}