Default delete key handler preventing users from using backspace in other elements on the page
See original GitHub issueDescribe 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
- See above example
- Attempt to backspace text out of the text input (it doesn’t work)
- Set
deleteKeyCode={null}
in the Flow component - 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:
- Created a year ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top 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 >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
In the next major version (v11) you can add a class name
nokey
to all elements that should be treated as an input field.@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!