(
readonly overlayRef: OverlayRef,
readonly config: DialogConfig<any, DialogRef<R, C>, DialogContainer>,
)
| 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. |
nothing calls this directly
no test coverage detected