Skip to content

Commit fc67ff3

Browse files
authored
fix(drag-drop): remove redundant style changes from handle directive (#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.
1 parent 2058f71 commit fc67ff3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/cdk/drag-drop/directives/drag-handle.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from '@angular/core';
2020
import {Subject} from 'rxjs';
2121
import {CDK_DRAG_PARENT} from '../drag-parent';
22-
import {toggleNativeDragInteractions} from '../drag-styling';
2322

2423
/**
2524
* Injection token that can be used to reference instances of `CdkDragHandle`. It serves as
@@ -55,9 +54,7 @@ export class CdkDragHandle implements OnDestroy {
5554
constructor(
5655
public element: ElementRef<HTMLElement>,
5756
@Inject(CDK_DRAG_PARENT) @Optional() @SkipSelf() parentDrag?: any) {
58-
5957
this._parentDrag = parentDrag;
60-
toggleNativeDragInteractions(element.nativeElement, false);
6158
}
6259

6360
ngOnDestroy() {

src/cdk/drag-drop/directives/drag.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,20 @@ describe('CdkDrag', () => {
713713
}).not.toThrow();
714714
}));
715715

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

723+
it('should disable native drag interactions on the drag handle', () => {
724+
const fixture = createComponent(StandaloneDraggableWithHandle);
725+
fixture.detectChanges();
726+
const styles = fixture.componentInstance.handleElement.nativeElement.style;
727+
expect(styles.touchAction || (styles as any).webkitUserDrag).toBe('none');
728+
});
729+
723730
it('should be able to reset a freely-dragged item to its initial position', fakeAsync(() => {
724731
const fixture = createComponent(StandaloneDraggable);
725732
fixture.detectChanges();

0 commit comments

Comments
 (0)