diff --git a/src/libs/setSelection/index.js b/src/libs/setSelection/index.js deleted file mode 100644 index c7f24ae4a199..000000000000 --- a/src/libs/setSelection/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function setSelection(textInput, start, end) { - if (!textInput) { - return; - } - - textInput.setSelectionRange(start, end); -} diff --git a/src/libs/setSelection/index.native.js b/src/libs/setSelection/index.native.js deleted file mode 100644 index 02d812d84cd4..000000000000 --- a/src/libs/setSelection/index.native.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function setSelection(textInput, start, end) { - if (!textInput) { - return; - } - - textInput.setSelection(start, end); -} diff --git a/src/libs/setSelection/index.native.ts b/src/libs/setSelection/index.native.ts new file mode 100644 index 000000000000..e27cd4e58bd7 --- /dev/null +++ b/src/libs/setSelection/index.native.ts @@ -0,0 +1,13 @@ +import SetSelection from './types'; + +const setSelection: SetSelection = (textInput, start, end) => { + if (!textInput) { + return; + } + + if ('setSelection' in textInput) { + textInput.setSelection(start, end); + } +}; + +export default setSelection; diff --git a/src/libs/setSelection/index.ts b/src/libs/setSelection/index.ts new file mode 100644 index 000000000000..5eee88881924 --- /dev/null +++ b/src/libs/setSelection/index.ts @@ -0,0 +1,13 @@ +import SetSelection from './types'; + +const setSelection: SetSelection = (textInput, start, end) => { + if (!textInput) { + return; + } + + if ('setSelectionRange' in textInput) { + textInput.setSelectionRange(start, end); + } +}; + +export default setSelection; diff --git a/src/libs/setSelection/types.ts b/src/libs/setSelection/types.ts new file mode 100644 index 000000000000..f2717079725f --- /dev/null +++ b/src/libs/setSelection/types.ts @@ -0,0 +1,5 @@ +import {TextInput} from 'react-native'; + +type SetSelection = (textInput: TextInput | HTMLInputElement, start: number, end: number) => void; + +export default SetSelection; diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts new file mode 100644 index 000000000000..1b0b39e5f67d --- /dev/null +++ b/src/types/modules/react-native.d.ts @@ -0,0 +1,9 @@ +/* eslint-disable @typescript-eslint/consistent-type-definitions */ +import 'react-native'; + +declare module 'react-native' { + interface TextInput { + // Typescript type declaration is missing in React Native for setting text selection. + setSelection: (start: number, end: number) => void; + } +}