react-native: Using `toUpperCase` or `textTransform: 'uppercase'` breaks on an Android controlled TextInput
React Native version: 0.61.4 and lower
Trying to force capitalization of characters inside a TextInput is broken on Android.
autoCapitalize="characters"
doesn’t seem to do anything- Using
toUpperCase
in the onChangeText hook causes duplication of letters - Using
textTransform: 'uppercase'
in styles block causes the same duplication of letters - Using
textTransform: 'uppercase'
in a non-controlled TextInput does nothing
Steps To Reproduce
- Create a controlled TextInput and either use onTextChanged to modify the text to uppercase or use text transform in the styles block
- Type multiple lowercase characters into the text box
Describe what you expected to happen: Characters should be capitalized
What actually happens: Characters are capitalized and duplicated
Snack, code example, screenshot, or link to a repository: https://snack.expo.io/@nmi09/rn-android-capitalize-input-bug
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 33
- Comments: 36 (6 by maintainers)
keyboardType={Platform.OS === 'ios' ? 'default' : 'visible-password'}
Seems to be the only workaround for me with Android at the moment (I’ve been looking for ages!). Will need some cross platform testing locally though.
autoCapitalize={'characters'}
Seems to solve the problem. https://www.reddit.com/r/reactnative/comments/jhdref/any_solution_to_the_touppercase_problemText transform Example in React Native
Table of content
https://infinitbility.com/react-native/text-transform-in-react-native
This issue is still present in React Native version:
0.63.2
I find a possible solution to my problem, the TextInput has a property autoCapitalize with the values ‘words, sentences, characters’, but the user can disable the uppercase in his keyboard so is necessary convert the value to uppercase when i want to save the data
i have the same issue when i want to save the value on the onChangeText function. i’m using expo and react-hook-form for handle the form.
Hello ReactNative Developers! 😃
I just prepared Pull Request https://github.com/facebook/react-native/pull/29070 that seems to solve this issue
PREVIEWS OF THE BUGFIX
You can contact me by email at fabrizio.developer@gmail.com
Please head over to the Pull Request https://github.com/facebook/react-native/pull/29070 and thumbs up if you like it. If you want to get this fix you can follow the instructions for building ReactAndroid or checkout my video introduction on forking react-native (patch-package does not work).
If you don’t like the pr please feel free to leave a code review or comment, I’ll be happy to add improvements and changes.
Thanks a lot 🙏 ☮️ 🏖️
You have the same behaviour with the code that delegates the ‘toLowercase’ function elsewhere :
you get in console with typing “fgHj” : LOG filter: f LOG filter: fg LOG filter: fgH LOG replic: fgh LOG filter: fgh LOG filter: fghfgHj LOG replic: fghfghj LOG filter: fghfghj
it as if there is a state inside the Textinput that is emerging back with an old memory not updated.
hi, yes on RN 0.73.2 , with code :
autoCapitalize="none"
solve the problem for 1st letter if you don not force to uppercase.The problem is :
yes I got that bug also on RN 0.70.6 the first letter is doubled with .toLowerCase() (Android) and with autoCapitalize=“none” in the Text Input parameters it is “solved” (does not reaprear)