fix: Reject keyboard shortcut listeners if input box is active (#3019)

Reject keyboard shortcut listeners if input box is active
This commit is contained in:
Pranav Raj S
2021-09-15 20:15:06 +05:30
committed by GitHub
parent a14f4ede87
commit 3abcadb5cb
7 changed files with 84 additions and 37 deletions

View File

@@ -1,8 +1,28 @@
import { isEscape } from '../helpers/KeyboardHelpers';
export default {
mounted() {
document.addEventListener('keydown', this.handleKeyEvents);
document.addEventListener('keydown', this.onKeyDownHandler);
},
destroyed() {
document.removeEventListener('keydown', this.handleKeyEvents);
beforeDestroy() {
document.removeEventListener('keydown', this.onKeyDownHandler);
},
methods: {
onKeyDownHandler(e) {
const isEventFromAnInputBox =
e.target?.tagName === 'INPUT' || e.target?.tagName === 'TEXTAREA';
const isEventFromProseMirror = e.target?.className?.includes(
'ProseMirror'
);
if (isEventFromAnInputBox || isEventFromProseMirror) {
if (isEscape(e)) {
e.target.blur();
}
return;
}
this.handleKeyEvents(e);
},
},
};