Skip to content

Polyfill setSelectionRange, selectionStart, selectionEnd#435

Merged
necolas merged 3 commits into
mainfrom
native/setSelectionRange
Dec 10, 2025
Merged

Polyfill setSelectionRange, selectionStart, selectionEnd#435
necolas merged 3 commits into
mainfrom
native/setSelectionRange

Conversation

@necolas

@necolas necolas commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Polyfill imperative selection APIs for input and textarea components

@meta-cla meta-cla Bot added the cla signed label Dec 8, 2025
@github-actions

github-actions Bot commented Dec 8, 2025

Copy link
Copy Markdown

workflow: benchmarks/size

Comparison of minified (terser) and compressed (brotli) size results, measured in bytes. Smaller is better.

Results Base Patch Ratio
react-strict-dom/dist/web/index.js
· compressed 3,251 3,251 1.00
· minified 10,375 10,375 1.00
react-strict-dom/dist/web/runtime.js
· compressed 1,645 1,645 1.00
· minified 4,131 4,131 1.00
react-strict-dom/dist/native/index.js
· compressed 16,232 16,528 1.02 +
· minified 62,962 64,084 1.02 +

@github-actions

github-actions Bot commented Dec 8, 2025

Copy link
Copy Markdown

workflow: benchmarks/perf (native)

Comparison of performance test results, measured in operations per second. Larger is better.

Results Base Patch Ratio
css.create
· small 1,138,303 1,128,658 0.99 -
· small with units 494,059 487,319 0.99 -
· small with variables 663,421 674,633 1.02 +
· several small 351,837 347,182 0.99 -
· large 198,860 199,295 1.00 +
· large with polyfills 147,504 148,970 1.01 +
· complex 103,443 103,277 1.00 -
· unsupported 210,178 211,000 1.00 +
css.createTheme
· simple theme 227,241 228,454 1.01 +
· polyfill theme 213,062 214,347 1.01 +

@necolas necolas force-pushed the native/setSelectionRange branch from 67437ee to 6be3ae2 Compare December 9, 2025 03:19
Polyfill imperative selection APIs for input and textarea components
Not all native platforms implement this part of React Native.
`Values` is a reserved type name
@necolas necolas force-pushed the native/setSelectionRange branch from 6be3ae2 to e76ca4c Compare December 9, 2025 22:12
@necolas necolas merged commit 1205696 into main Dec 10, 2025
7 checks passed
@necolas necolas deleted the native/setSelectionRange branch December 10, 2025 20:30
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 to react/react-native 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant