Skip to content

fix(TextInput): report correct selection after autofill on Android - #57809

Open
stareezy-1 wants to merge 1 commit into
react:mainfrom
stareezy-1:fix/textinput-autofill-selection
Open

fix(TextInput): report correct selection after autofill on Android#57809
stareezy-1 wants to merge 1 commit into
react:mainfrom
stareezy-1:fix/textinput-autofill-selection

Conversation

@stareezy-1

Copy link
Copy Markdown

Summary

Fixes the onChange event reporting selection: {start: 0, end: 0} instead of the actual cursor position when text is filled via Android's system autofill.

Fixes #57458

Changelog:

[ANDROID] [FIXED] - TextInput onChange now reports correct selection after system autofill

Problem

ReactTextInputTextWatcher.onTextChanged dispatches the onChange event with editText.selectionStart/End. During autofill, Android sets the text before updating the cursor position — so at onTextChanged time, the selection is still at {0, 0}.

Paste and keyboard input work correctly because Android updates their selection synchronously before the TextWatcher callbacks.

Solution

Moved the event dispatch (state update + ReactTextChangedEvent) from onTextChanged to afterTextChanged. By that point the Editable is fully committed and Android has updated the selection to reflect the actual cursor position.

The change detection logic stays in onTextChanged (where it has access to the start/before/count parameters) and sets a flag that afterTextChanged checks before dispatching.

Test Plan

  • Android autofill: onChange now reports selection: {start: N, end: N} where N = text length
  • Keyboard input: selection still correct (unchanged behavior)
  • Paste: selection still correct (unchanged behavior)
  • Controlled TextInput: state updates still fire correctly

Move the onChange event dispatch from onTextChanged to afterTextChanged.

During system autofill, Android sets the text content before updating the
cursor position. When onTextChanged fires, editText.selectionStart/End
still report {0, 0} from the initial empty state. By the time
afterTextChanged runs, the Editable is fully committed and Android has
updated the selection to reflect the actual cursor position.

This fixes the regression where autofill produces
selection: {start: 0, end: 0} instead of the correct position at the
end of the inserted text. Paste and keyboard input are unaffected since
Android updates their selection synchronously before the TextWatcher
callbacks.

Fixes react#57458
@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 Aug 4, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 4, 2026
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. 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.

TextInput emits onChange event with invalid selection on Android browser autofill

1 participant