Skip to content

[iOS] Fabric: Only add selection of textinput payload when event is selectionChange#51051

Closed
zhongwuzw wants to merge 4 commits into
react:mainfrom
zhongwuzw:features/consolidate_textinput_change
Closed

[iOS] Fabric: Only add selection of textinput payload when event is selectionChange#51051
zhongwuzw wants to merge 4 commits into
react:mainfrom
zhongwuzw:features/consolidate_textinput_change

Conversation

@zhongwuzw

@zhongwuzw zhongwuzw commented May 1, 2025

Copy link
Copy Markdown
Contributor

Summary:

Fixes #51020: TextInputChangeEventData does not contain selection (see here). Additionally, Android does not have selection either (see here) (iOS old arch also not contains it). We can consolidate these to prevent any misleading information.

Changelog:

[IOS] [FIXED] - Fabric: Only add selection of textinput payload when event is selectionChange

Test Plan:

TextInput onChange's event should not contains selection.

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels May 1, 2025
@cortinico

Copy link
Copy Markdown
Contributor

cc @cipolleschi is this something you can import/review/merge?

@cipolleschi cipolleschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me.
I wonder how the types on JS get messed up like this.

To be fair, the selectionChange event doesn't have the text property either... and I don't know why the selectionChange event does not have the eventCount: number; that the textChanged has...

I'll import this and ask these questions to other people internally.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.


static jsi::Value textInputMetricsPayload(
jsi::Runtime& runtime,
const std::string& name,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some internal feedback: can we instead have something like includeSelectionState as a boolean to avoid the string comparison?

@zhongwuzw zhongwuzw requested a review from cipolleschi June 11, 2025 02:41
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @zhongwuzw in 3bfbaa8

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Jun 17, 2025
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cipolleschi merged this pull request in 3bfbaa8.

alanleedev added a commit to alanleedev/react-native that referenced this pull request Jan 6, 2026
Summary:

This change adds `selection` data to the `TextInput.onChange` event for both iOS and Android platforms.

NOTE: `selection` only represents the cursor location when returned via `onChange` as this will not be invoked on a pure selection change without text change. We should also add this note to the documentation.

## Why

On the web, text input elements provide `selectionStart` and `selectionEnd` properties that are always accessible during input events.

React Native's `onChange` event previously included `selection` on iOS (Fabric), but this was removed in PR [react#51051](react#51051) 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.

This is also to support pollyfill added in `react-strict-dom`; react/react-strict-dom#435


## What Changed

1. **iOS/macOS (C++)**: Enable selection in `onChange` event via `TextInputEventEmitter`
2. **Android (Kotlin)**: Added selection data to `ReactTextChangedEvent`

Changelog:
[General][Added] - TextInput onChange event now includes selection data (cursor location) on iOS and Android

Reviewed By: cipolleschi, javache

Differential Revision: D90123295
meta-codesync Bot pushed a commit that referenced this pull request Jan 6, 2026
Summary:
Pull Request resolved: #55044

This change adds `selection` data to the `TextInput.onChange` event for both iOS and Android platforms.

NOTE: `selection` only represents the cursor location when returned via `onChange` as this will not be invoked on a pure selection change without text change. We should also add this note to the documentation.

## Why

On the web, text input elements provide `selectionStart` and `selectionEnd` properties that are always accessible during input events.

React Native's `onChange` event previously included `selection` on iOS (Fabric), but this was removed in PR [#51051](#51051) 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.

This is also to support pollyfill added in `react-strict-dom`; react/react-strict-dom#435

## What Changed

1. **iOS/macOS (C++)**: Enable selection in `onChange` event via `TextInputEventEmitter`
2. **Android (Kotlin)**: Added selection data to `ReactTextChangedEvent`

Changelog:
[General][Added] - TextInput onChange event now includes selection data (cursor location) on iOS and Android

Reviewed By: cipolleschi, javache

Differential Revision: D90123295

fbshipit-source-id: 988ce4ce737e8b297313ade8bfaa2cbbfc9758cf
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. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text Input onChange TextInputChangeEventData native event returns selection data but the TS complains

5 participants