Skip to content

fix(material/tooltip): resolve server-side rendering error #25728

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
Oct 3, 2022
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/material/tooltip/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ ng_module(
"//src/cdk/overlay",
"//src/cdk/portal",
"//src/material/core",
"@npm//@material/tooltip",
],
)

Expand Down
14 changes: 10 additions & 4 deletions src/material/tooltip/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
ScrollStrategy,
VerticalConnectionPos,
} from '@angular/cdk/overlay';
import {numbers} from '@material/tooltip';
import {ComponentPortal} from '@angular/cdk/portal';
import {Observable, Subject} from 'rxjs';

Expand Down Expand Up @@ -156,6 +155,13 @@ const passiveListenerOptions = normalizePassiveListenerOptions({passive: true});
*/
const LONGPRESS_DELAY = 500;

// These constants were taken from MDC's `numbers` object. We can't import them from MDC,
// because they have some top-level references to `window` which break during SSR.
const MIN_VIEWPORT_TOOLTIP_THRESHOLD = 8;
const UNBOUNDED_ANCHOR_GAP = 8;
const MIN_HEIGHT = 24;
const MAX_WIDTH = 200;

@Directive()
export abstract class _MatTooltipBase<T extends _TooltipComponentBase>
implements OnDestroy, AfterViewInit
Expand Down Expand Up @@ -879,11 +885,11 @@ export class MatTooltip extends _MatTooltipBase<TooltipComponent> {
defaultOptions,
_document,
);
this._viewportMargin = numbers.MIN_VIEWPORT_TOOLTIP_THRESHOLD;
this._viewportMargin = MIN_VIEWPORT_TOOLTIP_THRESHOLD;
}

protected override _addOffset(position: ConnectedPosition): ConnectedPosition {
const offset = numbers.UNBOUNDED_ANCHOR_GAP;
const offset = UNBOUNDED_ANCHOR_GAP;
const isLtr = !this._dir || this._dir.value == 'ltr';

if (position.originY === 'top') {
Expand Down Expand Up @@ -1133,6 +1139,6 @@ export class TooltipComponent extends _TooltipComponentBase {
/** Whether the tooltip text has overflown to the next line */
private _isTooltipMultiline() {
const rect = this._elementRef.nativeElement.getBoundingClientRect();
return rect.height > numbers.MIN_HEIGHT && rect.width >= numbers.MAX_WIDTH;
return rect.height > MIN_HEIGHT && rect.width >= MAX_WIDTH;
}
}