Skip to content

[drag-drop] Re-entering the initial container can place the dragged item in an undesirable index #18697

@Achilles1515

Description

@Achilles1515

Reproduction

"Drag&Drop connected sorting group" example from the official examples page.

Behavior

Regarding the following code line:

this._dropContainer.enter(this, x, y,
            // If we're re-entering the initial container,
            // put item the into its starting index to begin with.
            newContainer === this._initialContainer ? this._initialIndex : undefined);

Like the comment states, re-entering the initial container will place the item back in its initial position. Checks to perform a sort occur after this code line.

This has the potential to cause undesirable behavior when a container is re-entered at a location not near the initial index AND when no sorting occurs.

Like this:
GIF

Now, I assume this behavior was coded this way to better handle when sorting is disabled, because it makes more sense that the item shouldn't be sorted away from its initial index. But when sorting is enabled (like in the gif above) and those stated conditions are met, the item doesn't get placed into the expected index.

Can the following change be made (checking for sortingDisabled)?

this._dropContainer.enter(this, x, y,
            // If we're re-entering the initial container,
            // put item the into its starting index to begin with.
            newContainer === this._initialContainer && newContainer.sortingDisabled ? this._initialIndex : undefined);

With this change in place, the behavior becomes:
GIF2

StackBlitz with change

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions