Skip to content

Commit

Permalink
changes to delete from delete keyboard button
Browse files Browse the repository at this point in the history
  • Loading branch information
srijondasgit committed Mar 29, 2020
1 parent 88eb170 commit 255b1ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/SketchField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -648,6 +652,12 @@ class SketchField extends PureComponent {
}
};

deleteKey = (event) => {
if(event.code == "Delete" || event.code == "Backspace"){
this.props.removeItem()
}
}

render = () => {
let {
className,
Expand Down

0 comments on commit 255b1ab

Please sign in to comment.