Skip to content

fix(drag-drop): enable drag interactions when there is a drag handle #13780

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
Nov 7, 2018
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
8 changes: 8 additions & 0 deletions src/cdk/drag-drop/drag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ describe('CdkDrag', () => {
}).not.toThrow();
}));

it('should not disable native drag interactions when there is a drag handle', () => {
const fixture = createComponent(StandaloneDraggableWithHandle);
fixture.detectChanges();
const dragElement = fixture.componentInstance.dragElement.nativeElement;
expect(dragElement.style.touchAction)
.not.toEqual('none', 'should not disable touchAction on when there is a drag handle');
});

});

describe('draggable with a handle', () => {
Expand Down
13 changes: 9 additions & 4 deletions src/cdk/drag-drop/drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '@angular/core';
import {normalizePassiveListenerOptions} from '@angular/cdk/platform';
import {Observable, Subject, Subscription, Observer} from 'rxjs';
import {take} from 'rxjs/operators';
import {startWith, take} from 'rxjs/operators';
import {DragDropRegistry} from './drag-drop-registry';
import {
CdkDragDrop,
Expand Down Expand Up @@ -274,7 +274,8 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
const rootElement = this._rootElement = this._getRootElement();
rootElement.addEventListener('mousedown', this._pointerDown, passiveEventListenerOptions);
rootElement.addEventListener('touchstart', this._pointerDown, passiveEventListenerOptions);
toggleNativeDragInteractions(rootElement , false);
this._handles.changes.pipe(startWith(null)).subscribe(() =>
toggleNativeDragInteractions(rootElement, this.getChildHandles().length > 0));
});
}

Expand Down Expand Up @@ -309,10 +310,14 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
return this._dragDropRegistry.isDragging(this);
}

/** Gets only handles that are not inside descendant `CdkDrag` instances. */
private getChildHandles() {
return this._handles.filter(handle => handle._parentDrag === this);
}

/** Handler for the `mousedown`/`touchstart` events. */
_pointerDown = (event: MouseEvent | TouchEvent) => {
// Skip handles inside descendant `CdkDrag` instances.
const handles = this._handles.filter(handle => handle._parentDrag === this);
const handles = this.getChildHandles();

// Delegate the event based on whether it started from a handle or the element itself.
if (handles.length) {
Expand Down