/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { FocusMonitor, FocusTrapFactory, InteractivityChecker, } from '@angular/cdk/a11y'; import { OverlayRef } from '@angular/cdk/overlay'; import { _getFocusedElementPierceShadowDom } from '@angular/cdk/platform'; import { BasePortalOutlet, CdkPortalOutlet, } from '@angular/cdk/portal'; import { DOCUMENT } from '@angular/common'; import { ChangeDetectionStrategy, Component, ElementRef, Inject, NgZone, Optional, ViewChild, ViewEncapsulation, } from '@angular/core'; import { DialogConfig } from './dialog-config'; import * as i0 from "@angular/core"; import * as i1 from "@angular/cdk/a11y"; import * as i2 from "@angular/cdk/overlay"; import * as i3 from "@angular/cdk/portal"; export function throwDialogContentAlreadyAttachedError() { throw Error('Attempting to attach dialog content after content is already attached'); } /** * Internal component that wraps user-provided dialog content. * @docs-private */ export class CdkDialogContainer extends BasePortalOutlet { constructor(_elementRef, _focusTrapFactory, _document, _config, _interactivityChecker, _ngZone, _overlayRef, _focusMonitor) { super(); this._elementRef = _elementRef; this._focusTrapFactory = _focusTrapFactory; this._config = _config; this._interactivityChecker = _interactivityChecker; this._ngZone = _ngZone; this._overlayRef = _overlayRef; this._focusMonitor = _focusMonitor; /** Element that was focused before the dialog was opened. Save this to restore upon close. */ this._elementFocusedBeforeDialogWasOpened = null; /** * Type of interaction that led to the dialog being closed. This is used to determine * whether the focus style will be applied when returning focus to its original location * after the dialog is closed. */ this._closeInteractionType = null; /** * Queue of the IDs of the dialog's label element, based on their definition order. The first * ID will be used as the `aria-labelledby` value. We use a queue here to handle the case * where there are two or more titles in the DOM at a time and the first one is destroyed while * the rest are present. */ this._ariaLabelledByQueue = []; /** * Attaches a DOM portal to the dialog container. * @param portal Portal to be attached. * @deprecated To be turned into a method. * @breaking-change 10.0.0 */ this.attachDomPortal = (portal) => { if (this._portalOutlet.hasAttached() && (typeof ngDevMode === 'undefined' || ngDevMode)) { throwDialogContentAlreadyAttachedError(); } const result = this._portalOutlet.attachDomPortal(portal); this._contentAttached(); return result; }; this._document = _document; if (this._config.ariaLabelledBy) { this._ariaLabelledByQueue.push(this._config.ariaLabelledBy); } } _contentAttached() { this._initializeFocusTrap(); this._handleBackdropClicks(); this._captureInitialFocus(); } /** * Can be used by child classes to customize the initial focus * capturing behavior (e.g. if it's tied to an animation). */ _captureInitialFocus() { this._trapFocus(); } ngOnDestroy() { this._restoreFocus(); } /** * Attach a ComponentPortal as content to this dialog container. * @param portal Portal to be attached as the dialog content. */ attachComponentPortal(portal) { if (this._portalOutlet.hasAttached() && (typeof ngDevMode === 'undefined' || ngDevMode)) { throwDialogContentAlreadyAttachedError(); } const result = this._portalOutlet.attachComponentPortal(portal); this._contentAttached(); return result; } /** * Attach a TemplatePortal as content to this dialog container. * @param portal Portal to be attached as the dialog content. */ attachTemplatePortal(portal) { if (this._portalOutlet.hasAttached() && (typeof ngDevMode === 'undefined' || ngDevMode)) { throwDialogContentAlreadyAttachedError(); } const result = this._portalOutlet.attachTemplatePortal(portal); this._contentAttached(); return result; } // TODO(crisbeto): this shouldn't be exposed, but there are internal references to it. /** Captures focus if it isn't already inside the dialog. */ _recaptureFocus() { if (!this._containsFocus()) { this._trapFocus(); } } /** * Focuses the provided element. If the element is not focusable, it will add a tabIndex * attribute to forcefully focus it. The attribute is removed after focus is moved. * @param element The element to focus. */ _forceFocus(element, options) { if (!this._interactivityChecker.isFocusable(element)) { element.tabIndex = -1; // The tabindex attribute should be removed to avoid navigating to that element again this._ngZone.runOutsideAngular(() => { const callback = () => { element.removeEventListener('blur', callback); element.removeEventListener('mousedown', callback); element.removeAttribute('tabindex'); }; element.addEventListener('blur', callback); element.addEventListener('mousedown', callback); }); } element.focus(options); } /** * Focuses the first element that matches the given selector within the focus trap. * @param selector The CSS selector for the element to set focus to. */ _focusByCssSelector(selector, options) { let elementToFocus = this._elementRef.nativeElement.querySelector(selector); if (elementToFocus) { this._forceFocus(elementToFocus, options); } } /** * Moves the focus inside the focus trap. When autoFocus is not set to 'dialog', if focus * cannot be moved then focus will go to the dialog container. */ _trapFocus() { const element = this._elementRef.nativeElement; // If were to attempt to focus immediately, then the content of the dialog would not yet be // ready in instances where change detection has to run first. To deal with this, we simply // wait for the microtask queue to be empty when setting focus when autoFocus isn't set to // dialog. If the element inside the dialog can't be focused, then the container is focused // so the user can't tab into other elements behind it. switch (this._config.autoFocus) { case false: case 'dialog': // Ensure that focus is on the dialog container. It's possible that a different // component tried to move focus while the open animation was running. See: // https://github.com/angular/components/issues/16215. Note that we only want to do this // if the focus isn't inside the dialog already, because it's possible that the consumer // turned off `autoFocus` in order to move focus themselves. if (!this._containsFocus()) { element.focus(); } break; case true: case 'first-tabbable': this._focusTrap.focusInitialElementWhenReady().then(focusedSuccessfully => { // If we weren't able to find a focusable element in the dialog, then focus the dialog // container instead. if (!focusedSuccessfully) { this._focusDialogContainer(); } }); break; case 'first-heading': this._focusByCssSelector('h1, h2, h3, h4, h5, h6, [role="heading"]'); break; default: this._focusByCssSelector(this._config.autoFocus); break; } } /** Restores focus to the element that was focused before the dialog opened. */ _restoreFocus() { const focusConfig = this._config.restoreFocus; let focusTargetElement = null; if (typeof focusConfig === 'string') { focusTargetElement = this._document.querySelector(focusConfig); } else if (typeof focusConfig === 'boolean') { focusTargetElement = focusConfig ? this._elementFocusedBeforeDialogWasOpened : null; } else if (focusConfig) { focusTargetElement = focusConfig; } // We need the extra check, because IE can set the `activeElement` to null in some cases. if (this._config.restoreFocus && focusTargetElement && typeof focusTargetElement.focus === 'function') { const activeElement = _getFocusedElementPierceShadowDom(); const element = this._elementRef.nativeElement; // Make sure that focus is still inside the dialog or is on the body (usually because a // non-focusable element like the backdrop was clicked) before moving it. It's possible that // the consumer moved it themselves before the animation was done, in which case we shouldn't // do anything. if (!activeElement || activeElement === this._document.body || activeElement === element || element.contains(activeElement)) { if (this._focusMonitor) { this._focusMonitor.focusVia(focusTargetElement, this._closeInteractionType); this._closeInteractionType = null; } else { focusTargetElement.focus(); } } } if (this._focusTrap) { this._focusTrap.destroy(); } } /** Focuses the dialog container. */ _focusDialogContainer() { // Note that there is no focus method when rendering on the server. if (this._elementRef.nativeElement.focus) { this._elementRef.nativeElement.focus(); } } /** Returns whether focus is inside the dialog. */ _containsFocus() { const element = this._elementRef.nativeElement; const activeElement = _getFocusedElementPierceShadowDom(); return element === activeElement || element.contains(activeElement); } /** Sets up the focus trap. */ _initializeFocusTrap() { this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement); // Save the previously focused element. This element will be re-focused // when the dialog closes. if (this._document) { this._elementFocusedBeforeDialogWasOpened = _getFocusedElementPierceShadowDom(); } } /** Sets up the listener that handles clicks on the dialog backdrop. */ _handleBackdropClicks() { // Clicking on the backdrop will move focus out of dialog. // Recapture it if closing via the backdrop is disabled. this._overlayRef.backdropClick().subscribe(() => { if (this._config.disableClose) { this._recaptureFocus(); } }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkDialogContainer, deps: [{ token: i0.ElementRef }, { token: i1.FocusTrapFactory }, { token: DOCUMENT, optional: true }, { token: DialogConfig }, { token: i1.InteractivityChecker }, { token: i0.NgZone }, { token: i2.OverlayRef }, { token: i1.FocusMonitor }], target: i0.ɵɵFactoryTarget.Component }); } static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.1.1", type: CdkDialogContainer, selector: "cdk-dialog-container", host: { attributes: { "tabindex": "-1" }, properties: { "attr.id": "_config.id || null", "attr.role": "_config.role", "attr.aria-modal": "_config.ariaModal", "attr.aria-labelledby": "_config.ariaLabel ? null : _ariaLabelledByQueue[0]", "attr.aria-label": "_config.ariaLabel", "attr.aria-describedby": "_config.ariaDescribedBy || null" }, classAttribute: "cdk-dialog-container" }, viewQueries: [{ propertyName: "_portalOutlet", first: true, predicate: CdkPortalOutlet, descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: "\n", styles: [".cdk-dialog-container{display:block;width:100%;height:100%;min-height:inherit;max-height:inherit}"], dependencies: [{ kind: "directive", type: i3.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.Default, encapsulation: i0.ViewEncapsulation.None }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkDialogContainer, decorators: [{ type: Component, args: [{ selector: 'cdk-dialog-container', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.Default, host: { 'class': 'cdk-dialog-container', 'tabindex': '-1', '[attr.id]': '_config.id || null', '[attr.role]': '_config.role', '[attr.aria-modal]': '_config.ariaModal', '[attr.aria-labelledby]': '_config.ariaLabel ? null : _ariaLabelledByQueue[0]', '[attr.aria-label]': '_config.ariaLabel', '[attr.aria-describedby]': '_config.ariaDescribedBy || null', }, template: "\n", styles: [".cdk-dialog-container{display:block;width:100%;height:100%;min-height:inherit;max-height:inherit}"] }] }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i1.FocusTrapFactory }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT] }] }, { type: undefined, decorators: [{ type: Inject, args: [DialogConfig] }] }, { type: i1.InteractivityChecker }, { type: i0.NgZone }, { type: i2.OverlayRef }, { type: i1.FocusMonitor }]; }, propDecorators: { _portalOutlet: [{ type: ViewChild, args: [CdkPortalOutlet, { static: true }] }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGlhbG9nLWNvbnRhaW5lci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvZGlhbG9nL2RpYWxvZy1jb250YWluZXIudHMiLCIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL2RpYWxvZy9kaWFsb2ctY29udGFpbmVyLmh0bWwiXS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