Parcourir la source

Merge pull request #28 from smiclea/CORWEB-57

Allow text selection in task execution list without closing the accordion
Dorin Paslaru il y a 8 ans
Parent
commit
43ca414d6a
1 fichiers modifiés avec 18 ajouts et 2 suppressions
  1. 18 2
      src/components/Table/Table.js

+ 18 - 2
src/components/Table/Table.js

@@ -51,7 +51,7 @@ class Table extends Component {
   }
 
 
-  toggleDrawer(e, index) {
+  toggleDrawer(index) {
     let newOpenState = this.state.openState
     let toggled = !newOpenState[index]
     for (let i in newOpenState) {
@@ -62,6 +62,21 @@ class Table extends Component {
     this.setState({ openState: newOpenState })
   }
 
+  rowMouseDown(e) {
+    this.dragStartPosition = {x: e.screenX, y: e.screenY};
+  }
+
+  rowMouseUp(e, index) {
+    this.dragStartPosition = this.dragStartPosition || {x: e.screenX, y: e.screenY};
+   
+    // If a drag operation has been initiated (i.e. text selection), don't call toggleDrawer
+    if (Math.abs(this.dragStartPosition.x - e.screenX) < 3 && Math.abs(this.dragStartPosition.y - e.screenY) < 3) {
+      this.toggleDrawer(index);
+    }
+
+    this.dragStartPosition = null;
+  }
+
   render() {
     let headerItems = this.props.headerItems.map((item, index) =>
       <div className={s.cell + " cell"} key={'headerItem_' + index}>{item.label}</div>
@@ -96,7 +111,8 @@ class Table extends Component {
           <div
             className={s.row + " row " + (this.state.openState[index] ? "isOpen" : "")}
             key={"row_" + index}
-            onClick={(e) => this.toggleDrawer(e, index)}
+            onMouseDown={e => this.rowMouseDown(e)}
+            onMouseUp={e => this.rowMouseUp(e, index)}
           >
             {row} {detailView}
           </div>)