angular / angular/components

feat(cdk/drag-drop): Allow dynamic drop lists creation while dragging an item

未关闭
#28,958 1 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看
area: cdk/drag-drop feature P4
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

### Feature Description

I have noticed that if I try to create a drop list dynamically while I am dragging an item, the drop list is created graphically but it is not possible to drop the item I am dragging into that drop list. This seems to happen because the "_siblings" are created at drag initiation and do not notice if a row is created at runtime. It start working after a few drop list exit or enter but not if you directly go to that drop list.

Would it be possible to have this feature?
Or if it is already possible could you tell me how to do it?
For the moment I solved it by adding this method to my code, but it seems to me a very dirty solution.

```typescript
private refreshDropLists() {
// do it only if the component rows and the library rows are not sync
if (this.dropLists.toArray().length === this.configuration.length) {
// loop over the droplists
this.dropLists.toArray().forEach((dropList) => {
// force to recalculate the row positions
// @ts-ignore
dropList._dropListRef._cacheParentPositions();
// force the link between each row except for the row itself
dropList._dropListRef.connectedTo(
this.dropLists
.toArray()
.filter((dropList2) => dropList.id !== dropList2.id)
.map((droplist2) => droplist2._dropListRef)
);
});
}
}
```

An example can be viewed at the following link: https://stackblitz.com/edit/stackblitz-starters-7xvrf3?file=src%2Fapp%2Fapp.component.ts

If you want to make it work where to uncomment line 30 and 31 of the file "app.component.ts"

### Use Case

A useful use case would be, as with the linked stackblitz, creating a new droplists from the element I am dragging.
So if I have as in my case a structure of rows and columns, I want to be able to drag my column to a new row that doesn't exist.

贡献指南

打开贡献指南

调研方向

从链接的 StackBlitz 示例开始,尤其是 src/app/app.component.ts,并复现拖动时创建 drop list 的过程。阅读针对同级列表的 CDK drag-drop 处理,并验证新创建的列表无需 workaround 即可接受直接 drop;如果确定了相关的测试入口,则添加或更新针对性测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。