Skip to content

Conversation

@alanleedev
Copy link
Contributor

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: D89898092

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: D89898092
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 29, 2025
@meta-codesync
Copy link

meta-codesync bot commented Dec 29, 2025

@alanleedev has exported this pull request. If you are a Meta employee, you can view the originating Diff in D89898092.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

2 participants