Skip to content

fix(drag-drop): not picking up handle that isn't a direct descendant #13360

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

Merged
merged 1 commit into from
Oct 19, 2018

Conversation

crisbeto
Copy link
Member

Fixes not being able to have a drag handle that isn't a direct descendant of CdkDrag.

Fixes #13335.

@crisbeto crisbeto added the target: major This PR is targeted for the next major release label Sep 29, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 29, 2018
@crisbeto crisbeto force-pushed the 13335/drag-indirect-handle branch from 7c5ec03 to 07e9b8d Compare September 29, 2018 09:32
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn
Copy link
Member

jelbourn commented Oct 2, 2018

Just needs rebase

@ngbot
Copy link

ngbot bot commented Oct 5, 2018

Hi @crisbeto! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

@crisbeto crisbeto force-pushed the 13335/drag-indirect-handle branch from 07e9b8d to ca8ce11 Compare October 7, 2018 08:50
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Oct 7, 2018
@crisbeto
Copy link
Member Author

crisbeto commented Oct 7, 2018

This one's good to go now.

Fixes not being able to have a drag handle that isn't a direct descendant of `CdkDrag`.

Fixes angular#13335.
@crisbeto crisbeto force-pushed the 13335/drag-indirect-handle branch from ca8ce11 to 6074ff4 Compare October 9, 2018 10:51
@dakotamaker
Copy link

dakotamaker commented Oct 12, 2018

Hello @crisbeto I have an issue (stackblitz preview) that could be solved by the merging of this PR, just was curious if you all had an estimate of when this would go in since I see it's been good to go for 5 days. Thanks!

@crisbeto crisbeto added target: patch This PR is targeted for the next patch release and removed target: major This PR is targeted for the next major release labels Oct 18, 2018
@josephperrott josephperrott merged commit c38ebb6 into angular:master Oct 19, 2018
@wendelstam
Copy link

Do the same thing apply to to CdkDrag in relation to CdkDropList i.e. can a CdkDropList parent have projected content containing CdrDrag (and CdkDragHandle)?

@crisbeto
Copy link
Member Author

crisbeto commented Oct 20, 2018

Each CdkDrag instance looks up the DI tree until it finds a CdkDropList.

@wendelstam
Copy link

wendelstam commented Oct 20, 2018

Great but just to clarify, so there are no problem using a ngFor in a CdkDropList that loads the content through an ngTemplate ref (that containt the CdkDrag and CdkDragHandle?

@crisbeto
Copy link
Member Author

crisbeto commented Oct 20, 2018

Having it in an ngFor definitely works, but I'm not too sure about your ngTemplate example. AFAIK the template's position in the DOM determines whether it'll be able to pick up the drop container.

@wendelstam
Copy link

FYI:
I tested it and it does not work when having the CdkDrag inside content projected through an ng-template.

This show the non-working scenario.
https://stackblitz.com/edit/angular-zttfez?embed=1&file=app/cdk-drag-drop-custom-preview-example.html

@crisbeto
Copy link
Member Author

It doesn't work because the ng-template has no way of knowing about the cdkDropList. You can get it to work by moving it into the drop list:

<div cdkDropList class="example-list" (cdkDropListDropped)="drop($event)">
	<ng-container *ngTemplateOutlet="content"></ng-container>

	<ng-template #content>
		<div class="example-box" *ngFor="let movie of movies" cdkDrag>
			{{movie.title}}
		</div>
	</ng-template>
</div>

@shyamal890
Copy link

This is not working: https://stackblitz.com/edit/material-handle-issue

@crisbeto
Copy link
Member Author

@shyamal890 that's not the case that is described here. There's no way for us to manage the one you posted, because one component can't "reach into" the template of another component in order to get a reference to the handle.

@xaqbr
Copy link

xaqbr commented Jan 20, 2019

@shyamal890 that's not the case that is described here. There's no way for us to manage the one you posted, because one component can't "reach into" the template of another component in order to get a reference to the handle.

So much for splitting up components then.

@crisbeto
Copy link
Member Author

#14437 will add a bit more flexibility.

@willbeaufoy
Copy link
Contributor

willbeaufoy commented Feb 6, 2019

@shyamal890 that's not the case that is described here. There's no way for us to manage the one you posted, because one component can't "reach into" the template of another component in order to get a reference to the handle.

@crisbeto Does this mean we cannot currently have the cdkDropList in a parent component and the cdkDrag/cdkDragHandle in a child component? When I try this it doesn't work. If this isn't possible, will #14437 allow us to do this?

@ghost
Copy link

ghost commented Feb 13, 2019

It helped me, hope it helps you guys.
===== BEFORE =====

<container>
    <files-container>
        <ng-container *ngFor="let file of files>
            <files-container-item *ngIf="allowReorder" cdkDrag>
            </files-container-item>
        </ng-container>
</files-container>
<container>

My drag handle was inside files-container-item component, which did NOT work.
<div class="uploaded-file__drag-handle" cdkDragHandle></div>
===== AFTER =====

<container>
    <files-container>
        <ng-container *ngFor="let file of files>
            <files-container-item *ngIf="allowReorder" cdkDrag>
                <div slot="drag-handle" class="uploaded-file__drag-handle" cdkDragHandle></div>
            </files-container-item>
        </ng-container>
</files-container>
<container>

Now INSIDE child files-container-item component where the old drag handle used to be I put:

<ng-container *ngIf="allowReorder">
    <ng-content select="[slot=drag-handle]">
    </ng-content>
</ng-container>

What we did to make it work was to move dragHandle out of child component into parent with SLOT parameter, and in child component have ng-content with select a SLOT.

ulferts added a commit to opf/openproject that referenced this pull request Jul 12, 2019
@Allisone
Copy link

What's the current status on that ?

@shyamal890 that's not the case that is described here. There's no way for us to manage the one you posted, because one component can't "reach into" the template of another component in order to get a reference to the handle.

@crisbeto Does this mean we cannot currently have the cdkDropList in a parent component and the cdkDrag/cdkDragHandle in a child component? When I try this it doesn't work. If this isn't possible, will #14437 allow us to do this?

What's the status ? I need this too. In my dashboard component I have a list of widget configurations, each widget configuration is passed to a widget component, that component has a header, that header should be my handle. The cdkDropList is of course in the dashboard component attached to a div.row. The cdkDragHandle is on my header inside of the widget component. I think this is a common use case, and it's very unfortunate that right now the cdkDragHandle is ignored and no way around.

@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 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cdkDragHandle not working if it's not a direct child of cdkDrag
10 participants