From 74d6b39c9883810bcaa6f411b0992e8930e958fd Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Tue, 29 Aug 2023 14:52:49 +0200 Subject: [PATCH 1/3] [TS migration] Migrate 'DomUtils' lib to TypeScript --- src/libs/DomUtils/index.js | 12 ------------ src/libs/DomUtils/index.native.js | 10 ---------- src/libs/DomUtils/index.native.ts | 10 ++++++++++ src/libs/DomUtils/index.ts | 16 ++++++++++++++++ src/libs/DomUtils/types.ts | 4 ++++ 5 files changed, 30 insertions(+), 22 deletions(-) delete mode 100644 src/libs/DomUtils/index.js delete mode 100644 src/libs/DomUtils/index.native.js create mode 100644 src/libs/DomUtils/index.native.ts create mode 100644 src/libs/DomUtils/index.ts create mode 100644 src/libs/DomUtils/types.ts 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..cda38b2a5131 --- /dev/null +++ b/src/libs/DomUtils/index.native.ts @@ -0,0 +1,10 @@ +import {BlurActiveElement, GetActiveElement} from './types'; + +const blurActiveElement: BlurActiveElement = () => {}; + +const getActiveElement: GetActiveElement = () => undefined; + +export default { + blurActiveElement, + getActiveElement, +}; diff --git a/src/libs/DomUtils/index.ts b/src/libs/DomUtils/index.ts new file mode 100644 index 000000000000..4215d93bab76 --- /dev/null +++ b/src/libs/DomUtils/index.ts @@ -0,0 +1,16 @@ +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..fb1eff84749e --- /dev/null +++ b/src/libs/DomUtils/types.ts @@ -0,0 +1,4 @@ +type BlurActiveElement = () => void; +type GetActiveElement = () => Element | null | undefined; + +export type {BlurActiveElement, GetActiveElement}; From d61fe7b0d233f53ef4ec8d8fd0621512131ed7bc Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Mon, 11 Sep 2023 09:47:22 +0200 Subject: [PATCH 2/3] Remove undefined from GetActiveElement type --- src/libs/DomUtils/index.native.ts | 2 +- src/libs/DomUtils/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/DomUtils/index.native.ts b/src/libs/DomUtils/index.native.ts index cda38b2a5131..d3774baec208 100644 --- a/src/libs/DomUtils/index.native.ts +++ b/src/libs/DomUtils/index.native.ts @@ -2,7 +2,7 @@ import {BlurActiveElement, GetActiveElement} from './types'; const blurActiveElement: BlurActiveElement = () => {}; -const getActiveElement: GetActiveElement = () => undefined; +const getActiveElement: GetActiveElement = () => null; export default { blurActiveElement, diff --git a/src/libs/DomUtils/types.ts b/src/libs/DomUtils/types.ts index fb1eff84749e..8be7b3cddae5 100644 --- a/src/libs/DomUtils/types.ts +++ b/src/libs/DomUtils/types.ts @@ -1,4 +1,4 @@ type BlurActiveElement = () => void; -type GetActiveElement = () => Element | null | undefined; +type GetActiveElement = () => Element | null; export type {BlurActiveElement, GetActiveElement}; From 3efa2849a16f698636677e6f440e6e8dcf823736 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Mon, 11 Sep 2023 09:48:33 +0200 Subject: [PATCH 3/3] Change return syntax --- src/libs/DomUtils/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/DomUtils/index.ts b/src/libs/DomUtils/index.ts index 4215d93bab76..784a01bd7885 100644 --- a/src/libs/DomUtils/index.ts +++ b/src/libs/DomUtils/index.ts @@ -3,7 +3,9 @@ import {BlurActiveElement, GetActiveElement} from './types'; const blurActiveElement: BlurActiveElement = () => { const activeElement = document.activeElement as HTMLElement; - if (!activeElement?.blur) return; + if (!activeElement?.blur) { + return; + } activeElement.blur(); };