MCPcopy Create free account
hub / github.com/angular/components / constructor

Method constructor

src/cdk/dialog/dialog-ref.ts:62–95  ·  view source on GitHub ↗
(
    readonly overlayRef: OverlayRef,
    readonly config: DialogConfig<any, DialogRef<R, C>, DialogContainer>,
  )

Source from the content-addressed store, hash-verified

60 private _detachSubscription: Subscription;
61
62 constructor(
63 readonly overlayRef: OverlayRef,
64 readonly config: DialogConfig<any, DialogRef<R, C>, DialogContainer>,
65 ) {
66 this.disableClose = config.disableClose;
67 this.backdropClick = overlayRef.backdropClick();
68 this.keydownEvents = overlayRef.keydownEvents();
69 this.outsidePointerEvents = overlayRef.outsidePointerEvents();
70 this.id = config.id!; // By the time the dialog is created we are guaranteed to have an ID.
71
72 this.keydownEvents.subscribe(event => {
73 if (event.keyCode === ESCAPE && !this.disableClose && !hasModifierKey(event)) {
74 event.preventDefault();
75 this.close(undefined, {focusOrigin: 'keyboard'});
76 }
77 });
78
79 this.backdropClick.subscribe(() => {
80 if (!this.disableClose && this._canClose()) {
81 this.close(undefined, {focusOrigin: 'mouse'});
82 } else {
83 // Clicking on the backdrop will move focus out of dialog.
84 // Recapture it if closing via the backdrop is disabled.
85 this.containerInstance._recaptureFocus?.();
86 }
87 });
88
89 this._detachSubscription = overlayRef.detachments().subscribe(() => {
90 // Check specifically for `false`, because we want `undefined` to be treated like `true`.
91 if (config.closeOnOverlayDetachments !== false) {
92 this.close();
93 }
94 });
95 }
96
97 /**
98 * Close the dialog.

Callers

nothing calls this directly

Calls 8

closeMethod · 0.95
_canCloseMethod · 0.95
hasModifierKeyFunction · 0.90
outsidePointerEventsMethod · 0.80
_recaptureFocusMethod · 0.80
detachmentsMethod · 0.80
backdropClickMethod · 0.45
keydownEventsMethod · 0.45

Tested by

no test coverage detected