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(drag-drop): add option for items to be returned to original list if not dropped on container #18610

Open
MrPollux opened this issue Feb 25, 2020 · 10 comments
Labels
area: cdk/drag-drop feature This issue represents a new feature or feature request rather than a bug or bug fix P4 A relatively minor issue that is not relevant to core functions

Comments

@MrPollux
Copy link

MrPollux commented Feb 25, 2020

Steps to reproduce:

  1. Have 2 drop containers.
  2. Drag item from one container.
  3. Move over the items of the other container
  4. Move outside any container.
  5. Release button.

Expected Behavior

The item should transform to initial container and initial position.

Actual Behavior

The item transforms to the position of the last hovered item of the last entered container.

Environment

  • Angular: 9.0.2
  • CDK/Material: 9.1.0
  • Browser(s): Google Chrome Version 80.0.3987.116
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10 Pro
@crisbeto
Copy link
Member

I couldn't reproduce it against any of the examples from the docs, but I'm not sure I understand the instructions. At step 2 am I supposed to move one item, but then at step 3 move over all the other items?

@Achilles1515
Copy link

Achilles1515 commented Feb 25, 2020

I couldn't reproduce it against any of the examples from the docs, but I'm not sure I understand the instructions. At step 2 am I supposed to move one item, but then at step 3 move over all the other items?

He's talking about the design decision of how letting go of a dragged item will always send it back to the last sorted container, and not necessarily the initial container (which is desired in his case). It seems it would be a good option, and sort of falls under the same category of an "abort drag" feature that resets all containers back to initial state before any isDragging occured.

@crisbeto
Copy link
Member

I see. The reason why it currently works this way is that it would look weird if we snapped it back into the initial list, because there's nothing taking up the space for it anymore.

@MrPollux
Copy link
Author

@Achilles1515: You're right.

I solved it as follows:

onDragStarted(event: CdkDragStart) {
this.dragRect = event.source.element.nativeElement.getBoundingClientRect();
}

onDragReleased(event: CdkDragRelease) {
const placeholder = event.source.getPlaceholderElement();
placeholder.style.transform = "";
const rect = placeholder.getBoundingClientRect();
const x = this.dragRect.left - rect.left;
const y = this.dragRect.top - rect.top;
placeholder.style.transform = translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0);
}

I hope there would be a better way.
DropListRef._isOverContainer is private :-(

@Achilles1515
Copy link

@MrPollux Can you add your droplist event code?

@MrPollux
Copy link
Author

@mmalerba mmalerba added the needs triage This issue needs to be triaged by the team label May 20, 2020
@andrewseguin andrewseguin changed the title [drag-drop] _animatePreviewToPlaceholder transform issue feat(drag-drop): add option for items to be returned to original list if not dropped on container May 26, 2020
@andrewseguin andrewseguin added area: cdk/drag-drop feature This issue represents a new feature or feature request rather than a bug or bug fix P4 A relatively minor issue that is not relevant to core functions and removed needs triage This issue needs to be triaged by the team labels May 26, 2020
@tonyholt
Copy link

tonyholt commented Jun 21, 2020

@MrPollux, @Achilles1515, this zip file is no longer available, could you upload it again?

@angular-robot
Copy link
Contributor

angular-robot bot commented Feb 22, 2022

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@angular-robot
Copy link
Contributor

angular-robot bot commented Mar 14, 2022

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

@yusijs
Copy link

yusijs commented Sep 2, 2022

I have a similar requirement where I want to move something between two lists. I'm able to reset it by checking the isPointerOverContainer attribute, but it looks a bit weird when I'm dragging the element around, since it appears like it will land in a given container, but that's no longer the case so the behaviour gets inconsistent. Some way to define this behaviour would be really good imo (either with an input on the droplist / drag-element or via an injection token)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/drag-drop feature This issue represents a new feature or feature request rather than a bug or bug fix P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

7 participants