Confirm Delete
In production-grade editors, accidentally pressing Delete or Backspace and losing a complex cluster of nodes can be catastrophic. By default, Flow includes built-in keyboard listeners for immediate deletion. To implement a confirmation dialog (or any interception logic), you can disable the default shortcuts and take control of the deletion flow yourself.
Intersection & Confirmation Demo
Select one or more nodes below and press the Delete key on your keyboard. Observe how the system intercepts the action and prompts for confirmation before proceeding with the removal.
Safe Deletion Workflow
Implementation Strategy
- Disable Internal Handling: Pass
:keyboard-shortcuts="false"to the<yh-flow>component. This prevents the engine from automatically handlingDelete,Backspace,Ctrl+C, etc. - Top-Level Interception: Wrap the flow component in a container with
@keydownlisteners to capture the specific keys you want to intercept. Ensure the container is focusable (e.g., usingtabindex="0"). - Filtered Mutation: After verifying the user's intent (e.g., via a Modal), simply filter your
nodesandedgesarrays to remove the selected IDs. Reactivity takes care of the rest.