angular / angular/components

bug(cdkDropList): Wrong index for cdkPlaceHolder/cdkDrag after drag/hover other list and going back to original droplist

Open
#28,919 4 comments 2 reactions 0 assignees View on GitHub
area: cdk/drag-drop P3
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

My apologies if this is a stupid use case, I am trying to use multiple droplists as a base for a patience/solitaire card game as a learning project. There are multiple connected droplists where you can only drag the last item, and drop it in the last position of another container. This works amazing.

However, dragging from a cdkDroplist from the right to another cdkDroplist to the left of it and returning to the original list does not put the cdkPlaceHolder in the original index. Dragging from left to right (and returning to the original list) does?!

Not sure is this is an issue or working as intended.
I think i understand partially why it happens, but don't understand why it does work from left to right.

### Reproduction

StackBlitz link: https://stackblitz.com/~/github.com/PsychoSpike/cdkDropListsSortedToBottom
Steps to reproduce:
1. Pick up an item from the most right list
2. Drag(not drop) it over a list to the left
3. Return to the original list

### Expected Behavior

The CdkDragPlaceholder and CdkDrag element returns to its original index

### Actual Behavior

The CdkDragPlaceholder shows up at the wrong index and the CdkDrag element gets put into index-1 from starting the drag

### Environment

- Angular:
- CDK/Material:
- Browser(s):
- Operating System (e.g. Windows, macOS, Ubuntu):

Contributor guide

Open the contributing guide

Research direction

Start by running the linked StackBlitz reproduction and follow the cdkDropList, cdkPlaceHolder, and cdkDrag behavior while moving an item from the right list to a left list and back. Compare the returned placeholder index and final item index with the original position; done means the item and placeholder return to that original index without changing the drag direction.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.