MCPcopy Index your code
hub / github.com/angular/components / _createOverlay

Method _createOverlay

src/material/tooltip/tooltip.ts:498–584  ·  view source on GitHub ↗

Create the overlay config and position strategy

(origin?: {x: number; y: number})

Source from the content-addressed store, hash-verified

496
497 /** Create the overlay config and position strategy */
498 private _createOverlay(origin?: {x: number; y: number}): OverlayRef {
499 if (this._overlayRef) {
500 const existingStrategy = this._overlayRef.getConfig()
501 .positionStrategy as FlexibleConnectedPositionStrategy;
502
503 if ((!this.positionAtOrigin || !origin) && existingStrategy._origin instanceof ElementRef) {
504 return this._overlayRef;
505 }
506
507 this._detach();
508 }
509
510 const scrollableAncestors = this._injector
511 .get(ScrollDispatcher)
512 .getAncestorScrollContainers(this._elementRef);
513
514 const panelClass = `${this._cssClassPrefix}-${PANEL_CLASS}`;
515
516 // Create connected position strategy that listens for scroll events to reposition.
517 const strategy = createFlexibleConnectedPositionStrategy(
518 this._injector,
519 this.positionAtOrigin ? origin || this._elementRef : this._elementRef,
520 )
521 .withTransformOriginOn(`.${this._cssClassPrefix}-tooltip`)
522 .withFlexibleDimensions(false)
523 .withViewportMargin(this._viewportMargin)
524 .withScrollableContainers(scrollableAncestors)
525 .withPopoverLocation('global');
526
527 strategy.positionChanges.pipe(takeUntil(this._destroyed)).subscribe(change => {
528 this._updateCurrentPositionClass(change.connectionPair);
529
530 if (this._tooltipInstance) {
531 if (change.scrollableViewProperties.isOverlayClipped && this._tooltipInstance.isVisible()) {
532 // After position changes occur and the overlay is clipped by
533 // a parent scrollable then close the tooltip.
534 this._ngZone.run(() => this.hide(0));
535 }
536 }
537 });
538
539 this._overlayRef = createOverlayRef(this._injector, {
540 direction: this._dir,
541 positionStrategy: strategy,
542 panelClass: this._overlayPanelClass ? [...this._overlayPanelClass, panelClass] : panelClass,
543 scrollStrategy: this._injector.get(MAT_TOOLTIP_SCROLL_STRATEGY)(),
544 disableAnimations: this._animationsDisabled,
545 eventPredicate: this._overlayEventPredicate,
546 });
547
548 this._updatePosition(this._overlayRef);
549
550 this._overlayRef
551 .detachments()
552 .pipe(takeUntil(this._destroyed))
553 .subscribe(() => this._detach());
554
555 this._overlayRef

Callers 2

showMethod · 0.95
_openMenuFunction · 0.45

Calls 15

_detachMethod · 0.95
hideMethod · 0.95
_updatePositionMethod · 0.95
createOverlayRefFunction · 0.90
getConfigMethod · 0.80
withPopoverLocationMethod · 0.80
withViewportMarginMethod · 0.80

Tested by

no test coverage detected