question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Item being dragged is not moving when lockToContainerEdges is true

See original GitHub issue

Item being dragged is not moving. I’m using the basic example to do this with the lockToContainerEdges prop. Sample code below:

`const SortableItem = sortableElement(({value}) => <li style={{ color: ‘white’}}>{value});

const SortableContainer = sortableContainer(({children}) => { return

    {children}
; });

class App extends Component { state = { items: [‘Item 1’, ‘Item 2’, ‘Item 3’, ‘Item 4’, ‘Item 5’, ‘Item 6’], };

onSortEnd = ({oldIndex, newIndex}) => { this.setState(({items}) => ({ items: arrayMove(items, oldIndex, newIndex), })); };

render() { const {items} = this.state;

return (
  <SortableContainer lockToContainerEdges={true} onSortEnd={this.onSortEnd}>
    {items.map((value, index) => (
      <SortableItem key={`item-${value}`} index={index} value={value} />
    ))}
  </SortableContainer>
);

} }`

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

4reactions
dcsaszarcommented, Sep 21, 2020

The item not moving is caused by translate3d receiving NaN values. This issue may be caused by the following change to the limit util:

https://github.com/clauderic/react-sortable-hoc/commit/6e8fe9f9bdf36cd59f7d9d46ee31560ec9d52ff8#diff-2b4ca49d4bb0a774c4d4c1672d7aa781R67-R69

Under some circumstances, limit is called with undefined for min and max. The old code returned value in this case, the new code returns NaN.

For vertical dragging, the issue can be worked around by:

  • setting lockAxis="x", because this will override NaN with 0
  • not setting lockToContainerEdges, because this will not run the limit code in question
  • setting axis="xy", because this will prevent undefined arguments to limit
1reaction
mmichael0413commented, Jan 13, 2020

Turns out I’m just an idiot. I was using lockAxis="x" but didn’t set axis="x", so once I added the axis prop, lockToContainerEdges started working. @rjdecilos I have a feeling that once you fix your container issue (missing wrapping element), or any other incorrect props, you’ll see that lockToContainerEdges starts to work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is dragged item hidden when lockToContainerEdges is ...
There is a weird interaction, the dragged element stays in position and the one in the position you drag it disappears. if I...
Read more >
Drag operations - Web APIs - MDN Web Docs - Mozilla
If the drag contains no drag data items, or all of the items have been subsequently cleared, then no drag will occur.
Read more >
clauderic/react-sortable-hoc - Gitter
My goal is providing some buttons on sortable items with onClick method ... list items are being recreated/rerendered many times without doing drag...
Read more >
404 | Vue Slicksort
By default, the group is not set and items cannot be dragged in or out of ... Setting the group prop requires the...
Read more >
react-sortable-hoc | Yarn - Package Manager
Since the new context API was introduced in React ^16.3.0, the peer dependencies had to be upgraded accordingly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found