Skip to content

Commit

Permalink
fix(drag-drop): remove redundant style changes from handle directive (#…
Browse files Browse the repository at this point in the history
…20330)

This came up from #19919, although it's not the root cause. We were disabling the native drag interactions on the handle element in two places which is redundant. These changes remove one of them and add a unit test since we were missing coverage.
  • Loading branch information
crisbeto committed Aug 20, 2020
1 parent 2058f71 commit fc67ff3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions src/cdk/drag-drop/directives/drag-handle.ts
Expand Up @@ -19,7 +19,6 @@ import {
} from '@angular/core';
import {Subject} from 'rxjs';
import {CDK_DRAG_PARENT} from '../drag-parent';
import {toggleNativeDragInteractions} from '../drag-styling';

/**
* Injection token that can be used to reference instances of `CdkDragHandle`. It serves as
Expand Down Expand Up @@ -55,9 +54,7 @@ export class CdkDragHandle implements OnDestroy {
constructor(
public element: ElementRef<HTMLElement>,
@Inject(CDK_DRAG_PARENT) @Optional() @SkipSelf() parentDrag?: any) {

this._parentDrag = parentDrag;
toggleNativeDragInteractions(element.nativeElement, false);
}

ngOnDestroy() {
Expand Down
9 changes: 8 additions & 1 deletion src/cdk/drag-drop/directives/drag.spec.ts
Expand Up @@ -713,13 +713,20 @@ describe('CdkDrag', () => {
}).not.toThrow();
}));

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

it('should disable native drag interactions on the drag handle', () => {
const fixture = createComponent(StandaloneDraggableWithHandle);
fixture.detectChanges();
const styles = fixture.componentInstance.handleElement.nativeElement.style;
expect(styles.touchAction || (styles as any).webkitUserDrag).toBe('none');
});

it('should be able to reset a freely-dragged item to its initial position', fakeAsync(() => {
const fixture = createComponent(StandaloneDraggable);
fixture.detectChanges();
Expand Down

0 comments on commit fc67ff3

Please sign in to comment.