When I drag an item within the same list it will save it on the first drag but since the index didn't update, on the following dragging events it will move all of the items at once and there are empty spaces because it thinks its moving it as if it were still in its last position.
When moving to another list it hides the sortable element with the same index and since the indexes are not updating the element with the same index stays hidden.
Below is my component ( I removed alot of code but this is the main sorting part of the code)
ListWrapper is the same as the ListWrapper component from your src/stories/index.js file.
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import List from '../List';
import { default as Item } from '../Item';
import { SortableContainer, SortableElement, DragLayer } from 'react-sortable-hoc';
import ListWrapper from './ListWrapper';
const SortableItem = SortableElement(Item)
const SortableList = SortableContainer(List, { withRef: true })
class Container extends Component {
constructor(props) {
this.createLists = this.createLists.bind(this)
this.state = { lists: [] }
}
createLists() {
const createItems = (data) => {
let items= []
let i = 0
for(let prop in data) {
items.push(
<SortableItem
key={ `task-${prop}-${data[prop].name}` }
index={ i }
pressDelay={ 100 }
title={ data[prop].name }
description={ data[prop].description } />
)
i++
}
return items
}
let lists= [];
const dragLayer = new DragLayer();
for (let key in data) {
lsits.push(<ListWrapper
component={SortableList}
key={ key }
pressDelay={ 100 }
title={ humanize(key) }
items={ createItems(data[key].items) }
dragLayer={ dragLayer }
getContainer={ wrappedInstance => ReactDOM.findDOMNode(wrappedInstance).children[1] }
/>
)
}
this.setState({ lists: lists})
}
componentWillMount() {
this.createLists()
}
render() {
return (
<div>
<h1>{ this.props.name }</h1>
<div>
{ this.state.lists}
</div>
</div>
)
}
}