Commit 8a7ce55
Add selection to TextInput onChange event
Summary:
This change adds `selection` data to the `TextInput.onChange` event for both iOS and Android platforms.
## Why
On the web, text input elements provide `selectionStart` and `selectionEnd` properties that are always accessible during input events. This is a W3C DOM standard that enables common use cases like:
- mention and tagging systems (insert at cursor position)
- Autocomplete/typeahead (replace text at cursor)
- Input masking (format text while maintaining cursor position)
- Rich text editing features
React Native's `onChange` event previously included `selection` on iOS (Fabric), but this was removed in D76253999 to unify with Android (which never had it). This change restores and extends this capability to both platforms, better aligning React Native with web standards.
## What Changed
1. **Flow Types**: Added optional `selection?: Selection` to `TextInputChangeEventData`
2. **iOS/macOS (C++)**: Enable selection in `onChange` event via `TextInputEventEmitter`
3. **Android (Kotlin)**: Added selection data to `ReactTextChangedEvent`
4. **RNTester**: Updated examples to verify the change
## Changelog
[General][Added] - TextInput onChange event now includes selection data on iOS and Android
Differential Revision: D898980921 parent fef5b84 commit 8a7ce55
File tree
6 files changed
+25
-6
lines changed- packages
- react-native
- Libraries/Components/TextInput
- ReactAndroid/src/main/java/com/facebook/react/views/textinput
- ReactCommon/react/renderer/components/textinput
- rn-tester/js/examples/TextInput
6 files changed
+25
-6
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
28 | 36 | | |
29 | 37 | | |
30 | 38 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
5277 | 5277 | | |
5278 | 5278 | | |
5279 | 5279 | | |
| 5280 | + | |
5280 | 5281 | | |
5281 | 5282 | | |
5282 | 5283 | | |
| |||
6189 | 6190 | | |
6190 | 6191 | | |
6191 | 6192 | | |
6192 | | - | |
| 6193 | + | |
6193 | 6194 | | |
6194 | | - | |
| 6195 | + | |
6195 | 6196 | | |
6196 | 6197 | | |
6197 | 6198 | | |
6198 | 6199 | | |
6199 | 6200 | | |
6200 | | - | |
| 6201 | + | |
6201 | 6202 | | |
6202 | 6203 | | |
6203 | 6204 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
397 | 404 | | |
398 | 405 | | |
399 | 406 | | |
| |||
0 commit comments