mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-08-30 01:38:55 +00:00
35 lines
782 B
TypeScript
35 lines
782 B
TypeScript
const nonTextInputTypes = new Set([
|
|
'button',
|
|
'checkbox',
|
|
'color',
|
|
'file',
|
|
'hidden',
|
|
'image',
|
|
'radio',
|
|
'range',
|
|
'reset',
|
|
'submit',
|
|
])
|
|
|
|
type FocusableElement = Pick<
|
|
HTMLElement,
|
|
'getAttribute' | 'isContentEditable' | 'tagName'
|
|
>
|
|
|
|
export function isTextInputElement(element: FocusableElement): boolean {
|
|
if (
|
|
element.getAttribute('readonly') !== null ||
|
|
element.getAttribute('aria-readonly') === 'true'
|
|
) {
|
|
return false
|
|
}
|
|
if (element.isContentEditable || element.getAttribute('role') === 'textbox') {
|
|
return true
|
|
}
|
|
if (element.tagName === 'TEXTAREA') return true
|
|
if (element.tagName !== 'INPUT') return false
|
|
|
|
const inputType = element.getAttribute('type')?.toLowerCase() ?? 'text'
|
|
return !nonTextInputTypes.has(inputType)
|
|
}
|