Skip to content

iOS: Multiline TextInput onKeyPress event handler unexpectedly receives a Backspace event #37967

Description

@jbrowning

Description

The TextInput onKeyPress event handler receives an unexpected Backspace event when multiline is true. The exact behavior varies between iOS 15 and iOS 16:

  • iOS 15: The Backspace event is received after value is reset to an empty string
  • iOS 16: The Backspace event is received on EVERY change AND when value is reset to an empty string

This has been tested on iOS 15.5, 16.4, and 16.5.

Possibly related: #34891

React Native Version

0.71.11

Output of npx react-native info

System:
OS: macOS 13.4
CPU: (16) x64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
Memory: 27.38 GB / 64.00 GB
Shell: 5.9 - /usr/local/bin/zsh
Binaries:
Node: 18.16.0 - ~/.asdf/installs/nodejs/18.16.0/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.6.6 - ~/.asdf/plugins/nodejs/shims/npm
Watchman: Not Found
Managers:
CocoaPods: 1.12.1 - /Users/jeff/.asdf/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: 2022.2 AI-222.4459.24.2221.10121639
Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
Languages:
Java: 11.0.13 - /Users/jeff/.asdf/shims/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.11 => 0.71.11
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  1. Add a <TextInput multiline /> component and log all events received by onKeyPress
  2. Type into the input
  3. Observe that an event with nativeEvent.key set to 'Backspace' is received after every onKeyPress event is received for the typed key

Snack, code example, screenshot, or link to a repository

https://github.com/jbrowning/RN071TextInputBackspace

Activity

  1. changed the title [-]iOS: Multiline TextInput onKeyPress event handler receives a Backspace event after every change[/-] [+]iOS: Multiline TextInput onKeyPress event handler unexpectedly receives a Backspace event[/+] on Jun 19, 2023
  2. rodrigoeidelvein commented on Jun 19, 2023

    @rodrigoeidelvein

    Same issue here

  3. Pranav-yadav commented on Jun 21, 2023

    @Pranav-yadav
    Contributor
  4. gbalduzzi commented on Jun 28, 2023

    @gbalduzzi

    I'm having the same issue on iOS 16.4 with a single line textfield.

    <TextInput onKeyPress={(e) => console.log(e.nativeEvent} />

    Pressing a random key, such as 'a' results in the following log:

    {"eventCount": 1, "key": "a", "target": 1205}
    {"eventCount": 2, "key": "Backspace", "target": 1205}
    

    I'm guessing it's related to iOS 16.4, because some of my components that were working before are now broken

    My current clunky workaround is to check for the distance between events, under 100 milliseconds I ignore the Backspace:

    function onKeyPress(e) {
        if (e.nativeEvent.key === 'Backspace' && Date.now() - latestTimestamp > 100) {
            // Handle backspace actually wanted by the user
        }
    
        if (e.nativeEvent.key !== 'Backspace') {
          latestTimestamp = Date.now()
        }
    }
    
  5. chadders404 commented on Jun 28, 2023

    @chadders404

    I'm also having this problem on a physical iPhone 11 Pro running iOS 16.1.1. My project is using Expo. The behaviour does not occur on Android.

  6. mokhtarHamdoune commented on Aug 19, 2023

    @mokhtarHamdoune

    I have the same issue, after each key press event of the TextInput component, I have a Backspace.

    LOG F
    LOG Backspace

    React Native: 0.71.6
    IOS: 16.4

  7. tibbe commented on Sep 19, 2023

    @tibbe

    We also seem to get duplicated Enter key presses.

    System:
        OS: macOS 13.5.2
        CPU: (8) arm64 Apple M1 Pro
        Memory: 95.41 MB / 16.00 GB
        Shell: 5.9 - /bin/zsh
      Binaries:
        Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
        Yarn: Not Found
        npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
        Watchman: 2023.07.03.00 - /opt/homebrew/bin/watchman
      Managers:
        CocoaPods: 1.12.1 - /Users/tibbe/.rbenv/shims/pod
      SDKs:
        iOS SDK:
          Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
        Android SDK: Not Found
      IDEs:
        Android Studio: 2022.2 AI-222.4459.24.2221.10121639
        Xcode: 15.0/15A240d - /usr/bin/xcodebuild
      Languages:
        Java: 11.0.19 - /usr/bin/javac
      npmPackages:
        @react-native-community/cli: Not Found
        react: 18.2.0 => 18.2.0 
        react-native: 0.71.13 => 0.71.13 
        react-native-macos: Not Found
      npmGlobalPackages:
        *react-native*: Not Found
    
  8. pee0803 commented on Nov 23, 2023

    @pee0803

    Same issue here, but with multiline = false. And also I hit on return key in my iOS simulator, it does not show any event

  9. vinaykumar0339 commented on Dec 4, 2023

    @vinaykumar0339

    same here in 0.72.7 version

  10. raynox commented on Jan 23, 2024

    @raynox

    I experience the same issue
    React Native: 0.70.10
    iOS: 17.2, simulator

  11. chadders404 commented on Apr 8, 2024

    @chadders404

    I am still experiencing this issue.

    iOS 17.4.1 , iPhone 11
    React Native: 0.73.6
    Expo Managed Workflow
    Expo SDK: 50.0.14

    Has anyone got more information or found a way around this problem?

  12. 7 remaining items

  13. tibbe commented on Mar 18, 2025

    @tibbe

    Still happens.

  14. removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Mar 18, 2025
  15. gaoag commented on Apr 1, 2025

    @gaoag

    still happening. anybody get any progress here?

  16. react-native-bot commented on Sep 29, 2025

    @react-native-bot
    Collaborator

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  17. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Sep 29, 2025
  18. tibbe commented on Sep 29, 2025

    @tibbe

    Still an issue

  19. removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Sep 30, 2025
  20. react-native-bot commented on Mar 29, 2026

    @react-native-bot
    Collaborator

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  21. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Mar 29, 2026
  22. pxpeterxu commented on Mar 29, 2026

    @pxpeterxu
    Contributor

    We recently updated our app to React Native version 0.81, and this issue no longer seems to happen:

    This issue can likely be closed now. It likely got changed in some refactor of how the TextInput component works.

    Image

  23. removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Mar 30, 2026
  24. react-native-bot commented on Sep 26, 2026

    @react-native-bot
    Collaborator

    This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

  25. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Sep 26, 2026
  26. react-native-bot commented on Oct 3, 2026

    @react-native-bot
    Collaborator

    This issue was closed because it has been stalled for 7 days with no activity.

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: Triage 🔍Platform: iOSiOS applications.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions