Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to override the default 'Backspace' delete functionality? #300

Open
connerkennedy32 opened this issue Feb 17, 2025 · 3 comments
Milestone

Comments

@connerkennedy32
Copy link

I want to be able to rename the different nodes I'm using, but anytime a node is selected and I press backspace, it runs the onDelete function and wipes the node from the tree. Anyway to override this so backspace doesn't delete a node?

@jameskerr jameskerr added this to the Version 4 milestone Feb 18, 2025
@jameskerr
Copy link
Contributor

jameskerr commented Feb 18, 2025

That's no fun.

There is no way to override it through a configuration (yet). It is coming in version 4.

For now, add an event listener for onKeyDown on your Node Renderer or Row Renderer, and call e.stopPropagation() if the key is the backspace key.

@connerkennedy32
Copy link
Author

Perfect. Thanks!

@smark-1
Copy link

smark-1 commented Mar 19, 2025

I also am trying to delete a node with a button press instead/in addition to the default backspace press. I ended up hacking it like this:

const triggerBackspace = (node) => {
    const event = new KeyboardEvent("keydown", {
        key: "Backspace",
        code: "Backspace",
        keyCode: 8,     
        charCode: 8, 
        which: 8,
        bubbles: true,
        cancelable: true,
    });

    node.dispatchEvent(event);
}

node.focus()
triggerBackspace(document.activeElement)

Let me know if there is a better way to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants