Skip to content

Commit e745c41

Browse files
nsbarsukovmeta-codesync[bot]
authored andcommitted
Add selection to TextInputChangeEventData in TypeScript types (#57249)
Summary: The native `TextInput.onChange` event now emits `selection` data (cursor location) on both iOS and Android, added in [162627a](162627a) (#55044). - #55044 The JS companion PR [c1f5445](c1f5445) (#55043) added the corresponding types, but only to two of the three TypeScript/Flow type sources: - #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: #57249 Test Plan: Type-only change. `selection` is now available and correctly typed on the `onChange` event: ```tsx <TextInput onChange={e => { // 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
1 parent 5c197fb commit e745c41

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

packages/react-native/Libraries/Components/TextInput/TextInput.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ export type TextInputKeyPressEvent =
515515
export interface TextInputChangeEventData extends TargetedEvent {
516516
eventCount: number;
517517
text: string;
518+
selection?:
519+
| {
520+
start: number;
521+
end: number;
522+
}
523+
| undefined;
518524
}
519525

520526
/**

0 commit comments

Comments
 (0)