Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
refacored code so the handleKey function is called after pressing the key
  • Loading branch information
agmes4 committed Jan 27, 2024
1 parent e59809c commit 3038941
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions web/resources/js/user-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
* the Apache License, Version 2.0. See the LICENSE file for details
*/

function waitForKeyPress(callback: (event: KeyboardEvent) => void): void {
const handleKeyPress = (event: KeyboardEvent) => {
// Call the callback function with the event when a key is pressed
callback(event);
};

// Add the event listener to the document
document.addEventListener('keydown', handleKeyPress);
}

waitForKeyPress((event) => {
function handleKeyPress(event: KeyboardEvent) {
// checks rather the input was triggered in a text area then it is dismissed
if(event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) return;

Expand All @@ -40,4 +30,7 @@ waitForKeyPress((event) => {
}
}
}
});
}

document.addEventListener('keydown', handleKeyPress);

0 comments on commit 3038941

Please sign in to comment.