Skip to content

Commit 4d489f0

Browse files
crisbetommalerba
authored andcommitted
fix(cdk/drag-drop): dragging styles not reset once dragging is… (#17150)
When the user starts dragging an element we set some styles on it in order to prevent some native interactions like text selection, however we never reset them which can prevent the user from being able to start dragging from the same element afterwards. Fixes #17139. (cherry picked from commit e62e6bd)
1 parent 6fb6bda commit 4d489f0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,24 @@ describe('CdkDrag', () => {
637637
expect(styles.touchAction || (styles as any).webkitUserDrag).toBe('none');
638638
}));
639639

640+
it('should re-enable drag interactions once dragging is over', fakeAsync(() => {
641+
const fixture = createComponent(StandaloneDraggable);
642+
fixture.detectChanges();
643+
const dragElement = fixture.componentInstance.dragElement.nativeElement;
644+
const styles = dragElement.style;
645+
646+
startDraggingViaMouse(fixture, dragElement);
647+
dispatchMouseEvent(document, 'mousemove', 50, 100);
648+
fixture.detectChanges();
649+
650+
expect(styles.touchAction || (styles as any).webkitUserDrag).toBe('none');
651+
652+
dispatchMouseEvent(document, 'mouseup', 50, 100);
653+
fixture.detectChanges();
654+
655+
expect(styles.touchAction || (styles as any).webkitUserDrag).toBeFalsy();
656+
}));
657+
640658
it('should stop propagation for the drag sequence start event', fakeAsync(() => {
641659
const fixture = createComponent(StandaloneDraggable);
642660
fixture.detectChanges();

src/cdk/drag-drop/drag-ref.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ export class DragRef<T = any> {
619619

620620
this._removeSubscriptions();
621621
this._dragDropRegistry.stopDragging(this);
622+
this._toggleNativeDragInteractions();
622623

623624
if (this._handles) {
624625
this._rootElement.style.webkitTapHighlightColor = this._rootElementTapHighlight;

0 commit comments

Comments
 (0)