diff --git a/examples/main.jsx b/examples/main.jsx index c7dcf6bb..8d3851e7 100644 --- a/examples/main.jsx +++ b/examples/main.jsx @@ -346,6 +346,7 @@ class SketchFieldDemo extends React.Component { ref={c => (this._sketch = c)} lineColor={this.state.lineColor} lineWidth={this.state.lineWidth} + removeItem={this._removeSelected} fillColor={ this.state.fillWithColor ? this.state.fillColor diff --git a/src/SketchField.jsx b/src/SketchField.jsx index 5e8b6f7c..15f54f66 100644 --- a/src/SketchField.jsx +++ b/src/SketchField.jsx @@ -591,7 +591,8 @@ class SketchField extends PureComponent { // Control resize window.addEventListener('resize', this._resize, false); - + window.addEventListener('keydown', this.deleteKey, false) + // Initialize History, with maximum number of undo steps this._history = new History(undoSteps); @@ -621,7 +622,10 @@ class SketchField extends PureComponent { }; - componentWillUnmount = () => window.removeEventListener('resize', this._resize); + componentWillUnmount = () => { + window.removeEventListener('resize', this._resize); + window.removeEventListener('keydown', this.deleteKey, false) + } componentDidUpdate = (prevProps, prevState) => { if (this.state.parentWidth !== prevState.parentWidth @@ -648,6 +652,12 @@ class SketchField extends PureComponent { } }; + deleteKey = (event) => { + if(event.code == "Delete" || event.code == "Backspace"){ + this.props.removeItem() + } + } + render = () => { let { className,