Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure sortenter event is fired when a dragged element enters container the first time #492

Closed
Closed
28 changes: 27 additions & 1 deletion src/html5sortable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ let originItemsBeforeUpdate
// Destination List - data from before any item was changed
let destinationItemsBeforeUpdate

// Previous Sortable Container - we dispatch as sortenter event when a
// dragged item enters a sortableContainer for the first time
let previousContainer

/**
* remove event handlers from items
* @param {Array|NodeList} items
Expand Down Expand Up @@ -320,7 +324,8 @@ export default function sortable (sortableElements, options: object|string|undef
index: originIndex,
container: originContainer
},
item: dragging
item: dragging,
originalTarget: target
}
}))
})
Expand All @@ -336,6 +341,26 @@ export default function sortable (sortableElements, options: object|string|undef
const sortableContainer = findSortable(target, e)
destinationItemsBeforeUpdate = _filter(sortableContainer.children, _data(sortableContainer, 'items'))
.filter(item => item !== store(sortableElement).placeholder)

if(sortableContainer !== previousContainer) {
// dispatch sortenter event on each element in group
sortableContainer.dispatchEvent(new CustomEvent('sortenter', {
detail: {
origin: {
elementIndex: originElementIndex,
index: originIndex,
container: originContainer
},
destination: {
container: sortableContainer,
itemsBeforeUpdate: destinationItemsBeforeUpdate
},
item: dragging,
originalTarget: target
}
}));
}
previousContainer = sortableContainer
})
/*
* Dragend Event - https://developer.mozilla.org/en-US/docs/Web/Events/dragend
Expand Down Expand Up @@ -377,6 +402,7 @@ export default function sortable (sortableElements, options: object|string|undef
}
}))

previousContainer = null
dragging = null
draggingHeight = null
})
Expand Down