Skip to content

Commit 2a6195e

Browse files
AllenFangpowellandy
authored andcommitted
fix #1750
1 parent 198d191 commit 2a6195e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/TableBody.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class TableBody extends Component {
252252

253253
handleCellKeyDown = (e, lastEditCell) => {
254254
e.preventDefault();
255-
const { keyBoardNav, onNavigateCell, cellEdit } = this.props;
255+
const { keyBoardNav, onNavigateCell, cellEdit, selectedRowKeys } = this.props;
256256
let offset;
257257
if (e.keyCode === 37) {
258258
offset = { x: -1, y: 0 };
@@ -269,21 +269,30 @@ class TableBody extends Component {
269269
} else if (e.keyCode === 40) {
270270
offset = { x: 0, y: 1 };
271271
} else if (e.keyCode === 13) {
272+
const rowIndex = e.target.parentElement.rowIndex + 1;
272273
const enterToEdit = typeof keyBoardNav === 'object' ?
273274
keyBoardNav.enterToEdit :
274275
false;
275276
const enterToExpand = typeof keyBoardNav === 'object' ?
276277
keyBoardNav.enterToExpand :
277278
false;
279+
const enterToSelect = typeof keyBoardNav === 'object' ?
280+
keyBoardNav.enterToSelect :
281+
false;
278282

279283
if (cellEdit && enterToEdit) {
280-
this.handleEditCell(e.target.parentElement.rowIndex + 1,
281-
e.currentTarget.cellIndex, '', e);
284+
this.handleEditCell(rowIndex, e.currentTarget.cellIndex, '', e);
282285
}
283286

284287
if (enterToExpand) {
285288
this.handleClickCell(this.props.y + 1, this.props.x);
286289
}
290+
291+
if (enterToSelect) {
292+
const isSelected = selectedRowKeys.indexOf(
293+
this.props.data[rowIndex - 1][this.props.keyField]) !== -1;
294+
this.handleSelectRow(rowIndex, !isSelected, e);
295+
}
287296
}
288297
if (offset && keyBoardNav) {
289298
onNavigateCell(offset);

0 commit comments

Comments
 (0)