MrBlenny / react-flow-chart

🌊 A flexible, stateless, declarative flow chart library for react.
https://mrblenny.github.io/react-flow-chart/index.html
MIT License
1.48k stars 306 forks source link

How to disable backspace to remove node element #141

Closed smartball closed 4 years ago

smartball commented 4 years ago

I want to know how to disable backspace to remove node element (not custom node_modules). help me please.

davidanitoiu commented 4 years ago

The event is checked in the CanvasInner, so you have to use a custom component to overwrite it.

import { CanvasInnerDefault } from "@mrblenny/react-flow-chart";
import React from 'react';

const CustomCanvasInner = ({children, config, onKeyDown, ...args}) => {

    const handleKeyDown = (e) => {
        if (e.keyCode === 46) {
            return {...onKeyDown(e)}
        }
    }

    return (
        <CanvasInnerDefault {...args} onKeyDown={handleKeyDown}>
            {children}
        </CanvasInnerDefault>
    )
}

export default CustomCanvasInner;
smartball commented 4 years ago

The event is checked in the CanvasInner, so you have to use a custom component to overwrite it.

import { CanvasInnerDefault } from "@mrblenny/react-flow-chart";
import React from 'react';

const CustomCanvasInner = ({children, config, onKeyDown, ...args}) => {

    const handleKeyDown = (e) => {
        if (e.keyCode === 46) {
            return {...onKeyDown(e)}
        }
    }

    return (
        <CanvasInnerDefault {...args} onKeyDown={handleKeyDown}>
            {children}
        </CanvasInnerDefault>
    )
}

export default CustomCanvasInner;

Wow. It work. Thank you so much mr.@davidanitoiu .