diff --git a/src/libs/DomUtils/index.js b/src/libs/DomUtils/index.js deleted file mode 100644 index ad636c6167fb..000000000000 --- a/src/libs/DomUtils/index.js +++ /dev/null @@ -1,12 +0,0 @@ -function blurActiveElement() { - document.activeElement.blur(); -} - -function getActiveElement() { - return document.activeElement; -} - -export default { - blurActiveElement, - getActiveElement, -}; diff --git a/src/libs/DomUtils/index.native.js b/src/libs/DomUtils/index.native.js deleted file mode 100644 index 1d3ef14c954d..000000000000 --- a/src/libs/DomUtils/index.native.js +++ /dev/null @@ -1,10 +0,0 @@ -function blurActiveElement() {} - -function getActiveElement() { - return undefined; -} - -export default { - blurActiveElement, - getActiveElement, -}; diff --git a/src/libs/DomUtils/index.native.ts b/src/libs/DomUtils/index.native.ts new file mode 100644 index 000000000000..d3774baec208 --- /dev/null +++ b/src/libs/DomUtils/index.native.ts @@ -0,0 +1,10 @@ +import {BlurActiveElement, GetActiveElement} from './types'; + +const blurActiveElement: BlurActiveElement = () => {}; + +const getActiveElement: GetActiveElement = () => null; + +export default { + blurActiveElement, + getActiveElement, +}; diff --git a/src/libs/DomUtils/index.ts b/src/libs/DomUtils/index.ts new file mode 100644 index 000000000000..784a01bd7885 --- /dev/null +++ b/src/libs/DomUtils/index.ts @@ -0,0 +1,18 @@ +import {BlurActiveElement, GetActiveElement} from './types'; + +const blurActiveElement: BlurActiveElement = () => { + const activeElement = document.activeElement as HTMLElement; + + if (!activeElement?.blur) { + return; + } + + activeElement.blur(); +}; + +const getActiveElement: GetActiveElement = () => document.activeElement; + +export default { + blurActiveElement, + getActiveElement, +}; diff --git a/src/libs/DomUtils/types.ts b/src/libs/DomUtils/types.ts new file mode 100644 index 000000000000..8be7b3cddae5 --- /dev/null +++ b/src/libs/DomUtils/types.ts @@ -0,0 +1,4 @@ +type BlurActiveElement = () => void; +type GetActiveElement = () => Element | null; + +export type {BlurActiveElement, GetActiveElement};