-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextInput cursor not aligned in the centre when value is empty #27658
Comments
It looks like you are using an older version of React Native. Please update to the latest release, v0.61 and verify if the issue still exists. The "Resolution: Old Version" label will be removed automatically once you edit your original post with the results of running `react-native info` on a project using the latest release.
|
The same issue. I use the latest version v0.61.5 |
same issue, any update ? |
Same issue on the latest version. It happens for me when using textAlign and value parameter to control what user can submit. |
It still exists. tricks is use a space instead an empty string, imperfect but better the present |
Same for me |
Im also stuck with this issue, in the latest version |
Same here on v0.62.2 |
Im using in the following way and it works: <TextInput
style={[
{
textAlign: 'center',
flex: 1,
},
]}
/> i hope it helps |
Same issue here Is there any progress on this? |
It's been 6 months what Facebook's React native team is doing ? Why can't you fix such a minor issue ? Maybe it's not big of a deal for you but for many people it is. |
I have the same issue here in Android, textAlign aligns in the center with flex: 1 (in the middle of placeholder string). Should be aligned with the placeholder first char. In iOS it is working fine like this. 0.61 version. |
@fabriziobertoglio1987 how will we test it ? I am new to this so .. sorry 😅 |
@ShivamJoker You either clone my branch https://github.com/fabriziobertoglio1987/react-native/tree/fix-text-input-cursor-jump and test it in the RNTester App Or even better, if you also want to fix this issue in your React Native project. and install in your project that version of react native as explained in the instructions here otherwise wait for the latest release and support me 😃 |
Seems to be an issue since 2016 with it being classified as desired behaviour #10030. Would really like it fixed so it matches with ios and normal web behaviour |
Thanks @fabriziobertoglio1987 I have tested your changes and it works perfect, hope they merge this soon |
here is full component code with cursor centered in TextInput. react natiive v0.61
|
Ohh... When will this be fixed ? |
Any update about fix? |
Same in 0.63.2 |
I had to remove the placeholder when the input is focused to center the cursor, maybe adding a label to the input when is focused could help to improve the UX with this workaround. |
Same issue in 0.62.2 |
+1, still a thing for now. |
Still an issue in 0.63.4 |
Still an issue in 0.64.2 |
any solution to this ? I am facing on "react-native": "0.64.2", |
I have same issue too.
|
Guys please upgrade to the latest react native version, the changes are included in I've not tested it in this but I believe it should work. |
I have solved it by wrapping textInput in with justify content/alignitem:'center' |
Can you share the JSX and StyleSheet code with React Native version? |
Sorry. This commit was not cherry picked in 0.65.1 react-native-community/releases#244 Upgrading will not fix this issue |
Oh no, why not ? What was issue with including it ? I mean it's been 2 years why they can't just merge this and release. |
Maybe because was merged to master 14 days ago. May require some testing before making a release. Hopefully we will see this fix soon in an upcoming release. Thanks for the support 🙏 |
I have managed by this: ` // styling |
+1 |
1 similar comment
+1 |
here is my solution
styles
|
this issue still occurs |
still happening with me |
still |
I was getting this issue only on iOS (RN 0.63.4). For some reason the previous developer had the following: |
Thanks for the idea @mrjackwhitaker This is a workaround if you still need a placeholder with textAlign='center'
Hope this help someone. |
Right, as someone that just hit this bug, just adding a wrapper that centers a TextInput with a dynamic width wasn't good enough. The caret would still appear at the end of the smaller TextInput when the placeholder was showing, and this approach would also reduce the touchable area (horizontally) that the user can press to focus the TextInput. I have managed to find a dodgy hackaround that will fix it (or rather make it appear to be fixed). You do want the wrapper element around your TextInput styled like so:
Then for your TextInput, you want to change the width depending on whether there is a value or not, so as to trigger a redraw of the element, and a recalculation of the caret position:
This will result in the behaviour appearing as you'd expect - the caret remains centered regardless of placeholder text, but the TextInput is still nice and wide to allow for touches at the edges. |
this works fine you can also use number of line. For I wanted one line text so I used |
Is there a reason this issue is closed? on android text align center with a placeholder still puts the cursor at the end. |
Still an issue |
+1 Still an issue As mentioned above, a workaround is:
|
When using TextInput with
textAlign: center
, the cursor is in the wrong position when the text is empty. It seems to be aligning with the placeholder.React Native version:
Steps To Reproduce
Expected Behaviour
The cursor should be in the middle of text input
The text was updated successfully, but these errors were encountered: