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
42 lines (38 loc) · 1.45 KB
/
input.ts
File metadata and controls
42 lines (38 loc) · 1.45 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
)
}
export const DATE_INPUT_MAX = '9999-12-31'
/** Attributes to prevent password managers from recognizing an input as a password field. */
export const noPasswordManager = {
/* ProtonPass, https://stackoverflow.com/a/51272839 */
['data-protonpass-ignore']: 'true',
/* LastPass, https://stackoverflow.com/a/51272839 */
['data-lpignore']: 'true',
/* 1Password, https://stackoverflow.com/a/51272839 */
['data-1p-ignore']: 'true',
/* Bitwarden, https://stackoverflow.com/questions/41945535/html-disable-password-manager#comment139327111_51272839 */
['data-bwignore']: 'true',
} as const