madiator.com/ui/util/detect-typing.js
2021-08-16 12:11:25 +02:00

14 lines
355 B
JavaScript

// A simple function to detect if a user is typing:
// useful when handling shortcut keys.
export default function isUserTyping() {
const activeElement = document.activeElement;
if (activeElement) {
const elementType = activeElement.tagName.toLowerCase();
return elementType === 'input' || elementType === 'textarea';
}
return false;
}