Skip to content

Commit 19f64ad

Browse files
crisbetojosephperrott
authored andcommitted
fix(tooltip): interfering with native drag&drop (#12200)
1 parent 19326f7 commit 19f64ad

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/lib/tooltip/tooltip.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ describe('MatTooltip', () => {
5454
ScrollableTooltipDemo,
5555
OnPushTooltipDemo,
5656
DynamicTooltipsDemo,
57-
TooltipOnTextFields
57+
TooltipOnTextFields,
58+
TooltipOnDraggableElement,
5859
],
5960
providers: [
6061
{provide: Platform, useFactory: () => platform},
@@ -795,6 +796,15 @@ describe('MatTooltip', () => {
795796
expect(instance.textarea.nativeElement.style.userSelect).toBeFalsy();
796797
expect(instance.textarea.nativeElement.style.webkitUserSelect).toBeFalsy();
797798
});
799+
800+
it('should clear the `-webkit-user-drag` on draggable elements', () => {
801+
const fixture = TestBed.createComponent(TooltipOnDraggableElement);
802+
803+
fixture.detectChanges();
804+
805+
expect(fixture.componentInstance.button.nativeElement.style.webkitUserDrag).toBeFalsy();
806+
});
807+
798808
});
799809

800810
});
@@ -900,6 +910,20 @@ class TooltipOnTextFields {
900910
@ViewChild('textarea') textarea: ElementRef;
901911
}
902912

913+
@Component({
914+
template: `
915+
<button
916+
#button
917+
style="-webkit-user-drag: none;"
918+
draggable="true"
919+
matTooltip="Drag me"></button>
920+
`,
921+
})
922+
class TooltipOnDraggableElement {
923+
@ViewChild('button') button: ElementRef;
924+
}
925+
926+
903927
/** Asserts whether a tooltip directive has a tooltip instance. */
904928
function assertTooltipInstance(tooltip: MatTooltip, shouldExist: boolean): void {
905929
// Note that we have to cast this to a boolean, because Jasmine will go into an infinite loop

src/lib/tooltip/tooltip.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ export class MatTooltip implements OnDestroy {
223223
element.style.webkitUserSelect = element.style.userSelect = '';
224224
}
225225

226+
// Hammer applies `-webkit-user-drag: none` on all elements by default,
227+
// which breaks the native drag&drop. If the consumer explicitly made
228+
// the element draggable, clear the `-webkit-user-drag`.
229+
if (element.draggable && element.style['webkitUserDrag'] === 'none') {
230+
element.style['webkitUserDrag'] = '';
231+
}
232+
226233
_focusMonitor.monitor(element).pipe(takeUntil(this._destroyed)).subscribe(origin => {
227234
// Note that the focus monitor runs outside the Angular zone.
228235
if (!origin) {

0 commit comments

Comments
 (0)