forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.ts
More file actions
28 lines (26 loc) · 884 Bytes
/
input.ts
File metadata and controls
28 lines (26 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export const noCorrect = {
autocapitalize: 'off',
autocomplete: 'off',
autocorrect: 'off',
spellcheck: 'false',
} as const
/**
* Check if an event target is an editable element (input, textarea, or contenteditable).
* Useful for keyboard shortcut handlers that should not trigger when the user is typing.
*/
export function isEditableElement(target: EventTarget | null): boolean {
if (!target || !(target instanceof HTMLElement)) return false
return target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable
}
/**
* Check if a keyboard event matches a specific key without any modifier keys.
*/
export function isKeyWithoutModifiers(event: KeyboardEvent, key: string): boolean {
return (
event.key?.toLowerCase() === key.toLowerCase() &&
!event.altKey &&
!event.ctrlKey &&
!event.metaKey &&
!event.shiftKey
)
}