Coder Social home page Coder Social logo

Comments (10)

moklick avatar moklick commented on June 20, 2024

It was meant to be a feature but I understand that it can be annoying. Currently all key event handlers are bound to window which could be changed to the wrapper. I will leave this open until we have a solution / decision for this.

from xyflow.

a1528zhang avatar a1528zhang commented on June 20, 2024

It was meant to be a feature but I understand that it can be annoying. Currently all key event handlers are bound to window which could be changed to the wrapper. I will leave this open until we have a solution / decision for this.

You mean "useKeyPress" hook? I use it In my app, such as :
const pressed = useKeyPress("Backspace", { target: "react-flow-ref"});
but I still can get Backspace key pressed when ReactFlow is blur.

what is the right way to use this hook?

from xyflow.

bcakmakoglu avatar bcakmakoglu commented on June 20, 2024

@a1528zhang target needs to be one of these target?: Window | Document | HTMLElement | ShadowRoot | null;

not just a string - it's not a query selector (if it was, the string you passed would still not be a valid query selector ^^)

from xyflow.

a1528zhang avatar a1528zhang commented on June 20, 2024

@bcakmakoglu Sure, my code actually is:
const rfRef = useRef(null); const pressed = useKeyPress("Backspace", { target: rfRef.current }); ... return <ReactFlow ref={rfRef} .../>
the problem is rfRef.current is null when component before mounted.

from xyflow.

bcakmakoglu avatar bcakmakoglu commented on June 20, 2024

Did you disable the delete key code on the ReactFlow component? <ReactFlow deleteKeyCode={null} ...>

from xyflow.

a1528zhang avatar a1528zhang commented on June 20, 2024

@bcakmakoglu Just try it, still not working

from xyflow.

bcakmakoglu avatar bcakmakoglu commented on June 20, 2024

What exactly isn't working? ^^

Your keycode listener? Disabling the delete key code should at least disable the removal of nodes initiated by ReactFlow - that much should work, yes?

from xyflow.

a1528zhang avatar a1528zhang commented on June 20, 2024

@bcakmakoglu Not working means: when I click element outof reactflow(that trigger onBlur callback), backspace still can delete selected node.

And yes, set deleteKeyCode = nullwill disable removal of nodes, but I can still trigger Backspace press event when reactflow is blur and useKeyPress is binding on reactflow ref. (I konw the time I use useKeyPress the rfRef.current is null, so useKeyPress may binding on window).

What confuses me is: when onBlur callback of reactflow triggered, some keyCode is disabled, like arrow button, but backspace is still working. Seems like backspace is different from othen keyCode

from xyflow.

bcakmakoglu avatar bcakmakoglu commented on June 20, 2024

The arrow keys don't use useKeyPress, they just an onKeyDown={handleKeyDown} handler directly to the node wrapper.

useKeyPress on the other hand, by default, binds to the window as Moritz previously explained, hence why it doesn't matter if the RF component is in focus or not.

Although your useKeyPress handler should work the way it's expected with the given bindings, at least that would be my expectation. Even if you pass null initially, if the keypress handler is re-run it should bind it to the correct element 🤔
Might be a bug ^^

from xyflow.

a1528zhang avatar a1528zhang commented on June 20, 2024

@bcakmakoglu Thanks for your explanation, waiting for your research result

from xyflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.