Skip to content

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

Closed

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

Activity

  1. changed the title [-][drag-drop] Re-entering the initial container can place an item in an undesirable index[/-] on Mar 3, 2020
  2. self-assigned this
    on Mar 4, 2020
  3. added
    P3
    on Mar 4, 2020
  4. added a commit that references this issue on Mar 4, 2020
    4f0902d
  5. added 2 commits that reference this issue on Mar 12, 2020
    1a3c35a
    14ae95f
  6. angular-automatic-lock-bot commented on Apr 12, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  7. locked and limited conversation to collaborators on Apr 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions