| 361 | } |
| 362 | |
| 363 | handleComponentKey (e) { |
| 364 | // handles keyboard events when editing components |
| 365 | const keyCode = e.which || e.keyCode |
| 366 | if (![ENTER_KEY, ESCAPE_KEY, TAB_KEY].includes(keyCode)) { |
| 367 | return |
| 368 | } |
| 369 | const {editing} = this.state |
| 370 | const {data} = this.props |
| 371 | const isEditing = !isEmpty(editing) |
| 372 | if (isEditing) { |
| 373 | const currentCell = data[editing.i][editing.j] |
| 374 | const offset = e.shiftKey ? -1 : 1 |
| 375 | if (currentCell && currentCell.component && !currentCell.forceComponent) { |
| 376 | e.preventDefault() |
| 377 | let func = this.onRevert // ESCAPE_KEY |
| 378 | if (keyCode === ENTER_KEY) { |
| 379 | func = () => this.handleNavigate(e, {i: offset, j: 0}) |
| 380 | } else if (keyCode === TAB_KEY) { |
| 381 | func = () => this.handleNavigate(e, {i: 0, j: offset}, true) |
| 382 | } |
| 383 | // setTimeout makes sure that component is done handling the event before we take over |
| 384 | setTimeout(() => { func(); this.dgDom && this.dgDom.focus() }, 1) |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | onContextMenu (evt, i, j) { |
| 390 | let cell = this.props.data[i][j] |