Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions BlazorSortableList.Lib/SortableList.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
if (DEBUG_MODE) {
console.log("Init for Id:", id, "swapThreshold:", swapThreshold);
}
let multiDrag = (typeof cssForSelection !== 'undefined');
// .NET marshals an unset string as null, never undefined, so a `typeof` check here would always pass.
let multiDrag = !!cssForSelection;

let htmlElement = document.getElementById(id);
if (!htmlElement) {
Expand Down Expand Up @@ -65,7 +66,7 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
handle: handle || undefined,

multiDrag: multiDrag,
selectedClass: cssForSelection,
selectedClass: cssForSelection || undefined,
multiDragKey: multiDragKey,
avoidImplicitDeselect: avoidImplicitDeselect,
swapThreshold: swapThreshold, //0.65,
Expand All @@ -78,7 +79,8 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
let oldIndex = event.oldDraggableIndex;
let newIndex = event.newDraggableIndex;
// in multi selection mode we have newIndicies only
let newIndicies = Array.from(event.newIndicies);
// Only the MultiDrag plugin adds these, so they are undefined when multiDrag is off.
let newIndicies = event.newIndicies ? Array.from(event.newIndicies) : [];
Comment on lines 79 to +83

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think this one holds. oldDraggableIndex/newDraggableIndex are core SortableJS state, not MultiDrag additions - they are module-level variables in src/Sortable.js, assigned in _prepareDragStart, _onDragOver and _onDrop, and included in every dispatched event regardless of which plugins are mounted.

The genuinely MultiDrag-only properties are oldIndicies/newIndicies, which come from the plugin's eventProperties() - and those are exactly what this PR guards. Leaving the draggable indices as they are.

if (newIndicies.length > 0) {
newIndex = newIndicies[0].index;

Expand Down Expand Up @@ -124,7 +126,8 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
let newIndex = event.newDraggableIndex;

// in multi selection mode we have newIndicies only
let newIndicies = Array.from(event.newIndicies);
// Only the MultiDrag plugin adds these, so they are undefined when multiDrag is off.
let newIndicies = event.newIndicies ? Array.from(event.newIndicies) : [];
if (newIndicies.length > 0) {
newIndex = newIndicies[0].index;

Expand Down