From e745c41a6b173f51bb4d2fb6df2c48742a05f310 Mon Sep 17 00:00:00 2001 From: Nikita Barsukov Date: Wed, 24 Jun 2026 01:00:32 -0700 Subject: [PATCH] Add `selection` to `TextInputChangeEventData` in TypeScript types (#57249) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: The native `TextInput.onChange` event now emits `selection` data (cursor location) on both iOS and Android, added in [162627a](https://github.com/facebook/react-native/commit/162627af7c53e27433f39f82c4630baff0695bf1) (https://github.com/react/react-native/issues/55044). - https://github.com/react/react-native/pull/55044 The JS companion PR [c1f5445](https://github.com/facebook/react-native/commit/c1f5445f4a59d0035389725e47da58eb3d2c267c) (https://github.com/react/react-native/issues/55043) added the corresponding types, but only to two of the three TypeScript/Flow type sources: - https://github.com/react/react-native/pull/55043 | Type source | Has `selection`? | |---|---| | `TextInput.flow.js` (Flow) | ✅ | | `ReactNativeApi.d.ts` (generated API surface) | ✅ | | `TextInput.d.ts` (legacy public `.d.ts`) | ❌ | The hand-written legacy `TextInput.d.ts` was missed, so consumers relying on it can't access `selection` from the `onChange` event even though native genuinely sends it. This PR adds the optional `selection` field there so all three type sources agree. ## Changelog: [GENERAL] [ADDED] - Add `selection` to `TextInputChangeEventData` in TypeScript types Pull Request resolved: https://github.com/react/react-native/pull/57249 Test Plan: Type-only change. `selection` is now available and correctly typed on the `onChange` event: ```tsx { // e.nativeEvent.selection is now typed as { start: number; end: number } | undefined console.log(e.nativeEvent.selection?.start, e.nativeEvent.selection?.end); }} /> Reviewed By: christophpurrer Differential Revision: D109435915 Pulled By: fabriziocucci fbshipit-source-id: b334e52e0e39a7f9053bf41e93077be90b3d9adf --- .../Libraries/Components/TextInput/TextInput.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts b/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts index 97535f6cf82..9f3966bc7dc 100644 --- a/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts +++ b/packages/react-native/Libraries/Components/TextInput/TextInput.d.ts @@ -515,6 +515,12 @@ export type TextInputKeyPressEvent = export interface TextInputChangeEventData extends TargetedEvent { eventCount: number; text: string; + selection?: + | { + start: number; + end: number; + } + | undefined; } /**