diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 6ddeeb9eda..6e8126e3aa 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -1095,6 +1095,17 @@ export interface TextInputScrollEventData { contentOffset: { x: number; y: number; } } +/** + * @see TextInputProps.onSelectionChange + */ +export interface TextInputSelectionChangeEventData { + selection: { + start: number; + end: number; + }; + target: number; +} + /** * @see https://facebook.github.io/react-native/docs/textinput.html#props */ @@ -1220,7 +1231,7 @@ export interface TextInputProps /** * Callback that is called when the text input selection is changed. */ - onSelectionChange?: (event: { nativeEvent: { selection: { start: number; end: number }; target: number } }) => void; + onSelectionChange?: (e: NativeSyntheticEvent) => void; /** * Callback that is called when the text input's submit button is pressed. diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 36e85698fa..8ff7ceacdb 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -56,7 +56,8 @@ import { StatusBar, NativeSyntheticEvent, GestureResponderEvent, - TextInputScrollEventData + TextInputScrollEventData, + TextInputSelectionChangeEventData, } from "react-native"; declare module "react-native" { @@ -492,6 +493,14 @@ class TextInputTest extends React.Component<{}, {username: string}> { testNativeSyntheticEvent(e); } + handleOnSelectionChange = (e: NativeSyntheticEvent) => { + testNativeSyntheticEvent(e); + + console.log(`target: ${ e.nativeEvent.target }`); + console.log(`start: ${ e.nativeEvent.selection.start }`); + console.log(`end: ${ e.nativeEvent.selection.end }`); + } + render() { return ( @@ -503,7 +512,7 @@ class TextInputTest extends React.Component<{}, {username: string}> { onChangeText={this.handleUsernameChange} /> - @@ -512,6 +521,10 @@ class TextInputTest extends React.Component<{}, {username: string}> { onBlur={this.handleOnBlur} onFocus={this.handleOnFocus} /> + + ); }