Skip to content

🐛 Android: Cursor jumps to right when clearing centered TextInput #55457

Open

Description

@DevarajuluR

Description

When using a TextInput with textAlign: "center" on Android, clearing the input causes the cursor to move to the right end of the input instead of staying centered.

This does not happen on iOS — iOS behaves correctly.

This issue makes centered numeric or OTP-style inputs feel broken on Android.

Steps to reproduce

1)Render a TextInput with textAlign: "center"
2)Type any value
3)Clear the value (backspace or programmatically)
4)Observe cursor position

`import React, { useState } from "react";
import { View, TextInput, StyleSheet } from "react-native";

export default function App() {
const [value, setValue] = useState("");

return (



);
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
padding: 20,
},
input: {
borderWidth: 1,
height: 48,
fontSize: 18,
textAlign: "center",
},
});
`

React Native Version

0.83.0

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

N/A

Stacktrace or Logs

N/A

MANDATORY Reproducer

https://reactnative.dev/docs/textinput

Screenshots and Videos

TextAlign.issue.webm

Activity

  1. react-native-bot commented on Feb 6, 2026

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  2. DevarajuluR commented on Feb 7, 2026

    @DevarajuluR
    Author

    here is the reproducible snack
    Textinput issue

  3. ishaquehassan commented on Feb 27, 2026

    @ishaquehassan

    The bug is in maybeSetText() in ReactEditText.kt. When the incoming text has length 0, the code does: if (reactTextUpdate.text.length == 0) { text = null } This call to setText(null) resets the EditText state completely. The comment in the code explains why: on some devices, buggy keyboards don't clear their composing text when the content is programmatically cleared, so setting null forces the composing text to be dismissed. The side effect is that after setText(null), Android places the cursor at its default position, which for a centered EditText does not end up visually centered. Adding an explicit setSelection(0) after the text = null line should put the cursor back at the known empty position, which Android then renders in the center because the gravity is still CENTER_HORIZONTAL. The relevant section in ReactEditText.kt (around line 686) would become:

    if (reactTextUpdate.text.length == 0) {
        text = null
        setSelection(0)
    }

    This is safe because selectionStart and selectionEnd are both 0 on an empty string anyway. The existing maybeSetSelection() method could also be used here if the broader selection-state machinery needs to be informed.

  4. HarshitMadhav commented on Apr 26, 2026

    @HarshitMadhav
    Contributor

    Hi @ishaquehassan @DevarajuluR I have raised a fix for this PR here
    #56615

  5. added 2 commits that reference this issue on Apr 26, 2026
    d352c57
    712bf0b
  6. HarshitMadhav commented on May 26, 2026

    @HarshitMadhav
    Contributor

    @react-native-bot Please review this #56615 for this fix

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: TextInputRelated to the TextInput component.Needs: AttentionIssues where the author has responded to feedback.Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.Platform: AndroidAndroid applications.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions