mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
18 lines
573 B
TypeScript
18 lines
573 B
TypeScript
|
|
export function isTextInputFocused(doc: Document): boolean {
|
|
const activeElement = doc.activeElement;
|
|
if (isTextInput(activeElement) && activeElement.parentElement) {
|
|
return activeElement.parentElement.querySelector(':focus') === activeElement;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
const NON_TEXT_INPUT_REGEX = /^(radio|checkbox|range|file|submit|reset|color|image|button)$/i;
|
|
|
|
function isTextInput(el: any) {
|
|
return !!el &&
|
|
(el.tagName === 'TEXTAREA'
|
|
|| el.contentEditable === 'true'
|
|
|| (el.tagName === 'INPUT' && !(NON_TEXT_INPUT_REGEX.test(el.type))));
|
|
}
|