question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default delete key handler preventing users from using backspace in other elements on the page

See original GitHub issue

Describe the Bug

When the ReactFlow component is present on a page, the backspace key is intercepted and seems to be prevented from working anywhere else on the page (other than purely native text inputs completely controlled by the browser).

I don’t think that document-scope key event handlers should be calling Event.preventDefault().

Your Example Website or App

https://codesandbox.io/s/sharp-tharp-jhxqm4?file=/src/App.js

Steps to Reproduce the Bug or Issue

  1. See above example
  2. Attempt to backspace text out of the text input (it doesn’t work)
  3. Set deleteKeyCode={null} in the Flow component
  4. Note that using backspace in the text input now works

Expected behavior

As a user, I should be able to use the backspace key elsewhere in the window.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome, Safari
  • Version: 103.0, 15.5

Additional context

The example I provided is using exactly the UI component library that I am using, for maximum accuracy to my use case.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
chrtzecommented, Aug 1, 2022

In the next major version (v11) you can add a class name nokey to all elements that should be treated as an input field.

0reactions
kahboomcommented, Aug 18, 2022

@EzraBrooks - I’ve been stuck on this issue for several days and couldn’t quite figure it out. Actually in my case it was even causing a complete re-render at times when pressing the backspace. Your workaround fixes it, thanks so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I prevent the backspace key from navigating back?
//Prevent backwards navigation when trying to delete disabled text. $(document).unbind('keydown').bind('keydown', function (event) { if (event.keyCode === 8) { ...
Read more >
Example Disable backspace and delete key with JavaScript
Use the onkeydown event and preventDefault() method to Disable Backspace and Delete key in JavaScript. Backspace char code is 8 and delete.
Read more >
Ways to capture the backspace and delete on the onkeydown ...
Given the HTML document. The task is to detect when the backspace and delete keys are pressed on keydown events. Here 2 approaches...
Read more >
How To Use React onKeyPress (Example Code Included)
To handle key presses in React, we use onKeyPress. It is passed as an attribute in elements, and can be used to perform...
Read more >
KeyboardEvent.key - Web APIs | MDN
The KeyboardEvent interface's key read-only property returns the value of the key pressed by the user, taking into consideration the state ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found