-
-
Notifications
You must be signed in to change notification settings - Fork 461
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
dispatch sortenter #494
dispatch sortenter #494
Conversation
Hey @christophe-g, looks very good. You are sending the originalTarget because it could be a list item instead of the sortable itself, correct? I fixed the issues with the tests, so could you please also fix the styling issues (https://travis-ci.org/lukasoppermann/html5sortable/builds/500918185#L521) so I can merge it, thanks. |
makes sure original target is sent with the sortenter and sortstart event;
@lukasoppermann - done. Reason for Polymer 2.0 version of html5-sortable tries to work with data model used by dom-repeat directly rather than dom-nodes: drag event will mutate array items, which triggers a refresh of dom-repeat. // Note(cg): we use this event to store model (dom-repeat item) hold by the dragged item.
_onSortstart(event) {
event.stopPropagation();
if (this.parentClass) {
this.parentElement.classList.add(this.parentClass);
}
const startparent = event.detail.origin && event.detail.origin.container,
startrepeater = this._getRepeater(startparent);
this.draggedModel = startrepeater.itemForElement(event.detail.originalTarget);
this.draggedIndex = startrepeater.indexForElement(event.detail.originalTarget);
// Note(cg): when we use a handle, originalTarget is the handle itself
// and not the initial dragged item
if (!this.draggedModel && event.detail.originalTarget.domHost) {
this.draggedModel = startrepeater.itemForElement(event.detail.originalTarget.domHost);
this.draggedIndex = startrepeater.indexForElement(event.detail.originalTarget.domHost);
}
this._dispatch('sort-start', event);
} This is to be used like <paper-listbox>
<polymer-sortable copy placeholder="<paper-item>drop</paper-item>" accept-from=".none" items="paper-item">
<template is="dom-repeat" items="[[items]]">
<paper-item>[[item.key]]</paper-item>
</template>
</polymer-sortable>
</paper-listbox> Note, Polymer 2.0 version is still a bit too WIP, but will push it soon |
I'll merge this later. 👍 If you have time to add tests for this that would be great so that this behavior is not accidentally broken down the line. Are you planning on sending a PR for a polymer 2 adapter as well? |
|
Replace and supersedes #492
sortenter
event first time dragged item enters a container;sortenter
andsortstart
event;Motivation:
sortenter
event - useful when dragging to a different list and wish to update placeholder content.sortstart
andsortenter
event. When sortable is used with copy = true, the dragged item is a deep-copy of the original target. This prevents accessing the real original target. it is a problem in some cases (like in polymer dom-repeat component) where only the original target holds some linked properties.