angular-ui/ui-grid

Cell remains in edit mode after Enter key on last row

Open

#6667 aperta il 11 apr 2018

Vedi su GitHub
 (0 commenti) (0 reazioni) (1 assegnatario)JavaScript (2496 fork)batch import
good first issue

Metriche repository

Star
 (5395 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

It is reproducible on http://plnkr.co/edit/9Zku7pBsCP2racyYButW?p=preview, but is also on tutorial page: http://ui-grid.info/docs/#!/tutorial/309_editable_with_cellnav

Symptoms: When last row is being edited using cellNav and Enter is pressed, last row remains in edit mode. Edit mode should end in this case.

Steps to reproduce:

  1. Scroll to the last row in grid
  2. Double click Name cell
  3. Edit the value and press Enter
  4. As you can see cell remained in edit mode.

Fix proposal: I found this line which is causing it. In method:

UiGridCellNav.prototype.getRowColDown

there are following lines:

if (curRowIndex === focusableRows.length - 1) {
  return new GridRowColumn(curRow, focusableCols[curColIndex]); //return same row
}
else {
  //down one row
  return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[curColIndex]);
}

Replace with:

if (curRowIndex === focusableRows.length - 1) {
  return null; // nowhere to navigate
}
else {
  //down one row
  return new GridRowColumn(focusableRows[curRowIndex + 1], focusableCols[curColIndex]);
}

Then method in usages of method UiGridCellNav.prototype.getRowColDown null check its result and if it is null do not proceed further with action.

This helped us to solve this issue but it would be great if fix can be a part of ui-grid's regular release.

Guida contributor