From d149941dbdf57c7f95e936aec8db9909cf3408dd Mon Sep 17 00:00:00 2001 From: AllenFang Date: Tue, 31 Jan 2017 18:47:02 +0800 Subject: [PATCH] fix #994 --- src/TableEditColumn.js | 9 ++++++++- src/TableRow.js | 42 ++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/TableEditColumn.js b/src/TableEditColumn.js index 1b963f42f..93f106532 100644 --- a/src/TableEditColumn.js +++ b/src/TableEditColumn.js @@ -116,6 +116,12 @@ class TableEditColumn extends Component { this.clearTimeout(); } + handleClick = e => { + if (e.target.tagName !== 'TD') { + e.stopPropagation(); + } + } + render() { const { editable, format, customEditor } = this.props; const { shakeEditor, className } = this.state; @@ -146,7 +152,8 @@ class TableEditColumn extends Component { return ( + className={ className } + onClick={ this.handleClick }> { cellEditor } diff --git a/src/TableRow.js b/src/TableRow.js index 0928fc1af..54e868c77 100644 --- a/src/TableRow.js +++ b/src/TableRow.js @@ -11,31 +11,29 @@ class TableRow extends Component { rowClick = e => { const rowIndex = this.props.index + 1; if (this.props.onRowClick) this.props.onRowClick(rowIndex); - if (e.target.tagName === 'TD') { - const cellIndex = e.target.cellIndex; - const { selectRow, unselectableRow, isSelected, onSelectRow, onExpandRow } = this.props; - if (selectRow) { - if (selectRow.clickToSelect && !unselectableRow) { - onSelectRow(rowIndex, !isSelected, e); - } else if (selectRow.clickToSelectAndEditCell && !unselectableRow) { - this.clickNum++; - /** if clickToSelectAndEditCell is enabled, - * there should be a delay to prevent a selection changed when - * user dblick to edit cell on same row but different cell - **/ - setTimeout(() => { - if (this.clickNum === 1) { - onSelectRow(rowIndex, !isSelected, e); - onExpandRow(rowIndex, cellIndex); - } - this.clickNum = 0; - }, 200); - } else { - this.expandRow(rowIndex, cellIndex); - } + const cellIndex = e.target.cellIndex; + const { selectRow, unselectableRow, isSelected, onSelectRow, onExpandRow } = this.props; + if (selectRow) { + if (selectRow.clickToSelect && !unselectableRow) { + onSelectRow(rowIndex, !isSelected, e); + } else if (selectRow.clickToSelectAndEditCell && !unselectableRow) { + this.clickNum++; + /** if clickToSelectAndEditCell is enabled, + * there should be a delay to prevent a selection changed when + * user dblick to edit cell on same row but different cell + **/ + setTimeout(() => { + if (this.clickNum === 1) { + onSelectRow(rowIndex, !isSelected, e); + onExpandRow(rowIndex, cellIndex); + } + this.clickNum = 0; + }, 200); } else { this.expandRow(rowIndex, cellIndex); } + } else { + this.expandRow(rowIndex, cellIndex); } }