Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fmancuso opened this issue Apr 24, 2024 · 0 comments
Open
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team

Comments

@fmancuso
Copy link

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.

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.

@fmancuso fmancuso added feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team labels Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

1 participant