Skip to content

Commit

Permalink
feat(tooltip): Adjusting tooltip positioning logic so that the toolti…
Browse files Browse the repository at this point in the history
…p remains within the viewport even if the anchor element is partially off-screen.

PiperOrigin-RevId: 342884128
  • Loading branch information
sayris authored and copybara-github committed Nov 17, 2020
1 parent d8a3aed commit 482ff90
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/mdc-tooltip/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,14 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
// Indicates that all potential positions would result in the tooltip
// colliding with the viewport. This would only occur when the anchor
// element itself collides with the viewport, or the viewport is very
// narrow.
return centerPos;
// narrow. In this case, we allow the tooltip to be mis-aligned from the
// anchor element.
if (anchorRect.left < 0) {
return this.minViewportTooltipThreshold;
} else {
const viewportWidth = this.adapter.getViewportWidth();
return viewportWidth - (tooltipWidth + this.minViewportTooltipThreshold);
}
}

/**
Expand Down

0 comments on commit 482ff90

Please sign in to comment.