Skip to content

fix(tooltip): render style values in ngOnInit instead of the constructor #15468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/lib/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
InjectionToken,
Input,
NgZone,
OnInit,
OnDestroy,
Optional,
ViewContainerRef,
Expand Down Expand Up @@ -115,7 +116,7 @@ export function MAT_TOOLTIP_DEFAULT_OPTIONS_FACTORY(): MatTooltipDefaultOptions
'(touchend)': '_handleTouchend()',
},
})
export class MatTooltip implements OnDestroy {
export class MatTooltip implements OnDestroy, OnInit {
_overlayRef: OverlayRef | null;
_tooltipInstance: TooltipComponent | null;

Expand Down Expand Up @@ -256,6 +257,30 @@ export class MatTooltip implements OnDestroy {
});
}

/**
* Setup styling-specific things
*/
ngOnInit() {
const element = this._elementRef.nativeElement;
const elementStyle = element.style as CSSStyleDeclaration & {webkitUserDrag: string};

if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
// When we bind a gesture event on an element (in this case `longpress`), HammerJS
// will add some inline styles by default, including `user-select: none`. This is
// problematic on iOS and in Safari, because it will prevent users from typing in inputs.
// Since `user-select: none` is not needed for the `longpress` event and can cause unexpected
// behavior for text fields, we always clear the `user-select` to avoid such issues.
elementStyle.webkitUserSelect = elementStyle.userSelect = elementStyle.msUserSelect = '';
}

// 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 && elementStyle.webkitUserDrag === 'none') {
elementStyle.webkitUserDrag = '';
}
}

/**
* Dispose the tooltip when destroyed.
*/
Expand Down