Item being dragged is not moving when lockToContainerEdges is true
See original GitHub issueItem 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:
- Created 4 years ago
- Reactions:2
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The item not moving is caused by
translate3d
receivingNaN
values. This issue may be caused by the following change to thelimit
util:https://github.com/clauderic/react-sortable-hoc/commit/6e8fe9f9bdf36cd59f7d9d46ee31560ec9d52ff8#diff-2b4ca49d4bb0a774c4d4c1672d7aa781R67-R69
Under some circumstances,
limit
is called withundefined
formin
andmax
. The old code returnedvalue
in this case, the new code returnsNaN
.For vertical dragging, the issue can be worked around by:
lockAxis="x"
, because this will overrideNaN
with0
lockToContainerEdges
, because this will not run thelimit
code in questionaxis="xy"
, because this will preventundefined
arguments tolimit
Turns out I’m just an idiot. I was using
lockAxis="x"
but didn’t setaxis="x"
, so once I added theaxis
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 thatlockToContainerEdges
starts to work.