madiator.com/ui/util/detect-typing.js

14 lines
355 B
JavaScript
Raw Normal View History

2021-08-16 12:11:25 +02:00
// 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;
}