lbry-desktop/ui/util/detect-typing.js

14 lines
355 B
JavaScript
Raw Normal View History

// A simple function to detect if a user is typing:
2019-10-13 19:41:51 +02:00
// useful when handling shortcut keys.
2019-08-02 08:28:14 +02:00
export default function isUserTyping() {
const activeElement = document.activeElement;
if (activeElement) {
const elementType = activeElement.tagName.toLowerCase();
return elementType === 'input' || elementType === 'textarea';
}
return false;
}