private onCellKeydown()

in src/draft-components/gridv2/grid.tsx [318:369]


  private onCellKeydown(event: KeyboardEvent) {
    const { isEditing, pageLength } = this;
    const maxCellIndex = this.rowSelection === RowSelectionPattern.Checkbox ? this.columns.length : this.columns.length - 1;
    let [colIndex, rowIndex] = this.activeCell;
    switch(event.key) {
      case 'ArrowUp':
        rowIndex = Math.max(0, rowIndex - 1);
        break;
      case 'ArrowDown':
        rowIndex = Math.min(this.cells.length - 1, rowIndex + 1);
        break;
      case 'ArrowLeft':
        colIndex = Math.max(0, colIndex - 1);
        break;
      case 'ArrowRight':
        colIndex = Math.min(maxCellIndex, colIndex + 1);
        break;
      case 'Home':
        colIndex = 0;
        break;
      case 'End':
        colIndex = maxCellIndex;
        break;
      case ' ':
        // space never enters into actions column
        if (this.getColumnData(colIndex).actionsColumn) return;
      case 'Enter':
        // enter also doesn't enter into actions column unless the keyboard modal variant is true
        if (this.getColumnData(colIndex).actionsColumn && !this.modalCell) return;
        console.log('go into editing mode', this.modalCell, 'is action col?', this.getColumnData(colIndex));
        event.preventDefault();
        this.updateEditing(true, true);
        break;
      case 'Escape':
        this.updateEditing(false, true);
        event.stopPropagation();
        break;
      case 'PageUp':
        rowIndex = Math.max(0, rowIndex - pageLength);
        break;
      case 'PageDown':
        rowIndex = Math.min(this.cells.length - 1, rowIndex + pageLength);
        break;
      case 'Tab':
        // prevent tabbing outside cell if modal
        this.modalCell && this.isEditing && this.trapCellFocus(event);
    }

    if (!isEditing && this.updateActiveCell(colIndex, rowIndex)) {
      event.preventDefault();
    }
  }