TextInput onKeyPress fires after the onChange
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
Description
According to the docs the keyPress event should fire before the change event. That does not seem to be the case though, I've run into this on a physical device in a project (doesn't use expo) I can't share and also reproduced this on a online playground for react native with expo.
In the video you can see that the console.log in the onChange callback happens before the cosnole.log in the onKeyPress callback:
https://github.com/user-attachments/assets/6e5b8cd5-6452-42a7-b315-54c911933a14
Steps to reproduce
- Add the onKeyPress and onChange callbacks to a TextInput
- Trigger both events by pressing any key on a keyboard
- see that onChange triggers first
React Native Version
tested on 0.74.5 and 0.76.6
Affected Platforms
Runtime - Android
Output of npx react-native info
info Fetching system and libraries information...
System:
OS: Linux 5.10 Manjaro Linux
CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
Memory: 18.82 GB / 30.99 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.18.2
path: /usr/local/bin/node
Yarn:
version: 1.22.22
path: /usr/local/bin/yarn
npm:
version: 9.8.1
path: /usr/local/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: AI-241.18034.62.2411.12169540
Languages:
Java: Not Found
Ruby:
version: 2.6.8
path: /home/owner/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.74.5
wanted: 0.74.5
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: false
newArchEnabled: false
Stacktrace or Logs
no logs to show
Reproducer
https://snack.expo.dev/@ncpa/rn-bug
Screenshots and Videos
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Snack reproducer and the React Native TextInput documentation, focusing on the Android ordering of onKeyPress and onChange. Trace the relevant TextInput event path and add or update a regression test if the repository has one; done means the observed Android ordering matches the documented behavior or the documentation accurately reflects the implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100