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

Function _openOverlay

src/material/datepicker/datepicker-base.ts:731–795  ·  view source on GitHub ↗

Opens the overlay with the calendar.

()

Source from the content-addressed store, hash-verified

729
730 /** Opens the overlay with the calendar. */
731 private _openOverlay(): void {
732 this._destroyOverlay();
733
734 const isDialog = this.touchUi;
735 const portal = new ComponentPortal<MatDatepickerContent<S, D>>(
736 MatDatepickerContent,
737 this._viewContainerRef,
738 );
739 const overlayRef = (this._overlayRef = createOverlayRef(
740 this._injector,
741 new OverlayConfig({
742 positionStrategy: isDialog ? this._getDialogStrategy() : this._getDropdownStrategy(),
743 hasBackdrop: true,
744 backdropClass: [
745 isDialog ? 'cdk-overlay-dark-backdrop' : 'mat-overlay-transparent-backdrop',
746 this._backdropHarnessClass,
747 ],
748 direction: this._dir || 'ltr',
749 scrollStrategy: isDialog
750 ? createBlockScrollStrategy(this._injector)
751 : this._scrollStrategy(),
752 panelClass: `mat-datepicker-${isDialog ? 'dialog' : 'popup'}`,
753 disableAnimations: this._animationsDisabled,
754 }),
755 ));
756
757 this._getCloseStream(overlayRef).subscribe(event => {
758 if (event) {
759 event.preventDefault();
760 }
761 this.close();
762 });
763
764 // The `preventDefault` call happens inside the calendar as well, however focus moves into
765 // it inside a timeout which can give browsers a chance to fire off a keyboard event in-between
766 // that can scroll the page (see #24969). Always block default actions of arrow keys for the
767 // entire overlay so the page doesn't get scrolled by accident.
768 overlayRef.keydownEvents().subscribe(event => {
769 const keyCode = event.keyCode;
770
771 if (
772 keyCode === UP_ARROW ||
773 keyCode === DOWN_ARROW ||
774 keyCode === LEFT_ARROW ||
775 keyCode === RIGHT_ARROW ||
776 keyCode === PAGE_UP ||
777 keyCode === PAGE_DOWN
778 ) {
779 event.preventDefault();
780 }
781 });
782
783 this._componentRef = overlayRef.attach(portal);
784 this._forwardContentValues(this._componentRef.instance);
785
786 // Update the position once the calendar has rendered. Only relevant in dropdown mode.
787 if (!isDialog) {
788 afterNextRender(

Callers

nothing calls this directly

Calls 7

createOverlayRefFunction · 0.90
_forwardContentValuesMethod · 0.80
attachMethod · 0.65
closeMethod · 0.45
keydownEventsMethod · 0.45
updatePositionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…