TextInput onChangeText is called with empty text if maxLength is exceeded on iOS
See original GitHub issueDescription
If the max length of a controlled TextInput
is exceeded on iOS onChangeText
will get called with an empty string. We noticed this issue when our users added an emoji as the last character in a TextInput
. We only see the issue on iOS, on Android the the emoji can not be added. Since emojis are counted as two chars I’m guessing the emoji is causing the text to have length maxLength+1 and that is causing issues on iOS.
Using an uncontrolled TextInput
the emoji is replace with the last character in the screenshot below but keeps it’s value.
React Native version:
0.61.4
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
- Create a controlled TextInput with a maxLength
- Input text until you reach maxLength - 1
- Add a emoji
Expected Results
Same behaviour as on Android that the emoji is not accepted as input.
Snack, code example, screenshot, or link to a repository:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:12
Top Results From Across the Web
React Native to limit lines in TextInput - Stack Overflow
For standard text fontSize, giving maxHeight={60} will make TextInput scrollable after 3 lines. This is good for IOS - for Android you can...
Read more >When MaxLength is reached switch to another TextInput
I have a canvas app that includes two different text inputs. On the first text input I assigned the MaxLength to be 20...
Read more >TextInput - ReactXP
In the first mode, the contents of the text input are static and are specified by the value prop. Any attempt to modify...
Read more >React Native Text Input Component - GeeksforGeeks
maxLength : It is used when we do not want to exceed the particular number of characters. So we provide a fixed maximum...
Read more >TextInput QML Type | Qt Quick 6.4.1
TextInput does not have vertical alignment, as the natural height is exactly the height of the single line of text. If you set...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a workaround I’ve removed
maxLength
prop and added the following code to theonChangeText
callback:It minimizes the chances of the bug happening but doesn’t fix it.
I’ve found a workaround that fixes the issue:
It’s a bit ugly to access the private
_dispatchInstances
, but it does work.I’m using React Native ~0.63.4.