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

bug:(@angular/cdk/drag-drop): Cannot read property 'clientRect' of undefined #13077

Closed
kanidjar opened this issue Sep 11, 2018 · 28 comments · Fixed by #16081
Closed

bug:(@angular/cdk/drag-drop): Cannot read property 'clientRect' of undefined #13077

kanidjar opened this issue Sep 11, 2018 · 28 comments · Fixed by #16081
Assignees
Labels
P4 A relatively minor issue that is not relevant to core functions

Comments

@kanidjar
Copy link

Bug, feature request, or proposal:

BUG: when drag-dropping an item between two connected dropzone, an error occurs randomly

See video and image below

https://streamable.com/nuudt

error

What is the expected behavior?

No error should occur.

What is the current behavior?

An error occurs randomly as soon as an item enters in the dropzone. The (dropped) event happens anyway.

What are the steps to reproduce?

Classic connected dropzones.

My dropzones are not in the same component.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

"@angular/cdk": "^7.0.0-beta.0"
"@angular/material": "^6.4.7"
"@angular/core": "^6.1.6",

Is there anything else we should know?

The error is located in drag-drop.es5.js.CdkDrop._sortItem (drag-drop.es5.js:1436)

var currentPosition = siblings[currentIndex].clientRect;
@josephperrott josephperrott added the P4 A relatively minor issue that is not relevant to core functions label Sep 11, 2018
@kanidjar
Copy link
Author

kanidjar commented Sep 13, 2018

FYI: the error occurs when adding the 2nd "List" item.

@crisbeto
Copy link
Member

It's hard to tell what's going on based on the video. Based on the stack trace, it looks like a CdkDrag somehow ended up in the wrong container, but I can't think of any obvious place where it could happen. @kanidjar would you be able to put together a simplified example that breaks?

@kanidjar
Copy link
Author

@crisbeto

here it is : https://stackblitz.com/edit/angular-uhe5x7

Try to drop a same item twice in the red zone.

@crisbeto
Copy link
Member

Thanks for the reproduction @kanidjar. It looks like the issue was fixed in master already.

@kanidjar
Copy link
Author

Nice, thank you @crisbeto

@dakotamaker
Copy link

@crisbeto what was the fix exactly? I'm still seeing this issue and I am on the newest version of the cdk

@crisbeto
Copy link
Member

@dakotamaker it's been a while so I don't remember. I think I tried out the Stackblitz against master and the issue just wasn't there.

@jurStv
Copy link

jurStv commented Oct 22, 2018

I'm facing same issue. Did you find any way to resolve this one @kanidjar?

@antonpegov
Copy link

I'm getting this error when applying [cdkDropList] directive it the parent component and [cdkDragData] in it's childrens. When everything in the one component, then no errors.

@birjitningomba
Copy link

I'm getting this error when applying [cdkDropList] directive it the parent component and [cdkDragData] in it's childrens. When everything in the one component, then no errors.

Yes, I am facing the same, is there a solution for this?

@birjitningomba
Copy link

birjitningomba commented Nov 17, 2018

@crisbeto I am trying to sort or dragdrop dynamically generated components. The container has the cdkDropList directive while the dynamically components has the cdkDrag directive and I would expect it works, It is simply not working.

[Parent Component that holds a container for the dynamic child component to insert.]

<div (cdkDropListDropped)="drop($event)" class="example-list"  cdkDropList>
    <ng-template   #container  ></ng-template>
</div>

[HTML of the child component that would be inserted in the container.]

<mat-card class="sample-chips" cdkDrag>
	<mat-card-title>{{chipData.chipName}} </mat-card-title>
	<mat-card-content> <b>{{chipData.chipFlavour}}</b> </mat-card-content>
</mat-card>

@birjitningomba
Copy link

The drag & drop is a great feature, In my opinion it should be not only with simple list that we can drag and drop but also components and more specific to dynamic components. I am sure the usage of dynamic components may be limited scope but this is where Angular is helping new developers like us achive a lot of things quickly and easily. I do not understand the priority of the bugs but to me this bug should be raised to a higher priority. @crisbeto please comment.

@millerlight
Copy link

millerlight commented Dec 1, 2018

same problems here with mat-table as cdkDropList and mat-row inside as cdkDrag

this means that the new drag&drop api in angular7.1 is not usable with mat-tables which is sad, because i need this features...

@millerlight
Copy link

btw. only dragging of mat-tables works fine....

@JesseZomer
Copy link

JesseZomer commented Dec 11, 2018

I'm having the same problem using "@angular/cdk": "^7.1.1". Why was this issue closed?

I'm getting this while having the cdkDropList and cdkDrag directives spread over multiple components and child components. While having a parent with the cdkDropListGroup directive.

edit: the issues seems to resolve when I put the cdkDrag directives on the child-component selectors in the same html as the component instead of inside the html of the child component.

@cantastage
Copy link

cantastage commented Dec 12, 2018

Hello. Same problem with "@angular/cdk": "^7.1.1". I have a component with two connected cdkDropList. One list is filled with dynamically generated components that contain the cdkDrag directive in the template. When I try to drag one of these elements the error appears.

edit: solved following @JesseZomer hint:

edit: the issues seems to resolve when I put the cdkDrag directives on the child-component selectors in the same html as the component instead of inside the html of the child component.

@millerlight
Copy link

for me the problem is not solved.
here is a small test project.
problem is in the first table in home.component

@davidecavestro
Copy link

davidecavestro commented Jan 9, 2019

I reproduce it adding D&D to move reactive form controls (siblings dynamically added to a single form within a single angular component).
@JesseZomer or @cantastage could you please elaborate on the workaround you've found?

@jheyl
Copy link

jheyl commented Jan 16, 2019

Hey,
I stumbled upon this thread because I have the exact same the Problem when I use the cdkDrag Directive on a span inside a ngb-panel.

Using the exact same code inside a <ul>-element without the ngb-container works without any problems.

@amumm
Copy link

amumm commented Jan 24, 2019

I am experiencing the same issued. I need to be able to call the (cdkDragDropped) event within the child component, but this error makes it so the cdkDropList does not recognize the cdkDrop when in separate components.

@waniashik
Copy link

I am struggling with the same issue, has this issue been fixed?

@zhaodong-wang
Copy link

FYI, it seems that I added opacity: 1 to the draggable items and the error disappears. Not sure why.

@andyrue
Copy link
Contributor

andyrue commented Feb 28, 2019

I added a cdkDragHandle to an element inside my draggable component and I no longer got this error.

@xdevnull
Copy link

Any fix?

@ibenjelloun
Copy link

I'm reproducing this error on the stackblitz example from angular.io :
https://stackblitz.com/angular/dgxqejknvgg?file=app%2Fcdk-drag-drop-sorting-example.ts

cdk-drag-drop-clientRectOfUndefined

crisbeto added a commit to crisbeto/material2 that referenced this issue May 21, 2019
…s finishing

Fixes an error being thrown if the user manages to start a different drag sequence while the previous one is finishing. The error comes from the fact that some elements are still being moved around while we're waiting for the previous animation to finish.

Fixes angular#13077.
crisbeto added a commit to crisbeto/material2 that referenced this issue May 21, 2019
…s finishing

Fixes an error being thrown if the user manages to start a different drag sequence while the previous one is finishing. The error comes from the fact that some elements are still being moved around while we're waiting for the previous animation to finish.

Fixes angular#13077.
@AlyRadwan2020
Copy link

AlyRadwan2020 commented Jul 13, 2019

image

@kflo
Copy link

kflo commented Aug 17, 2019

bump ...

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.