Skip to content

Commit

Permalink
fix(tooltip): interfering with native drag&drop (#12200)
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto authored and josephperrott committed Jul 17, 2018
1 parent ac9d344 commit 225438d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/lib/tooltip/tooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ describe('MatTooltip', () => {
ScrollableTooltipDemo,
OnPushTooltipDemo,
DynamicTooltipsDemo,
TooltipOnTextFields
TooltipOnTextFields,
TooltipOnDraggableElement,
],
providers: [
{provide: Platform, useFactory: () => platform},
Expand Down Expand Up @@ -795,6 +796,15 @@ describe('MatTooltip', () => {
expect(instance.textarea.nativeElement.style.userSelect).toBeFalsy();
expect(instance.textarea.nativeElement.style.webkitUserSelect).toBeFalsy();
});

it('should clear the `-webkit-user-drag` on draggable elements', () => {
const fixture = TestBed.createComponent(TooltipOnDraggableElement);

fixture.detectChanges();

expect(fixture.componentInstance.button.nativeElement.style.webkitUserDrag).toBeFalsy();
});

});

});
Expand Down Expand Up @@ -900,6 +910,20 @@ class TooltipOnTextFields {
@ViewChild('textarea') textarea: ElementRef;
}

@Component({
template: `
<button
#button
style="-webkit-user-drag: none;"
draggable="true"
matTooltip="Drag me"></button>
`,
})
class TooltipOnDraggableElement {
@ViewChild('button') button: ElementRef;
}


/** Asserts whether a tooltip directive has a tooltip instance. */
function assertTooltipInstance(tooltip: MatTooltip, shouldExist: boolean): void {
// Note that we have to cast this to a boolean, because Jasmine will go into an infinite loop
Expand Down
7 changes: 7 additions & 0 deletions src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ export class MatTooltip implements OnDestroy {
element.style.webkitUserSelect = element.style.userSelect = '';
}

// Hammer applies `-webkit-user-drag: none` on all elements by default,
// which breaks the native drag&drop. If the consumer explicitly made
// the element draggable, clear the `-webkit-user-drag`.
if (element.draggable && element.style['webkitUserDrag'] === 'none') {
element.style['webkitUserDrag'] = '';
}

_focusMonitor.monitor(element).pipe(takeUntil(this._destroyed)).subscribe(origin => {
// Note that the focus monitor runs outside the Angular zone.
if (!origin) {
Expand Down

0 comments on commit 225438d

Please sign in to comment.