Skip to content

Commit 255b1ab

Browse files
committed
changes to delete from delete keyboard button
1 parent 88eb170 commit 255b1ab

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

examples/main.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ class SketchFieldDemo extends React.Component {
346346
ref={c => (this._sketch = c)}
347347
lineColor={this.state.lineColor}
348348
lineWidth={this.state.lineWidth}
349+
removeItem={this._removeSelected}
349350
fillColor={
350351
this.state.fillWithColor
351352
? this.state.fillColor

src/SketchField.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ class SketchField extends PureComponent {
591591

592592
// Control resize
593593
window.addEventListener('resize', this._resize, false);
594-
594+
window.addEventListener('keydown', this.deleteKey, false)
595+
595596
// Initialize History, with maximum number of undo steps
596597
this._history = new History(undoSteps);
597598

@@ -621,7 +622,10 @@ class SketchField extends PureComponent {
621622

622623
};
623624

624-
componentWillUnmount = () => window.removeEventListener('resize', this._resize);
625+
componentWillUnmount = () => {
626+
window.removeEventListener('resize', this._resize);
627+
window.removeEventListener('keydown', this.deleteKey, false)
628+
}
625629

626630
componentDidUpdate = (prevProps, prevState) => {
627631
if (this.state.parentWidth !== prevState.parentWidth
@@ -648,6 +652,12 @@ class SketchField extends PureComponent {
648652
}
649653
};
650654

655+
deleteKey = (event) => {
656+
if(event.code == "Delete" || event.code == "Backspace"){
657+
this.props.removeItem()
658+
}
659+
}
660+
651661
render = () => {
652662
let {
653663
className,

0 commit comments

Comments
 (0)