β¬ οΈ Back to Table of Contents
π onStartTyping¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 4 |
| π¦ Imports | 3 |
| π Interfaces | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/core/onStartTyping/index.ts
π¦ Imports¶
| Name | Source |
|---|---|
ConfigurableDocument |
../_configurable |
defaultDocument |
../_configurable |
useEventListener |
../useEventListener |
Functions¶
isFocusedElementEditable(): boolean¶
Returns: boolean
Calls:
activeElement.hasAttribute
Internal Comments:
// If not element has focus, we assume it is not editable, too.
// Assume <input> and <textarea> elements are editable.
// Check if any other focused element id editable.
Code
export function isFocusedElementEditable(): boolean {
const { activeElement, body } = document
if (!activeElement)
return false
// If not element has focus, we assume it is not editable, too.
if (activeElement === body)
return false
// Assume <input> and <textarea> elements are editable.
switch (activeElement.tagName) {
case 'INPUT':
case 'TEXTAREA':
return true
}
// Check if any other focused element id editable.
return activeElement.hasAttribute('contenteditable')
}
isTypedCharValid({ keyCode, metaKey, ctrlKey, alβ¦: KeyboardEvent): boolean¶
Parameters:
{ keyCode, metaKey, ctrlKey, altKey, }KeyboardEvent
Returns: boolean
Internal Comments:
Code
export function isTypedCharValid({
keyCode,
metaKey,
ctrlKey,
altKey,
}: KeyboardEvent): boolean {
if (metaKey || ctrlKey || altKey)
return false
// 0...9
if ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 96 && keyCode <= 105))
return true
// A...Z
if (keyCode >= 65 && keyCode <= 90)
return true
// All other keys.
return false
}
onStartTyping(callback: (event: KeyboardEvent) => void, options: OnStartTypingOptions): void¶
Fires when users start typing on non-editable elements.
Parameters:
callbackany: No descriptionoptionsany: No description
See: https://vueuse.org/onStartTyping
Raw JSDoc
Calls:
isFocusedElementEditableFnisTypedCharValidFncallbackuseEventListener (from ../useEventListener)
Code
export function onStartTyping(callback: (event: KeyboardEvent) => void, options: OnStartTypingOptions = {}) {
const { document = defaultDocument, isTypedCharValid: isTypedCharValidFn = isTypedCharValid, isFocusedElementEditable: isFocusedElementEditableFn = isFocusedElementEditable } = options
const keydown = (event: KeyboardEvent) => {
if (!isFocusedElementEditableFn() && isTypedCharValidFn(event)) {
callback(event)
}
}
if (document)
useEventListener(document, 'keydown', keydown, { passive: true })
}
Internal helpers¶
Declared inside another function in this file.
keydown(event: KeyboardEvent): void¶
Parameters:
eventKeyboardEvent
Returns: void
Calls:
isFocusedElementEditableFnisTypedCharValidFncallback
Code
Interfaces¶
OnStartTypingOptions¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
isTypedCharValid |
(event: KeyboardEvent) => boolean |
β | not shown |
isFocusedElementEditable |
() => boolean |
β | not shown |
Generated by Syntax Scribe