@angular/material
Version:
Angular Material
970 lines (960 loc) • 34.6 kB
JavaScript
import { OverlayModule, OverlayConfig, Overlay } from '@angular/cdk/overlay';
import { BasePortalOutlet, CdkPortalOutlet, PortalModule, TemplatePortal, ComponentPortal, PortalInjector } from '@angular/cdk/portal';
import { DOCUMENT, CommonModule, Location } from '@angular/common';
import { InjectionToken, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, ChangeDetectorRef, Optional, Inject, ViewChild, NgModule, TemplateRef, Injectable, Injector, SkipSelf, ɵɵdefineInjectable, ɵɵinject, INJECTOR } from '@angular/core';
import { AnimationDurations, AnimationCurves, MatCommonModule } from '@angular/material/core';
import { Breakpoints, BreakpointObserver } from '@angular/cdk/layout';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { FocusTrapFactory } from '@angular/cdk/a11y';
import { Directionality } from '@angular/cdk/bidi';
import { Subject, merge, of } from 'rxjs';
import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
import { filter, take } from 'rxjs/operators';
/**
* @fileoverview added by tsickle
* Generated from: src/material/bottom-sheet/bottom-sheet-config.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Injection token that can be used to access the data that was passed in to a bottom sheet.
* @type {?}
*/
const MAT_BOTTOM_SHEET_DATA = new InjectionToken('MatBottomSheetData');
/**
* Configuration used when opening a bottom sheet.
* @template D
*/
class MatBottomSheetConfig {
constructor() {
/**
* Data being injected into the child component.
*/
this.data = null;
/**
* Whether the bottom sheet has a backdrop.
*/
this.hasBackdrop = true;
/**
* Whether the user can use escape or clicking outside to close the bottom sheet.
*/
this.disableClose = false;
/**
* Aria label to assign to the bottom sheet element.
*/
this.ariaLabel = null;
/**
* Whether the bottom sheet should close when the user goes backwards/forwards in history.
* Note that this usually doesn't include clicking on links (unless the user is using
* the `HashLocationStrategy`).
*/
this.closeOnNavigation = true;
// Note that this is disabled by default, because while the a11y recommendations are to focus
// the first focusable element, doing so prevents screen readers from reading out the
// rest of the bottom sheet content.
/**
* Whether the bottom sheet should focus the first focusable element on open.
*/
this.autoFocus = false;
/**
* Whether the bottom sheet should restore focus to the
* previously-focused element, after it's closed.
*/
this.restoreFocus = true;
}
}
if (false) {
/**
* The view container to place the overlay for the bottom sheet into.
* @type {?}
*/
MatBottomSheetConfig.prototype.viewContainerRef;
/**
* Extra CSS classes to be added to the bottom sheet container.
* @type {?}
*/
MatBottomSheetConfig.prototype.panelClass;
/**
* Text layout direction for the bottom sheet.
* @type {?}
*/
MatBottomSheetConfig.prototype.direction;
/**
* Data being injected into the child component.
* @type {?}
*/
MatBottomSheetConfig.prototype.data;
/**
* Whether the bottom sheet has a backdrop.
* @type {?}
*/
MatBottomSheetConfig.prototype.hasBackdrop;
/**
* Custom class for the backdrop.
* @type {?}
*/
MatBottomSheetConfig.prototype.backdropClass;
/**
* Whether the user can use escape or clicking outside to close the bottom sheet.
* @type {?}
*/
MatBottomSheetConfig.prototype.disableClose;
/**
* Aria label to assign to the bottom sheet element.
* @type {?}
*/
MatBottomSheetConfig.prototype.ariaLabel;
/**
* Whether the bottom sheet should close when the user goes backwards/forwards in history.
* Note that this usually doesn't include clicking on links (unless the user is using
* the `HashLocationStrategy`).
* @type {?}
*/
MatBottomSheetConfig.prototype.closeOnNavigation;
/**
* Whether the bottom sheet should focus the first focusable element on open.
* @type {?}
*/
MatBottomSheetConfig.prototype.autoFocus;
/**
* Whether the bottom sheet should restore focus to the
* previously-focused element, after it's closed.
* @type {?}
*/
MatBottomSheetConfig.prototype.restoreFocus;
/**
* Scroll strategy to be used for the bottom sheet.
* @type {?}
*/
MatBottomSheetConfig.prototype.scrollStrategy;
}
/**
* @fileoverview added by tsickle
* Generated from: src/material/bottom-sheet/bottom-sheet-animations.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Animations used by the Material bottom sheet.
* @type {?}
*/
const matBottomSheetAnimations = {
/**
* Animation that shows and hides a bottom sheet.
*/
bottomSheetState: trigger('state', [
state('void, hidden', style({ transform: 'translateY(100%)' })),
state('visible', style({ transform: 'translateY(0%)' })),
transition('visible => void, visible => hidden', animate(`${AnimationDurations.COMPLEX} ${AnimationCurves.ACCELERATION_CURVE}`)),
transition('void => visible', animate(`${AnimationDurations.EXITING} ${AnimationCurves.DECELERATION_CURVE}`)),
])
};
/**
* @fileoverview added by tsickle
* Generated from: src/material/bottom-sheet/bottom-sheet-container.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
// TODO(crisbeto): consolidate some logic between this, MatDialog and MatSnackBar
/**
* Internal component that wraps user-provided bottom sheet content.
* \@docs-private
*/
class MatBottomSheetContainer extends BasePortalOutlet {
/**
* @param {?} _elementRef
* @param {?} _changeDetectorRef
* @param {?} _focusTrapFactory
* @param {?} breakpointObserver
* @param {?} document
* @param {?} bottomSheetConfig
*/
constructor(_elementRef, _changeDetectorRef, _focusTrapFactory, breakpointObserver, document, bottomSheetConfig) {
super();
this._elementRef = _elementRef;
this._changeDetectorRef = _changeDetectorRef;
this._focusTrapFactory = _focusTrapFactory;
this.bottomSheetConfig = bottomSheetConfig;
/**
* The state of the bottom sheet animations.
*/
this._animationState = 'void';
/**
* Emits whenever the state of the animation changes.
*/
this._animationStateChanged = new EventEmitter();
/**
* Element that was focused before the bottom sheet was opened.
*/
this._elementFocusedBeforeOpened = null;
/**
* Attaches a DOM portal to the bottom sheet container.
* @deprecated To be turned into a method.
* \@breaking-change 10.0.0
*/
this.attachDomPortal = (/**
* @param {?} portal
* @return {?}
*/
(portal) => {
this._validatePortalAttached();
this._setPanelClass();
this._savePreviouslyFocusedElement();
return this._portalOutlet.attachDomPortal(portal);
});
this._document = document;
this._breakpointSubscription = breakpointObserver
.observe([Breakpoints.Medium, Breakpoints.Large, Breakpoints.XLarge])
.subscribe((/**
* @return {?}
*/
() => {
this._toggleClass('mat-bottom-sheet-container-medium', breakpointObserver.isMatched(Breakpoints.Medium));
this._toggleClass('mat-bottom-sheet-container-large', breakpointObserver.isMatched(Breakpoints.Large));
this._toggleClass('mat-bottom-sheet-container-xlarge', breakpointObserver.isMatched(Breakpoints.XLarge));
}));
}
/**
* Attach a component portal as content to this bottom sheet container.
* @template T
* @param {?} portal
* @return {?}
*/
attachComponentPortal(portal) {
this._validatePortalAttached();
this._setPanelClass();
this._savePreviouslyFocusedElement();
return this._portalOutlet.attachComponentPortal(portal);
}
/**
* Attach a template portal as content to this bottom sheet container.
* @template C
* @param {?} portal
* @return {?}
*/
attachTemplatePortal(portal) {
this._validatePortalAttached();
this._setPanelClass();
this._savePreviouslyFocusedElement();
return this._portalOutlet.attachTemplatePortal(portal);
}
/**
* Begin animation of bottom sheet entrance into view.
* @return {?}
*/
enter() {
if (!this._destroyed) {
this._animationState = 'visible';
this._changeDetectorRef.detectChanges();
}
}
/**
* Begin animation of the bottom sheet exiting from view.
* @return {?}
*/
exit() {
if (!this._destroyed) {
this._animationState = 'hidden';
this._changeDetectorRef.markForCheck();
}
}
/**
* @return {?}
*/
ngOnDestroy() {
this._breakpointSubscription.unsubscribe();
this._destroyed = true;
}
/**
* @param {?} event
* @return {?}
*/
_onAnimationDone(event) {
if (event.toState === 'hidden') {
this._restoreFocus();
}
else if (event.toState === 'visible') {
this._trapFocus();
}
this._animationStateChanged.emit(event);
}
/**
* @param {?} event
* @return {?}
*/
_onAnimationStart(event) {
this._animationStateChanged.emit(event);
}
/**
* @private
* @param {?} cssClass
* @param {?} add
* @return {?}
*/
_toggleClass(cssClass, add) {
/** @type {?} */
const classList = this._elementRef.nativeElement.classList;
add ? classList.add(cssClass) : classList.remove(cssClass);
}
/**
* @private
* @return {?}
*/
_validatePortalAttached() {
if (this._portalOutlet.hasAttached()) {
throw Error('Attempting to attach bottom sheet content after content is already attached');
}
}
/**
* @private
* @return {?}
*/
_setPanelClass() {
/** @type {?} */
const element = this._elementRef.nativeElement;
/** @type {?} */
const panelClass = this.bottomSheetConfig.panelClass;
if (Array.isArray(panelClass)) {
// Note that we can't use a spread here, because IE doesn't support multiple arguments.
panelClass.forEach((/**
* @param {?} cssClass
* @return {?}
*/
cssClass => element.classList.add(cssClass)));
}
else if (panelClass) {
element.classList.add(panelClass);
}
}
/**
* Moves the focus inside the focus trap.
* @private
* @return {?}
*/
_trapFocus() {
/** @type {?} */
const element = this._elementRef.nativeElement;
if (!this._focusTrap) {
this._focusTrap = this._focusTrapFactory.create(element);
}
if (this.bottomSheetConfig.autoFocus) {
this._focusTrap.focusInitialElementWhenReady();
}
else {
/** @type {?} */
const activeElement = this._document.activeElement;
// Otherwise ensure that focus is on the 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 bottom sheet already, because it's possible that the
// consumer turned off `autoFocus` in order to move focus themselves.
if (activeElement !== element && !element.contains(activeElement)) {
element.focus();
}
}
}
/**
* Restores focus to the element that was focused before the bottom sheet was opened.
* @private
* @return {?}
*/
_restoreFocus() {
/** @type {?} */
const toFocus = this._elementFocusedBeforeOpened;
// We need the extra check, because IE can set the `activeElement` to null in some cases.
if (this.bottomSheetConfig.restoreFocus && toFocus && typeof toFocus.focus === 'function') {
/** @type {?} */
const activeElement = this._document.activeElement;
/** @type {?} */
const element = this._elementRef.nativeElement;
// Make sure that focus is still inside the bottom sheet 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)) {
toFocus.focus();
}
}
if (this._focusTrap) {
this._focusTrap.destroy();
}
}
/**
* Saves a reference to the element that was focused before the bottom sheet was opened.
* @private
* @return {?}
*/
_savePreviouslyFocusedElement() {
this._elementFocusedBeforeOpened = (/** @type {?} */ (this._document.activeElement));
// The `focus` method isn't available during server-side rendering.
if (this._elementRef.nativeElement.focus) {
Promise.resolve().then((/**
* @return {?}
*/
() => this._elementRef.nativeElement.focus()));
}
}
}
MatBottomSheetContainer.decorators = [
{ type: Component, args: [{
selector: 'mat-bottom-sheet-container',
template: "<ng-template cdkPortalOutlet></ng-template>\r\n",
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
animations: [matBottomSheetAnimations.bottomSheetState],
host: {
'class': 'mat-bottom-sheet-container',
'tabindex': '-1',
'role': 'dialog',
'aria-modal': 'true',
'[attr.aria-label]': 'bottomSheetConfig?.ariaLabel',
'[@state]': '_animationState',
'(@state.start)': '_onAnimationStart($event)',
'(@state.done)': '_onAnimationDone($event)'
},
styles: [".mat-bottom-sheet-container{padding:8px 16px;min-width:100vw;box-sizing:border-box;display:block;outline:0;max-height:80vh;overflow:auto}.cdk-high-contrast-active .mat-bottom-sheet-container{outline:1px solid}.mat-bottom-sheet-container-xlarge,.mat-bottom-sheet-container-large,.mat-bottom-sheet-container-medium{border-top-left-radius:4px;border-top-right-radius:4px}.mat-bottom-sheet-container-medium{min-width:384px;max-width:calc(100vw - 128px)}.mat-bottom-sheet-container-large{min-width:512px;max-width:calc(100vw - 256px)}.mat-bottom-sheet-container-xlarge{min-width:576px;max-width:calc(100vw - 384px)}\n"]
}] }
];
/** @nocollapse */
MatBottomSheetContainer.ctorParameters = () => [
{ type: ElementRef },
{ type: ChangeDetectorRef },
{ type: FocusTrapFactory },
{ type: BreakpointObserver },
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] },
{ type: MatBottomSheetConfig }
];
MatBottomSheetContainer.propDecorators = {
_portalOutlet: [{ type: ViewChild, args: [CdkPortalOutlet, { static: true },] }]
};
if (false) {
/**
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._breakpointSubscription;
/**
* The portal outlet inside of this container into which the content will be loaded.
* @type {?}
*/
MatBottomSheetContainer.prototype._portalOutlet;
/**
* The state of the bottom sheet animations.
* @type {?}
*/
MatBottomSheetContainer.prototype._animationState;
/**
* Emits whenever the state of the animation changes.
* @type {?}
*/
MatBottomSheetContainer.prototype._animationStateChanged;
/**
* The class that traps and manages focus within the bottom sheet.
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._focusTrap;
/**
* Element that was focused before the bottom sheet was opened.
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._elementFocusedBeforeOpened;
/**
* Server-side rendering-compatible reference to the global document object.
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._document;
/**
* Whether the component has been destroyed.
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._destroyed;
/**
* Attaches a DOM portal to the bottom sheet container.
* @deprecated To be turned into a method.
* \@breaking-change 10.0.0
* @type {?}
*/
MatBottomSheetContainer.prototype.attachDomPortal;
/**
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._elementRef;
/**
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._changeDetectorRef;
/**
* @type {?}
* @private
*/
MatBottomSheetContainer.prototype._focusTrapFactory;
/**
* The bottom sheet configuration.
* @type {?}
*/
MatBottomSheetContainer.prototype.bottomSheetConfig;
}
/**
* @fileoverview added by tsickle
* Generated from: src/material/bottom-sheet/bottom-sheet-module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MatBottomSheetModule {
}
MatBottomSheetModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule,
OverlayModule,
MatCommonModule,
PortalModule,
],
exports: [MatBottomSheetContainer, MatCommonModule],
declarations: [MatBottomSheetContainer],
entryComponents: [MatBottomSheetContainer],
},] }
];
/**
* @fileoverview added by tsickle
* Generated from: src/material/bottom-sheet/bottom-sheet-ref.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Reference to a bottom sheet dispatched from the bottom sheet service.
* @template T, R
*/
class MatBottomSheetRef {
/**
* @param {?} containerInstance
* @param {?} _overlayRef
* @param {?=} _location
*/
constructor(containerInstance, _overlayRef,
// @breaking-change 8.0.0 `_location` parameter to be removed.
_location) {
this._overlayRef = _overlayRef;
/**
* Subject for notifying the user that the bottom sheet has been dismissed.
*/
this._afterDismissed = new Subject();
/**
* Subject for notifying the user that the bottom sheet has opened and appeared.
*/
this._afterOpened = new Subject();
this.containerInstance = containerInstance;
this.disableClose = containerInstance.bottomSheetConfig.disableClose;
// Emit when opening animation completes
containerInstance._animationStateChanged.pipe(filter((/**
* @param {?} event
* @return {?}
*/
event => event.phaseName === 'done' && event.toState === 'visible')), take(1))
.subscribe((/**
* @return {?}
*/
() => {
this._afterOpened.next();
this._afterOpened.complete();
}));
// Dispose overlay when closing animation is complete
containerInstance._animationStateChanged
.pipe(filter((/**
* @param {?} event
* @return {?}
*/
event => event.phaseName === 'done' && event.toState === 'hidden')), take(1))
.subscribe((/**
* @return {?}
*/
() => {
clearTimeout(this._closeFallbackTimeout);
_overlayRef.dispose();
}));
_overlayRef.detachments().pipe(take(1)).subscribe((/**
* @return {?}
*/
() => {
this._afterDismissed.next(this._result);
this._afterDismissed.complete();
}));
merge(_overlayRef.backdropClick(), _overlayRef.keydownEvents().pipe(filter((/**
* @param {?} event
* @return {?}
*/
event => event.keyCode === ESCAPE)))).subscribe((/**
* @param {?} event
* @return {?}
*/
event => {
if (!this.disableClose &&
(event.type !== 'keydown' || !hasModifierKey((/** @type {?} */ (event))))) {
event.preventDefault();
this.dismiss();
}
}));
}
/**
* Dismisses the bottom sheet.
* @param {?=} result Data to be passed back to the bottom sheet opener.
* @return {?}
*/
dismiss(result) {
if (!this._afterDismissed.closed) {
// Transition the backdrop in parallel to the bottom sheet.
this.containerInstance._animationStateChanged.pipe(filter((/**
* @param {?} event
* @return {?}
*/
event => event.phaseName === 'start')), take(1)).subscribe((/**
* @param {?} event
* @return {?}
*/
event => {
// The logic that disposes of the overlay depends on the exit animation completing, however
// it isn't guaranteed if the parent view is destroyed while it's running. Add a fallback
// timeout which will clean everything up if the animation hasn't fired within the specified
// amount of time plus 100ms. We don't need to run this outside the NgZone, because for the
// vast majority of cases the timeout will have been cleared before it has fired.
this._closeFallbackTimeout = setTimeout((/**
* @return {?}
*/
() => {
this._overlayRef.dispose();
}), event.totalTime + 100);
this._overlayRef.detachBackdrop();
}));
this._result = result;
this.containerInstance.exit();
}
}
/**
* Gets an observable that is notified when the bottom sheet is finished closing.
* @return {?}
*/
afterDismissed() {
return this._afterDismissed.asObservable();
}
/**
* Gets an observable that is notified when the bottom sheet has opened and appeared.
* @return {?}
*/
afterOpened() {
return this._afterOpened.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();
}
}
if (false) {
/**
* Instance of the component making up the content of the bottom sheet.
* @type {?}
*/
MatBottomSheetRef.prototype.instance;
/**
* Instance of the component into which the bottom sheet content is projected.
* \@docs-private
* @type {?}
*/
MatBottomSheetRef.prototype.containerInstance;
/**
* Whether the user is allowed to close the bottom sheet.
* @type {?}
*/
MatBottomSheetRef.prototype.disableClose;
/**
* Subject for notifying the user that the bottom sheet has been dismissed.
* @type {?}
* @private
*/
MatBottomSheetRef.prototype._afterDismissed;
/**
* Subject for notifying the user that the bottom sheet has opened and appeared.
* @type {?}
* @private
*/
MatBottomSheetRef.prototype._afterOpened;
/**
* Result to be passed down to the `afterDismissed` stream.
* @type {?}
* @private
*/
MatBottomSheetRef.prototype._result;
/**
* Handle to the timeout that's running as a fallback in case the exit animation doesn't fire.
* @type {?}
* @private
*/
MatBottomSheetRef.prototype._closeFallbackTimeout;
/**
* @type {?}
* @private
*/
MatBottomSheetRef.prototype._overlayRef;
}
/**
* @fileoverview added by tsickle
* Generated from: src/material/bottom-sheet/bottom-sheet.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Injection token that can be used to specify default bottom sheet options.
* @type {?}
*/
const MAT_BOTTOM_SHEET_DEFAULT_OPTIONS = new InjectionToken('mat-bottom-sheet-default-options');
/**
* Service to trigger Material Design bottom sheets.
*/
class MatBottomSheet {
/**
* @param {?} _overlay
* @param {?} _injector
* @param {?} _parentBottomSheet
* @param {?=} _location
* @param {?=} _defaultOptions
*/
constructor(_overlay, _injector, _parentBottomSheet, _location, _defaultOptions) {
this._overlay = _overlay;
this._injector = _injector;
this._parentBottomSheet = _parentBottomSheet;
this._location = _location;
this._defaultOptions = _defaultOptions;
this._bottomSheetRefAtThisLevel = null;
}
/**
* Reference to the currently opened bottom sheet.
* @return {?}
*/
get _openedBottomSheetRef() {
/** @type {?} */
const parent = this._parentBottomSheet;
return parent ? parent._openedBottomSheetRef : this._bottomSheetRefAtThisLevel;
}
/**
* @param {?} value
* @return {?}
*/
set _openedBottomSheetRef(value) {
if (this._parentBottomSheet) {
this._parentBottomSheet._openedBottomSheetRef = value;
}
else {
this._bottomSheetRefAtThisLevel = value;
}
}
/**
* @template T, D, R
* @param {?} componentOrTemplateRef
* @param {?=} config
* @return {?}
*/
open(componentOrTemplateRef, config) {
/** @type {?} */
const _config = _applyConfigDefaults(this._defaultOptions || new MatBottomSheetConfig(), config);
/** @type {?} */
const overlayRef = this._createOverlay(_config);
/** @type {?} */
const container = this._attachContainer(overlayRef, _config);
/** @type {?} */
const ref = new MatBottomSheetRef(container, overlayRef, this._location);
if (componentOrTemplateRef instanceof TemplateRef) {
container.attachTemplatePortal(new TemplatePortal(componentOrTemplateRef, (/** @type {?} */ (null)), (/** @type {?} */ ({
$implicit: _config.data,
bottomSheetRef: ref
}))));
}
else {
/** @type {?} */
const portal = new ComponentPortal(componentOrTemplateRef, undefined, this._createInjector(_config, ref));
/** @type {?} */
const contentRef = container.attachComponentPortal(portal);
ref.instance = contentRef.instance;
}
// When the bottom sheet is dismissed, clear the reference to it.
ref.afterDismissed().subscribe((/**
* @return {?}
*/
() => {
// Clear the bottom sheet ref if it hasn't already been replaced by a newer one.
if (this._openedBottomSheetRef == ref) {
this._openedBottomSheetRef = null;
}
}));
if (this._openedBottomSheetRef) {
// If a bottom sheet is already in view, dismiss it and enter the
// new bottom sheet after exit animation is complete.
this._openedBottomSheetRef.afterDismissed().subscribe((/**
* @return {?}
*/
() => ref.containerInstance.enter()));
this._openedBottomSheetRef.dismiss();
}
else {
// If no bottom sheet is in view, enter the new bottom sheet.
ref.containerInstance.enter();
}
this._openedBottomSheetRef = ref;
return ref;
}
/**
* Dismisses the currently-visible bottom sheet.
* @return {?}
*/
dismiss() {
if (this._openedBottomSheetRef) {
this._openedBottomSheetRef.dismiss();
}
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this._bottomSheetRefAtThisLevel) {
this._bottomSheetRefAtThisLevel.dismiss();
}
}
/**
* Attaches the bottom sheet container component to the overlay.
* @private
* @param {?} overlayRef
* @param {?} config
* @return {?}
*/
_attachContainer(overlayRef, config) {
/** @type {?} */
const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
/** @type {?} */
const injector = new PortalInjector(userInjector || this._injector, new WeakMap([
[MatBottomSheetConfig, config]
]));
/** @type {?} */
const containerPortal = new ComponentPortal(MatBottomSheetContainer, config.viewContainerRef, injector);
/** @type {?} */
const containerRef = overlayRef.attach(containerPortal);
return containerRef.instance;
}
/**
* Creates a new overlay and places it in the correct location.
* @private
* @param {?} config The user-specified bottom sheet config.
* @return {?}
*/
_createOverlay(config) {
/** @type {?} */
const overlayConfig = new OverlayConfig({
direction: config.direction,
hasBackdrop: config.hasBackdrop,
disposeOnNavigation: config.closeOnNavigation,
maxWidth: '100%',
scrollStrategy: config.scrollStrategy || this._overlay.scrollStrategies.block(),
positionStrategy: this._overlay.position().global().centerHorizontally().bottom('0')
});
if (config.backdropClass) {
overlayConfig.backdropClass = config.backdropClass;
}
return this._overlay.create(overlayConfig);
}
/**
* Creates an injector to be used inside of a bottom sheet component.
* @private
* @template T
* @param {?} config Config that was used to create the bottom sheet.
* @param {?} bottomSheetRef Reference to the bottom sheet.
* @return {?}
*/
_createInjector(config, bottomSheetRef) {
/** @type {?} */
const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
/** @type {?} */
const injectionTokens = new WeakMap([
[MatBottomSheetRef, bottomSheetRef],
[MAT_BOTTOM_SHEET_DATA, config.data]
]);
if (config.direction &&
(!userInjector || !userInjector.get(Directionality, null))) {
injectionTokens.set(Directionality, {
value: config.direction,
change: of()
});
}
return new PortalInjector(userInjector || this._injector, injectionTokens);
}
}
MatBottomSheet.decorators = [
{ type: Injectable, args: [{ providedIn: MatBottomSheetModule },] }
];
/** @nocollapse */
MatBottomSheet.ctorParameters = () => [
{ type: Overlay },
{ type: Injector },
{ type: MatBottomSheet, decorators: [{ type: Optional }, { type: SkipSelf }] },
{ type: Location, decorators: [{ type: Optional }] },
{ type: MatBottomSheetConfig, decorators: [{ type: Optional }, { type: Inject, args: [MAT_BOTTOM_SHEET_DEFAULT_OPTIONS,] }] }
];
/** @nocollapse */ MatBottomSheet.ɵprov = ɵɵdefineInjectable({ factory: function MatBottomSheet_Factory() { return new MatBottomSheet(ɵɵinject(Overlay), ɵɵinject(INJECTOR), ɵɵinject(MatBottomSheet, 12), ɵɵinject(Location, 8), ɵɵinject(MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, 8)); }, token: MatBottomSheet, providedIn: MatBottomSheetModule });
if (false) {
/**
* @type {?}
* @private
*/
MatBottomSheet.prototype._bottomSheetRefAtThisLevel;
/**
* @type {?}
* @private
*/
MatBottomSheet.prototype._overlay;
/**
* @type {?}
* @private
*/
MatBottomSheet.prototype._injector;
/**
* @type {?}
* @private
*/
MatBottomSheet.prototype._parentBottomSheet;
/**
* @type {?}
* @private
*/
MatBottomSheet.prototype._location;
/**
* @type {?}
* @private
*/
MatBottomSheet.prototype._defaultOptions;
}
/**
* Applies default options to the bottom sheet config.
* @param {?} defaults Object containing the default values to which to fall back.
* @param {?=} config The configuration to which the defaults will be applied.
* @return {?} The new configuration object with defaults applied.
*/
function _applyConfigDefaults(defaults, config) {
return Object.assign(Object.assign({}, defaults), config);
}
/**
* @fileoverview added by tsickle
* Generated from: src/material/bottom-sheet/public-api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Generated bundle index. Do not edit.
*/
export { MAT_BOTTOM_SHEET_DATA, MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, MatBottomSheet, MatBottomSheetConfig, MatBottomSheetContainer, MatBottomSheetModule, MatBottomSheetRef, matBottomSheetAnimations };
//# sourceMappingURL=bottom-sheet.js.map