Skip to content

Conversation

Sheile
Copy link
Contributor

@Sheile Sheile commented May 16, 2019

When use some theme that can drag entire node, Can't disable draggable status dynamically by canDrag prop after enable.

Reproduce code snippet

constructor() {
  this.state = {
    treeData: [
      { title: 'Title', draggable: false },
      ...
    ]
  }
}

render() {
  <SortableTree
    treeData={this.state.treeData}
    canDrag={({ node }) => node.draggable}
  />
}

toggleDraggable = ({ node, path }) => {
  const newNode = {
    ...node,
    draggable: !node.draggable
  }

  const newState = changeNodeAtPath({
    treeData: this.state.treeData,
    path,
    newNode,
    getNodeKey: ({ treeIndex }) => treeIndex
  })
  this.setState({ treeData: newState })
}

Description

  1. Render tree and can't drag node. (Correct behavior)
  2. toggle dragging status.
  3. can drag node. (Correct behavior)
  4. toggle dragging status.
  5. CAN drag node. (Wrong behavior)

Reason

If turn on dragging feature, target node connect as drag source via connectDragSource.
This connecting status will NOT release when turn off feature.

Resolve

This PR change to pass canDrag prop to following property in react-dnd directly.
http://react-dnd.github.io/react-dnd/docs/api/drag-source#specification-methods

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 75.596% when pulling 13f0566 on Sheile:fix/disable-dragging into c87715a on frontend-collective:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants