UNPKG

@angular/material

Version:
1,002 lines (984 loc) 38.6 kB
/** * @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 { ChangeDetectionStrategy, ChangeDetectorRef, Component, Directive, ElementRef, EventEmitter, Inject, Injectable, InjectionToken, Injector, Input, NgModule, Optional, SkipSelf, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core'; import { CommonModule, DOCUMENT, Location } from '@angular/common'; import { Overlay, OverlayConfig, OverlayContainer, OverlayModule } from '@angular/cdk/overlay'; import { BasePortalOutlet, CdkPortalOutlet, ComponentPortal, PortalInjector, PortalModule, TemplatePortal } from '@angular/cdk/portal'; import { A11yModule, FocusTrapFactory } from '@angular/cdk/a11y'; import { MatCommonModule } from '@angular/material/core'; import { Directionality } from '@angular/cdk/bidi'; import { defer } from 'rxjs/observable/defer'; import { of } from 'rxjs/observable/of'; import { startWith } from 'rxjs/operators/startWith'; import { Subject } from 'rxjs/Subject'; import { animate, state, style, transition, trigger } from '@angular/animations'; import { ESCAPE } from '@angular/cdk/keycodes'; import { filter } from 'rxjs/operators/filter'; import { take } from 'rxjs/operators/take'; import { Subscription } from 'rxjs/Subscription'; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Possible overrides for a dialog's position. * @record */ /** * Configuration for opening a modal dialog with the MatDialog service. */ class MatDialogConfig { constructor() { /** * The ARIA role of the dialog element. */ this.role = 'dialog'; /** * Custom class for the overlay pane. */ this.panelClass = ''; /** * Whether the dialog has a backdrop. */ this.hasBackdrop = true; /** * Custom class for the backdrop, */ this.backdropClass = ''; /** * Whether the user can use escape or clicking outside to close a modal. */ this.disableClose = false; /** * Width of the dialog. */ this.width = ''; /** * Height of the dialog. */ this.height = ''; /** * Max-width of the dialog. If a number is provided, pixel units are assumed. Defaults to 80vw */ this.maxWidth = '80vw'; /** * Data being injected into the child component. */ this.data = null; /** * Layout direction for the dialog's content. */ this.direction = 'ltr'; /** * ID of the element that describes the dialog. */ this.ariaDescribedBy = null; /** * Aria label to assign to the dialog element */ this.ariaLabel = null; /** * Whether the dialog should focus the first focusable element on open. */ this.autoFocus = true; /** * Whether the dialog should close when the user goes backwards/forwards in history. */ this.closeOnNavigation = true; } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Animations used by MatDialog. */ const matDialogAnimations = { /** Animation that slides the dialog in and out of view and fades the opacity. */ slideDialog: trigger('slideDialog', [ // Note: The `enter` animation doesn't transition to something like `translate3d(0, 0, 0) // scale(1)`, because for some reason specifying the transform explicitly, causes IE both // to blur the dialog content and decimate the animation performance. Leaving it as `none` // solves both issues. state('enter', style({ transform: 'none', opacity: 1 })), state('void', style({ transform: 'translate3d(0, 25%, 0) scale(0.9)', opacity: 0 })), state('exit', style({ transform: 'translate3d(0, 25%, 0)', opacity: 0 })), transition('* => *', animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)')), ]) }; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Throws an exception for the case when a ComponentPortal is * attached to a DomPortalOutlet without an origin. * \@docs-private * @return {?} */ function throwMatDialogContentAlreadyAttachedError() { throw Error('Attempting to attach dialog content after content is already attached'); } /** * Internal component that wraps user-provided dialog content. * Animation is based on https://material.io/guidelines/motion/choreography.html. * \@docs-private */ class MatDialogContainer extends BasePortalOutlet { /** * @param {?} _elementRef * @param {?} _focusTrapFactory * @param {?} _changeDetectorRef * @param {?} _document */ constructor(_elementRef, _focusTrapFactory, _changeDetectorRef, _document) { super(); this._elementRef = _elementRef; this._focusTrapFactory = _focusTrapFactory; this._changeDetectorRef = _changeDetectorRef; this._document = _document; /** * Element that was focused before the dialog was opened. Save this to restore upon close. */ this._elementFocusedBeforeDialogWasOpened = null; /** * State of the dialog animation. */ this._state = 'enter'; /** * Emits when an animation state changes. */ this._animationStateChanged = new EventEmitter(); /** * ID of the element that should be considered as the dialog's label. */ this._ariaLabelledBy = null; } /** * Attach a ComponentPortal as content to this dialog container. * @template T * @param {?} portal Portal to be attached as the dialog content. * @return {?} */ attachComponentPortal(portal) { if (this._portalOutlet.hasAttached()) { throwMatDialogContentAlreadyAttachedError(); } this._savePreviouslyFocusedElement(); return this._portalOutlet.attachComponentPortal(portal); } /** * Attach a TemplatePortal as content to this dialog container. * @template C * @param {?} portal Portal to be attached as the dialog content. * @return {?} */ attachTemplatePortal(portal) { if (this._portalOutlet.hasAttached()) { throwMatDialogContentAlreadyAttachedError(); } this._savePreviouslyFocusedElement(); return this._portalOutlet.attachTemplatePortal(portal); } /** * Moves the focus inside the focus trap. * @return {?} */ _trapFocus() { if (!this._focusTrap) { this._focusTrap = this._focusTrapFactory.create(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. if (this._config.autoFocus) { this._focusTrap.focusInitialElementWhenReady(); } } /** * Restores focus to the element that was focused before the dialog opened. * @return {?} */ _restoreFocus() { const /** @type {?} */ toFocus = this._elementFocusedBeforeDialogWasOpened; // We need the extra check, because IE can set the `activeElement` to null in some cases. if (toFocus && typeof toFocus.focus === 'function') { toFocus.focus(); } if (this._focusTrap) { this._focusTrap.destroy(); } } /** * Saves a reference to the element that was focused before the dialog was opened. * @return {?} */ _savePreviouslyFocusedElement() { if (this._document) { this._elementFocusedBeforeDialogWasOpened = /** @type {?} */ (this._document.activeElement); // Note that there is no focus method when rendering on the server. if (this._elementRef.nativeElement.focus) { // Move focus onto the dialog immediately in order to prevent the user from accidentally // opening multiple dialogs at the same time. Needs to be async, because the element // may not be focusable immediately. Promise.resolve().then(() => this._elementRef.nativeElement.focus()); } } } /** * Callback, invoked whenever an animation on the host completes. * @param {?} event * @return {?} */ _onAnimationDone(event) { if (event.toState === 'enter') { this._trapFocus(); } else if (event.toState === 'exit') { this._restoreFocus(); } this._animationStateChanged.emit(event); } /** * Callback, invoked when an animation on the host starts. * @param {?} event * @return {?} */ _onAnimationStart(event) { this._animationStateChanged.emit(event); } /** * Starts the dialog exit animation. * @return {?} */ _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: "<ng-template cdkPortalOutlet></ng-template>", styles: [".mat-dialog-container{box-shadow:0 11px 15px -7px rgba(0,0,0,.2),0 24px 38px 3px rgba(0,0,0,.14),0 9px 46px 8px rgba(0,0,0,.12);display:block;padding:24px;border-radius:2px;box-sizing:border-box;overflow:auto;outline:0;width:100%;height:100%}@media screen and (-ms-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;-webkit-backface-visibility:hidden;backface-visibility:hidden}.mat-dialog-title{margin:0 0 20px;display:block}.mat-dialog-actions{padding:12px 0;display:flex;flex-wrap:wrap}.mat-dialog-actions:last-child{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+.mat-button,.mat-dialog-actions .mat-button+.mat-raised-button,.mat-dialog-actions .mat-raised-button+.mat-button,.mat-dialog-actions .mat-raised-button+.mat-raised-button{margin-left:8px}[dir=rtl] .mat-dialog-actions .mat-button+.mat-button,[dir=rtl] .mat-dialog-actions .mat-button+.mat-raised-button,[dir=rtl] .mat-dialog-actions .mat-raised-button+.mat-button,[dir=rtl] .mat-dialog-actions .mat-raised-button+.mat-raised-button{margin-left:0;margin-right:8px}"], encapsulation: ViewEncapsulation.None, preserveWhitespaces: false, // 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.slideDialog], host: { 'class': 'mat-dialog-container', 'tabindex': '-1', '[attr.id]': '_id', '[attr.role]': '_config?.role', '[attr.aria-labelledby]': '_config?.ariaLabel ? null : _ariaLabelledBy', '[attr.aria-label]': '_config?.ariaLabel', '[attr.aria-describedby]': '_config?.ariaDescribedBy || null', '[@slideDialog]': '_state', '(@slideDialog.start)': '_onAnimationStart($event)', '(@slideDialog.done)': '_onAnimationDone($event)', }, },] }, ]; /** @nocollapse */ MatDialogContainer.ctorParameters = () => [ { type: ElementRef, }, { type: FocusTrapFactory, }, { type: ChangeDetectorRef, }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] },] }, ]; MatDialogContainer.propDecorators = { "_portalOutlet": [{ type: ViewChild, args: [CdkPortalOutlet,] },], }; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ // TODO(jelbourn): resizing // Counter for unique dialog ids. let uniqueId = 0; /** * Reference to a dialog opened via the MatDialog service. */ class MatDialogRef { /** * @param {?} _overlayRef * @param {?} _containerInstance * @param {?=} location * @param {?=} id */ constructor(_overlayRef, _containerInstance, location, id = `mat-dialog-${uniqueId++}`) { this._overlayRef = _overlayRef; this._containerInstance = _containerInstance; this.id = id; /** * Whether the user is allowed to close the dialog. */ this.disableClose = this._containerInstance._config.disableClose; /** * Subject for notifying the user that the dialog has finished opening. */ this._afterOpen = new Subject(); /** * Subject for notifying the user that the dialog has finished closing. */ this._afterClosed = new Subject(); /** * Subject for notifying the user that the dialog has started closing. */ this._beforeClose = new Subject(); /** * Subscription to changes in the user's location. */ this._locationChanges = Subscription.EMPTY; // Pass the id along to the container. _containerInstance._id = id; // Emit when opening animation completes _containerInstance._animationStateChanged.pipe(filter(event => event.phaseName === 'done' && event.toState === 'enter'), take(1)) .subscribe(() => { this._afterOpen.next(); this._afterOpen.complete(); }); // Dispose overlay when closing animation is complete _containerInstance._animationStateChanged.pipe(filter(event => event.phaseName === 'done' && event.toState === 'exit'), take(1)) .subscribe(() => { this._overlayRef.dispose(); this._locationChanges.unsubscribe(); this._afterClosed.next(this._result); this._afterClosed.complete(); this.componentInstance = /** @type {?} */ ((null)); }); _overlayRef.keydownEvents() .pipe(filter(event => event.keyCode === ESCAPE && !this.disableClose)) .subscribe(() => this.close()); if (location) { // Close the dialog when the user goes forwards/backwards in history or when the location // hash changes. Note that this usually doesn't include clicking on links (unless the user // is using the `HashLocationStrategy`). this._locationChanges = location.subscribe(() => { if (this._containerInstance._config.closeOnNavigation) { this.close(); } }); } } /** * Close the dialog. * @param {?=} dialogResult Optional result to return to the dialog opener. * @return {?} */ close(dialogResult) { this._result = dialogResult; // Transition the backdrop in parallel to the dialog. this._containerInstance._animationStateChanged.pipe(filter(event => event.phaseName === 'start'), take(1)) .subscribe(() => { this._beforeClose.next(dialogResult); this._beforeClose.complete(); this._overlayRef.detachBackdrop(); }); this._containerInstance._startExitAnimation(); } /** * Gets an observable that is notified when the dialog is finished opening. * @return {?} */ afterOpen() { return this._afterOpen.asObservable(); } /** * Gets an observable that is notified when the dialog is finished closing. * @return {?} */ afterClosed() { return this._afterClosed.asObservable(); } /** * Gets an observable that is notified when the dialog has started closing. * @return {?} */ beforeClose() { return this._beforeClose.asObservable(); } /** * Gets an observable that emits when the overlay's backdrop has been clicked. * @return {?} */ backdropClick() { return this._overlayRef.backdropClick(); } /** * Gets an observable that emits when keydown events are targeted on the overlay. * @return {?} */ keydownEvents() { return this._overlayRef.keydownEvents(); } /** * Updates the dialog's position. * @param {?=} position New dialog position. * @return {?} */ updatePosition(position) { let /** @type {?} */ strategy = this._getPositionStrategy(); if (position && (position.left || position.right)) { position.left ? strategy.left(position.left) : strategy.right(position.right); } else { strategy.centerHorizontally(); } if (position && (position.top || position.bottom)) { position.top ? strategy.top(position.top) : strategy.bottom(position.bottom); } else { strategy.centerVertically(); } this._overlayRef.updatePosition(); return this; } /** * Updates the dialog's width and height. * @param {?=} width New width of the dialog. * @param {?=} height New height of the dialog. * @return {?} */ updateSize(width = 'auto', height = 'auto') { this._getPositionStrategy().width(width).height(height); this._overlayRef.updatePosition(); return this; } /** * Fetches the position strategy object from the overlay ref. * @return {?} */ _getPositionStrategy() { return /** @type {?} */ (this._overlayRef.getConfig().positionStrategy); } } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Injection token that can be used to access the data that was passed in to a dialog. */ const MAT_DIALOG_DATA = new InjectionToken('MatDialogData'); /** * Injection token that can be used to specify default dialog options. */ const MAT_DIALOG_DEFAULT_OPTIONS = new InjectionToken('mat-dialog-default-options'); /** * Injection token that determines the scroll handling while the dialog is open. */ const MAT_DIALOG_SCROLL_STRATEGY = new InjectionToken('mat-dialog-scroll-strategy'); /** * \@docs-private * @param {?} overlay * @return {?} */ function MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay) { return () => overlay.scrollStrategies.block(); } /** * \@docs-private */ const MAT_DIALOG_SCROLL_STRATEGY_PROVIDER = { provide: MAT_DIALOG_SCROLL_STRATEGY, deps: [Overlay], useFactory: MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY, }; /** * Service to open Material Design modal dialogs. */ class MatDialog { /** * @param {?} _overlay * @param {?} _injector * @param {?} _location * @param {?} _defaultOptions * @param {?} _scrollStrategy * @param {?} _parentDialog * @param {?} _overlayContainer */ constructor(_overlay, _injector, _location, _defaultOptions, _scrollStrategy, _parentDialog, _overlayContainer) { this._overlay = _overlay; this._injector = _injector; this._location = _location; this._defaultOptions = _defaultOptions; this._scrollStrategy = _scrollStrategy; this._parentDialog = _parentDialog; this._overlayContainer = _overlayContainer; this._openDialogsAtThisLevel = []; this._afterAllClosedAtThisLevel = new Subject(); this._afterOpenAtThisLevel = new Subject(); this._ariaHiddenElements = new Map(); /** * Stream that emits when all open dialog have finished closing. * Will emit on subscribe if there are no open dialogs to begin with. */ this.afterAllClosed = defer(() => this.openDialogs.length ? this._afterAllClosed : this._afterAllClosed.pipe(startWith(undefined))); } /** * Keeps track of the currently-open dialogs. * @return {?} */ get openDialogs() { return this._parentDialog ? this._parentDialog.openDialogs : this._openDialogsAtThisLevel; } /** * Stream that emits when a dialog has been opened. * @return {?} */ get afterOpen() { return this._parentDialog ? this._parentDialog.afterOpen : this._afterOpenAtThisLevel; } /** * @return {?} */ get _afterAllClosed() { const /** @type {?} */ parent = this._parentDialog; return parent ? parent._afterAllClosed : this._afterAllClosedAtThisLevel; } /** * Opens a modal dialog containing the given component. * @template T, D * @param {?} componentOrTemplateRef Type of the component to load into the dialog, * or a TemplateRef to instantiate as the dialog content. * @param {?=} config Extra configuration options. * @return {?} Reference to the newly-opened dialog. */ open(componentOrTemplateRef, config) { config = _applyConfigDefaults(config, this._defaultOptions || new MatDialogConfig()); if (config.id && this.getDialogById(config.id)) { throw Error(`Dialog with id "${config.id}" exists already. The dialog id must be unique.`); } const /** @type {?} */ overlayRef = this._createOverlay(config); const /** @type {?} */ dialogContainer = this._attachDialogContainer(overlayRef, config); const /** @type {?} */ dialogRef = this._attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config); // If this is the first dialog that we're opening, hide all the non-overlay content. if (!this.openDialogs.length) { this._hideNonDialogContentFromAssistiveTechnology(); } this.openDialogs.push(dialogRef); dialogRef.afterClosed().subscribe(() => this._removeOpenDialog(dialogRef)); this.afterOpen.next(dialogRef); return dialogRef; } /** * Closes all of the currently-open dialogs. * @return {?} */ closeAll() { let /** @type {?} */ i = this.openDialogs.length; while (i--) { // The `_openDialogs` property isn't updated after close until the rxjs subscription // runs on the next microtask, in addition to modifying the array as we're going // through it. We loop through all of them and call close without assuming that // they'll be removed from the list instantaneously. this.openDialogs[i].close(); } } /** * Finds an open dialog by its id. * @param {?} id ID to use when looking up the dialog. * @return {?} */ getDialogById(id) { return this.openDialogs.find(dialog => dialog.id === id); } /** * Creates the overlay into which the dialog will be loaded. * @param {?} config The dialog configuration. * @return {?} A promise resolving to the OverlayRef for the created overlay. */ _createOverlay(config) { const /** @type {?} */ overlayConfig = this._getOverlayConfig(config); return this._overlay.create(overlayConfig); } /** * Creates an overlay config from a dialog config. * @param {?} dialogConfig The dialog configuration. * @return {?} The overlay configuration. */ _getOverlayConfig(dialogConfig) { const /** @type {?} */ state$$1 = new OverlayConfig({ positionStrategy: this._overlay.position().global(), scrollStrategy: dialogConfig.scrollStrategy || this._scrollStrategy(), panelClass: dialogConfig.panelClass, hasBackdrop: dialogConfig.hasBackdrop, direction: dialogConfig.direction, minWidth: dialogConfig.minWidth, minHeight: dialogConfig.minHeight, maxWidth: dialogConfig.maxWidth, maxHeight: dialogConfig.maxHeight }); if (dialogConfig.backdropClass) { state$$1.backdropClass = dialogConfig.backdropClass; } return state$$1; } /** * Attaches an MatDialogContainer to a dialog's already-created overlay. * @param {?} overlay Reference to the dialog's underlying overlay. * @param {?} config The dialog configuration. * @return {?} A promise resolving to a ComponentRef for the attached container. */ _attachDialogContainer(overlay, config) { let /** @type {?} */ containerPortal = new ComponentPortal(MatDialogContainer, config.viewContainerRef); let /** @type {?} */ containerRef = overlay.attach(containerPortal); containerRef.instance._config = config; return containerRef.instance; } /** * Attaches the user-provided component to the already-created MatDialogContainer. * @template T * @param {?} componentOrTemplateRef The type of component being loaded into the dialog, * or a TemplateRef to instantiate as the content. * @param {?} dialogContainer Reference to the wrapping MatDialogContainer. * @param {?} overlayRef Reference to the overlay in which the dialog resides. * @param {?} config The dialog configuration. * @return {?} A promise resolving to the MatDialogRef that should be returned to the user. */ _attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config) { // Create a reference to the dialog we're creating in order to give the user a handle // to modify and close it. const /** @type {?} */ dialogRef = new MatDialogRef(overlayRef, dialogContainer, this._location, config.id); // When the dialog backdrop is clicked, we want to close it. if (config.hasBackdrop) { overlayRef.backdropClick().subscribe(() => { if (!dialogRef.disableClose) { dialogRef.close(); } }); } if (componentOrTemplateRef instanceof TemplateRef) { dialogContainer.attachTemplatePortal(new TemplatePortal(componentOrTemplateRef, /** @type {?} */ ((null)), /** @type {?} */ ({ $implicit: config.data, dialogRef }))); } else { const /** @type {?} */ injector = this._createInjector(config, dialogRef, dialogContainer); const /** @type {?} */ contentRef = dialogContainer.attachComponentPortal(new ComponentPortal(componentOrTemplateRef, undefined, injector)); dialogRef.componentInstance = contentRef.instance; } dialogRef .updateSize(config.width, config.height) .updatePosition(config.position); return dialogRef; } /** * Creates a custom injector to be used inside the dialog. This allows a component loaded inside * of a dialog to close itself and, optionally, to return a value. * @template T * @param {?} config Config object that is used to construct the dialog. * @param {?} dialogRef Reference to the dialog. * @param {?} dialogContainer * @return {?} The custom injector that can be used inside the dialog. */ _createInjector(config, dialogRef, dialogContainer) { const /** @type {?} */ userInjector = config && config.viewContainerRef && config.viewContainerRef.injector; const /** @type {?} */ injectionTokens = new WeakMap(); injectionTokens.set(MatDialogRef, dialogRef); // The MatDialogContainer is injected in the portal as the MatDialogContainer and the dialog's // content are created out of the same ViewContainerRef and as such, are siblings for injector // purposes. To allow the hierarchy that is expected, the MatDialogContainer is explicitly // added to the injection tokens. injectionTokens.set(MatDialogContainer, dialogContainer); injectionTokens.set(MAT_DIALOG_DATA, config.data); injectionTokens.set(Directionality, { value: config.direction, change: of() }); return new PortalInjector(userInjector || this._injector, injectionTokens); } /** * Removes a dialog from the array of open dialogs. * @param {?} dialogRef Dialog to be removed. * @return {?} */ _removeOpenDialog(dialogRef) { const /** @type {?} */ index = this.openDialogs.indexOf(dialogRef); if (index > -1) { this.openDialogs.splice(index, 1); // If all the dialogs were closed, remove/restore the `aria-hidden` // to a the siblings and emit to the `afterAllClosed` stream. if (!this.openDialogs.length) { this._ariaHiddenElements.forEach((previousValue, element) => { if (previousValue) { element.setAttribute('aria-hidden', previousValue); } else { element.removeAttribute('aria-hidden'); } }); this._ariaHiddenElements.clear(); this._afterAllClosed.next(); } } } /** * Hides all of the content that isn't an overlay from assistive technology. * @return {?} */ _hideNonDialogContentFromAssistiveTechnology() { const /** @type {?} */ overlayContainer = this._overlayContainer.getContainerElement(); // Ensure that the overlay container is attached to the DOM. if (overlayContainer.parentElement) { const /** @type {?} */ siblings = overlayContainer.parentElement.children; for (let /** @type {?} */ i = siblings.length - 1; i > -1; i--) { let /** @type {?} */ sibling = siblings[i]; if (sibling !== overlayContainer && sibling.nodeName !== 'SCRIPT' && sibling.nodeName !== 'STYLE' && !sibling.hasAttribute('aria-live')) { this._ariaHiddenElements.set(sibling, sibling.getAttribute('aria-hidden')); sibling.setAttribute('aria-hidden', 'true'); } } } } } MatDialog.decorators = [ { type: Injectable }, ]; /** @nocollapse */ MatDialog.ctorParameters = () => [ { type: Overlay, }, { type: Injector, }, { type: Location, decorators: [{ type: Optional },] }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_DIALOG_DEFAULT_OPTIONS,] },] }, { type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_SCROLL_STRATEGY,] },] }, { type: MatDialog, decorators: [{ type: Optional }, { type: SkipSelf },] }, { type: OverlayContainer, }, ]; /** * Applies default options to the dialog config. * @param {?=} config Config to be modified. * @param {?=} defaultOptions Default options provided. * @return {?} The new configuration object. */ function _applyConfigDefaults(config, defaultOptions) { return Object.assign({}, defaultOptions, config); } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Counter used to generate unique IDs for dialog elements. */ let dialogElementUid = 0; /** * Button that will close the current dialog. */ class MatDialogClose { /** * @param {?} dialogRef * @param {?} _elementRef * @param {?} _dialog */ constructor(dialogRef, _elementRef, _dialog) { this.dialogRef = dialogRef; this._elementRef = _elementRef; this._dialog = _dialog; /** * Screenreader label for the button. */ this.ariaLabel = 'Close dialog'; } /** * @return {?} */ ngOnInit() { if (!this.dialogRef) { // When this directive is included in a dialog via TemplateRef (rather than being // in a Component), the DialogRef isn't available via injection because embedded // views cannot be given a custom injector. Instead, we look up the DialogRef by // ID. This must occur in `onInit`, as the ID binding for the dialog container won't // be resolved at constructor time. this.dialogRef = /** @type {?} */ ((getClosestDialog(this._elementRef, this._dialog.openDialogs))); } } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { const /** @type {?} */ proxiedChange = changes["_matDialogClose"] || changes["_matDialogCloseResult"]; if (proxiedChange) { this.dialogResult = proxiedChange.currentValue; } } } MatDialogClose.decorators = [ { type: Directive, args: [{ selector: `button[mat-dialog-close], button[matDialogClose]`, exportAs: 'matDialogClose', host: { '(click)': 'dialogRef.close(dialogResult)', '[attr.aria-label]': 'ariaLabel', 'type': 'button', } },] }, ]; /** @nocollapse */ MatDialogClose.ctorParameters = () => [ { type: MatDialogRef, decorators: [{ type: Optional },] }, { type: ElementRef, }, { type: MatDialog, }, ]; MatDialogClose.propDecorators = { "ariaLabel": [{ type: Input, args: ['aria-label',] },], "dialogResult": [{ type: Input, args: ['mat-dialog-close',] },], "_matDialogClose": [{ type: Input, args: ['matDialogClose',] },], }; /** * Title of a dialog element. Stays fixed to the top of the dialog when scrolling. */ class MatDialogTitle { /** * @param {?} _dialogRef * @param {?} _elementRef * @param {?} _dialog */ constructor(_dialogRef, _elementRef, _dialog) { this._dialogRef = _dialogRef; this._elementRef = _elementRef; this._dialog = _dialog; this.id = `mat-dialog-title-${dialogElementUid++}`; } /** * @return {?} */ ngOnInit() { if (!this._dialogRef) { this._dialogRef = /** @type {?} */ ((getClosestDialog(this._elementRef, this._dialog.openDialogs))); } if (this._dialogRef) { Promise.resolve().then(() => { const /** @type {?} */ container = this._dialogRef._containerInstance; if (container && !container._ariaLabelledBy) { container._ariaLabelledBy = this.id; } }); } } } MatDialogTitle.decorators = [ { type: Directive, args: [{ selector: '[mat-dialog-title], [matDialogTitle]', exportAs: 'matDialogTitle', host: { 'class': 'mat-dialog-title', '[id]': 'id', }, },] }, ]; /** @nocollapse */ MatDialogTitle.ctorParameters = () => [ { type: MatDialogRef, decorators: [{ type: Optional },] }, { type: ElementRef, }, { type: MatDialog, }, ]; MatDialogTitle.propDecorators = { "id": [{ type: Input },], }; /** * Scrollable content container of a dialog. */ class MatDialogContent { } MatDialogContent.decorators = [ { type: Directive, args: [{ selector: `[mat-dialog-content], mat-dialog-content, [matDialogContent]`, host: { 'class': 'mat-dialog-content' } },] }, ]; /** @nocollapse */ MatDialogContent.ctorParameters = () => []; /** * Container for the bottom action buttons in a dialog. * Stays fixed to the bottom when scrolling. */ class MatDialogActions { } MatDialogActions.decorators = [ { type: Directive, args: [{ selector: `[mat-dialog-actions], mat-dialog-actions, [matDialogActions]`, host: { 'class': 'mat-dialog-actions' } },] }, ]; /** @nocollapse */ MatDialogActions.ctorParameters = () => []; /** * Finds the closest MatDialogRef to an element by looking at the DOM. * @param {?} element Element relative to which to look for a dialog. * @param {?} openDialogs References to the currently-open dialogs. * @return {?} */ function getClosestDialog(element, openDialogs) { let /** @type {?} */ parent = element.nativeElement.parentElement; while (parent && !parent.classList.contains('mat-dialog-container')) { parent = parent.parentElement; } return parent ? openDialogs.find(dialog => dialog.id === /** @type {?} */ ((parent)).id) : null; } /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ class MatDialogModule { } MatDialogModule.decorators = [ { type: NgModule, args: [{ imports: [ CommonModule, OverlayModule, PortalModule, A11yModule, MatCommonModule, ], exports: [ MatDialogContainer, MatDialogClose, MatDialogTitle, MatDialogContent, MatDialogActions, MatCommonModule, ], declarations: [ MatDialogContainer, MatDialogClose, MatDialogTitle, MatDialogActions, MatDialogContent, ], providers: [ MatDialog, MAT_DIALOG_SCROLL_STRATEGY_PROVIDER, ], entryComponents: [MatDialogContainer], },] }, ]; /** @nocollapse */ MatDialogModule.ctorParameters = () => []; /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ /** * Generated bundle index. Do not edit. */ export { MatDialogModule, MAT_DIALOG_DATA, MAT_DIALOG_DEFAULT_OPTIONS, MAT_DIALOG_SCROLL_STRATEGY, MAT_DIALOG_SCROLL_STRATEGY_PROVIDER_FACTORY, MAT_DIALOG_SCROLL_STRATEGY_PROVIDER, MatDialog, throwMatDialogContentAlreadyAttachedError, MatDialogContainer, MatDialogClose, MatDialogTitle, MatDialogContent, MatDialogActions, MatDialogConfig, MatDialogRef, matDialogAnimations }; //# sourceMappingURL=dialog.js.map