/** * @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 } from '@angular/cdk/a11y'; import { _getFocusedElementPierceShadowDom } from '@angular/cdk/platform'; import { BasePortalOutlet, CdkPortalOutlet } from '@angular/cdk/portal'; import { DOCUMENT } from '@angular/common'; import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Directive, ElementRef, EventEmitter, Inject, Optional, ViewChild, ViewEncapsulation, } from '@angular/core'; import { matDialogAnimations } from './dialog-animations'; import { MatDialogConfig } from './dialog-config'; /** * Throws an exception for the case when a ComponentPortal is * attached to a DomPortalOutlet without an origin. * @docs-private */ export function throwMatDialogContentAlreadyAttachedError() { throw Error('Attempting to attach dialog content after content is already attached'); } /** * Base class for the `MatDialogContainer`. The base class does not implement * animations as these are left to implementers of the dialog container. */ export class _MatDialogContainerBase extends BasePortalOutlet { constructor(_elementRef, _focusTrapFactory, _changeDetectorRef, _document, /** The dialog configuration. */ _config, _focusMonitor) { super(); this._elementRef = _elementRef; this._focusTrapFactory = _focusTrapFactory; this._changeDetectorRef = _changeDetectorRef; this._config = _config; this._focusMonitor = _focusMonitor; /** Emits when an animation state changes. */ this._animationStateChanged = new EventEmitter(); /** 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; /** * 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)) { throwMatDialogContentAlreadyAttachedError(); } return this._portalOutlet.attachDomPortal(portal); }; this._ariaLabelledBy = _config.ariaLabelledBy || null; this._document = _document; } /** Initializes the dialog container with the attached content. */ _initializeWithAttachedContent() { this._setupFocusTrap(); // Save the previously focused element. This element will be re-focused // when the dialog closes. this._capturePreviouslyFocusedElement(); // Move focus onto the dialog immediately in order to prevent the user // from accidentally opening multiple dialogs at the same time. this._focusDialogContainer(); } /** * 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)) { throwMatDialogContentAlreadyAttachedError(); } return this._portalOutlet.attachComponentPortal(portal); } /** * 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)) { throwMatDialogContentAlreadyAttachedError(); } return this._portalOutlet.attachTemplatePortal(portal); } /** Moves focus back into the dialog if it was moved out. */ _recaptureFocus() { if (!this._containsFocus()) { const focusContainer = !this._config.autoFocus || !this._focusTrap.focusInitialElement(); if (focusContainer) { this._elementRef.nativeElement.focus(); } } } /** Moves the focus inside the focus trap. */ _trapFocus() { // If we 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. if (this._config.autoFocus) { this._focusTrap.focusInitialElementWhenReady(); } else if (!this._containsFocus()) { // Otherwise 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. this._elementRef.nativeElement.focus(); } } /** Restores focus to the element that was focused before the dialog opened. */ _restoreFocus() { const previousElement = this._elementFocusedBeforeDialogWasOpened; // We need the extra check, because IE can set the `activeElement` to null in some cases. if (this._config.restoreFocus && previousElement && typeof previousElement.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(previousElement, this._closeInteractionType); this._closeInteractionType = null; } else { previousElement.focus(); } } } if (this._focusTrap) { this._focusTrap.destroy(); } } /** Sets up the focus trap. */ _setupFocusTrap() { this._focusTrap = this._focusTrapFactory.create(this._elementRef.nativeElement); } /** Captures the element that was focused before the dialog was opened. */ _capturePreviouslyFocusedElement() { if (this._document) { this._elementFocusedBeforeDialogWasOpened = _getFocusedElementPierceShadowDom(); } } /** 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); } } _MatDialogContainerBase.decorators = [ { type: Directive } ]; _MatDialogContainerBase.ctorParameters = () => [ { type: ElementRef }, { type: FocusTrapFactory }, { type: ChangeDetectorRef }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }, { type: MatDialogConfig }, { type: FocusMonitor } ]; _MatDialogContainerBase.propDecorators = { _portalOutlet: [{ type: ViewChild, args: [CdkPortalOutlet, { static: true },] }] }; /** * Internal component that wraps user-provided dialog content. * Animation is based on https://material.io/guidelines/motion/choreography.html. * @docs-private */ export class MatDialogContainer extends _MatDialogContainerBase { constructor() { super(...arguments); /** State of the dialog animation. */ this._state = 'enter'; } /** Callback, invoked whenever an animation on the host completes. */ _onAnimationDone({ toState, totalTime }) { if (toState === 'enter') { this._trapFocus(); this._animationStateChanged.next({ state: 'opened', totalTime }); } else if (toState === 'exit') { this._restoreFocus(); this._animationStateChanged.next({ state: 'closed', totalTime }); } } /** Callback, invoked when an animation on the host starts. */ _onAnimationStart({ toState, totalTime }) { if (toState === 'enter') { this._animationStateChanged.next({ state: 'opening', totalTime }); } else if (toState === 'exit' || toState === 'void') { this._animationStateChanged.next({ state: 'closing', totalTime }); } } /** Starts the dialog exit animation. */ _startExitAnimation() { this._state = 'exit'; // Mark the container for check so it can react if the // view container is using OnPush change detection. this._changeDetectorRef.markForCheck(); } } MatDialogContainer.decorators = [ { type: Component, args: [{ selector: 'mat-dialog-container', template: "\n", encapsulation: ViewEncapsulation.None, // Using OnPush for dialogs caused some G3 sync issues. Disabled until we can track them down. // tslint:disable-next-line:validate-decorators changeDetection: ChangeDetectionStrategy.Default, animations: [matDialogAnimations.dialogContainer], host: { 'class': 'mat-dialog-container', 'tabindex': '-1', 'aria-modal': 'true', '[id]': '_id', '[attr.role]': '_config.role', '[attr.aria-labelledby]': '_config.ariaLabel ? null : _ariaLabelledBy', '[attr.aria-label]': '_config.ariaLabel', '[attr.aria-describedby]': '_config.ariaDescribedBy || null', '[@dialogContainer]': '_state', '(@dialogContainer.start)': '_onAnimationStart($event)', '(@dialogContainer.done)': '_onAnimationDone($event)', }, styles: [".mat-dialog-container{display:block;padding:24px;border-radius:4px;box-sizing:border-box;overflow:auto;outline:0;width:100%;height:100%;min-height:inherit;max-height:inherit}.cdk-high-contrast-active .mat-dialog-container{outline:solid 1px}.mat-dialog-content{display:block;margin:0 -24px;padding:0 24px;max-height:65vh;overflow:auto;-webkit-overflow-scrolling:touch}.mat-dialog-title{margin:0 0 20px;display:block}.mat-dialog-actions{padding:8px 0;display:flex;flex-wrap:wrap;min-height:52px;align-items:center;box-sizing:content-box;margin-bottom:-24px}.mat-dialog-actions[align=end]{justify-content:flex-end}.mat-dialog-actions[align=center]{justify-content:center}.mat-dialog-actions .mat-button-base+.mat-button-base,.mat-dialog-actions .mat-mdc-button-base+.mat-mdc-button-base{margin-left:8px}[dir=rtl] .mat-dialog-actions .mat-button-base+.mat-button-base,[dir=rtl] .mat-dialog-actions .mat-mdc-button-base+.mat-mdc-button-base{margin-left:0;margin-right:8px}\n"] },] } ]; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz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