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

fix(drag-drop): only call enterPredicate when pointer is inside drop list #17310

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/cdk/drag-drop/directives/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3518,6 +3518,33 @@ describe('CdkDrag', () => {
expect(spy).toHaveBeenCalledWith(dragItem, dropInstances[1]);
}));

it('should not call the `enterPredicate` if the pointer is not over the container',
fakeAsync(() => {
const fixture = createComponent(ConnectedDropZones);
fixture.detectChanges();

const dropInstances = fixture.componentInstance.dropInstances.toArray();
const spy = jasmine.createSpy('enterPredicate spy').and.returnValue(true);
const groups = fixture.componentInstance.groupedDragItems.slice();
const dragElement = groups[0][1].element.nativeElement;
const targetRect = groups[1][2].element.nativeElement.getBoundingClientRect();

dropInstances[1].enterPredicate = spy;
fixture.detectChanges();

startDraggingViaMouse(fixture, dragElement);

dispatchMouseEvent(document, 'mousemove', targetRect.left - 1, targetRect.top - 1);
fixture.detectChanges();

expect(spy).not.toHaveBeenCalled();

dispatchMouseEvent(document, 'mousemove', targetRect.left + 1, targetRect.top + 1);
fixture.detectChanges();

expect(spy).toHaveBeenCalledTimes(1);
}));

it('should be able to start dragging after an item has been transferred', fakeAsync(() => {
const fixture = createComponent(ConnectedDropZones);
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/drag-drop/drop-list-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ export class DropListRef<T = any> {
* @param y Position of the item along the Y axis.
*/
_canReceive(item: DragRef, x: number, y: number): boolean {
if (!this.enterPredicate(item, this) || !isInsideClientRect(this._clientRect, x, y)) {
if (!isInsideClientRect(this._clientRect, x, y) || !this.enterPredicate(item, this)) {
return false;
}

Expand Down