UNPKG

@angular/material

Version:
1,460 lines (1,452 loc) 112 kB
import { FocusKeyManager, FocusMonitor, A11yModule } from '@angular/cdk/a11y'; import { ObserversModule } from '@angular/cdk/observers'; import { CdkPortal, TemplatePortal, CdkPortalOutlet, PortalHostDirective, PortalModule } from '@angular/cdk/portal'; import { DOCUMENT, CommonModule } from '@angular/common'; import { InjectionToken, Directive, ElementRef, NgZone, Inject, Optional, TemplateRef, Component, ChangeDetectionStrategy, ViewEncapsulation, ViewContainerRef, ContentChild, ViewChild, Input, ComponentFactoryResolver, forwardRef, EventEmitter, ChangeDetectorRef, Output, QueryList, ContentChildren, Attribute, NgModule } from '@angular/core'; import { mixinDisabled, mixinColor, mixinDisableRipple, mixinTabIndex, MAT_RIPPLE_GLOBAL_OPTIONS, RippleRenderer, MatCommonModule, MatRippleModule } from '@angular/material/core'; import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations'; import { Subject, Subscription, merge, fromEvent, of, timer } from 'rxjs'; import { Directionality } from '@angular/cdk/bidi'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { startWith, distinctUntilChanged, takeUntil } from 'rxjs/operators'; import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion'; import { ViewportRuler } from '@angular/cdk/scrolling'; import { normalizePassiveListenerOptions, Platform } from '@angular/cdk/platform'; import { hasModifierKey, SPACE, ENTER, END, HOME } from '@angular/cdk/keycodes'; /** * @fileoverview added by tsickle * Generated from: src/material/tabs/ink-bar.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Interface for a a MatInkBar positioner method, defining the positioning and width of the ink * bar in a set of tabs. * @record */ function _MatInkBarPositioner() { } /** * Injection token for the MatInkBar's Positioner. * @type {?} */ const _MAT_INK_BAR_POSITIONER = new InjectionToken('MatInkBarPositioner', { providedIn: 'root', factory: _MAT_INK_BAR_POSITIONER_FACTORY }); /** * The default positioner function for the MatInkBar. * \@docs-private * @return {?} */ function _MAT_INK_BAR_POSITIONER_FACTORY() { /** @type {?} */ const method = (/** * @param {?} element * @return {?} */ (element) => ({ left: element ? (element.offsetLeft || 0) + 'px' : '0', width: element ? (element.offsetWidth || 0) + 'px' : '0', })); return method; } /** * The ink-bar is used to display and animate the line underneath the current active tab label. * \@docs-private */ class MatInkBar { /** * @param {?} _elementRef * @param {?} _ngZone * @param {?} _inkBarPositioner * @param {?=} _animationMode */ constructor(_elementRef, _ngZone, _inkBarPositioner, _animationMode) { this._elementRef = _elementRef; this._ngZone = _ngZone; this._inkBarPositioner = _inkBarPositioner; this._animationMode = _animationMode; } /** * Calculates the styles from the provided element in order to align the ink-bar to that element. * Shows the ink bar if previously set as hidden. * @param {?} element * @return {?} */ alignToElement(element) { this.show(); if (typeof requestAnimationFrame !== 'undefined') { this._ngZone.runOutsideAngular((/** * @return {?} */ () => { requestAnimationFrame((/** * @return {?} */ () => this._setStyles(element))); })); } else { this._setStyles(element); } } /** * Shows the ink bar. * @return {?} */ show() { this._elementRef.nativeElement.style.visibility = 'visible'; } /** * Hides the ink bar. * @return {?} */ hide() { this._elementRef.nativeElement.style.visibility = 'hidden'; } /** * Sets the proper styles to the ink bar element. * @private * @param {?} element * @return {?} */ _setStyles(element) { /** @type {?} */ const positions = this._inkBarPositioner(element); /** @type {?} */ const inkBar = this._elementRef.nativeElement; inkBar.style.left = positions.left; inkBar.style.width = positions.width; } } MatInkBar.decorators = [ { type: Directive, args: [{ selector: 'mat-ink-bar', host: { 'class': 'mat-ink-bar', '[class._mat-animation-noopable]': `_animationMode === 'NoopAnimations'`, }, },] } ]; /** @nocollapse */ MatInkBar.ctorParameters = () => [ { type: ElementRef }, { type: NgZone }, { type: undefined, decorators: [{ type: Inject, args: [_MAT_INK_BAR_POSITIONER,] }] }, { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] } ]; if (false) { /** * @type {?} * @private */ MatInkBar.prototype._elementRef; /** * @type {?} * @private */ MatInkBar.prototype._ngZone; /** * @type {?} * @private */ MatInkBar.prototype._inkBarPositioner; /** @type {?} */ MatInkBar.prototype._animationMode; } /** * @fileoverview added by tsickle * Generated from: src/material/tabs/tab-content.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Decorates the `ng-template` tags and reads out the template from it. */ class MatTabContent { /** * @param {?} template */ constructor(template) { this.template = template; } } MatTabContent.decorators = [ { type: Directive, args: [{ selector: '[matTabContent]' },] } ]; /** @nocollapse */ MatTabContent.ctorParameters = () => [ { type: TemplateRef } ]; if (false) { /** @type {?} */ MatTabContent.prototype.template; } /** * @fileoverview added by tsickle * Generated from: src/material/tabs/tab-label.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Used to flag tab labels for use with the portal directive */ class MatTabLabel extends CdkPortal { } MatTabLabel.decorators = [ { type: Directive, args: [{ selector: '[mat-tab-label], [matTabLabel]', },] } ]; /** * @fileoverview added by tsickle * Generated from: src/material/tabs/tab.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // Boilerplate for applying mixins to MatTab. /** * \@docs-private */ class MatTabBase { } /** @type {?} */ const _MatTabMixinBase = mixinDisabled(MatTabBase); /** * Used to provide a tab group to a tab without causing a circular dependency. * \@docs-private * @type {?} */ const MAT_TAB_GROUP = new InjectionToken('MAT_TAB_GROUP'); class MatTab extends _MatTabMixinBase { /** * @param {?} _viewContainerRef * @param {?=} _closestTabGroup */ constructor(_viewContainerRef, _closestTabGroup) { super(); this._viewContainerRef = _viewContainerRef; this._closestTabGroup = _closestTabGroup; /** * Plain text label for the tab, used when there is no template label. */ this.textLabel = ''; /** * Portal that will be the hosted content of the tab */ this._contentPortal = null; /** * Emits whenever the internal state of the tab changes. */ this._stateChanges = new Subject(); /** * The relatively indexed position where 0 represents the center, negative is left, and positive * represents the right. */ this.position = null; /** * The initial relatively index origin of the tab if it was created and selected after there * was already a selected tab. Provides context of what position the tab should originate from. */ this.origin = null; /** * Whether the tab is currently active. */ this.isActive = false; } /** * Content for the tab label given by `<ng-template mat-tab-label>`. * @return {?} */ get templateLabel() { return this._templateLabel; } /** * @param {?} value * @return {?} */ set templateLabel(value) { // Only update the templateLabel via query if there is actually // a MatTabLabel found. This works around an issue where a user may have // manually set `templateLabel` during creation mode, which would then get clobbered // by `undefined` when this query resolves. if (value) { this._templateLabel = value; } } /** * \@docs-private * @return {?} */ get content() { return this._contentPortal; } /** * @param {?} changes * @return {?} */ ngOnChanges(changes) { if (changes.hasOwnProperty('textLabel') || changes.hasOwnProperty('disabled')) { this._stateChanges.next(); } } /** * @return {?} */ ngOnDestroy() { this._stateChanges.complete(); } /** * @return {?} */ ngOnInit() { this._contentPortal = new TemplatePortal(this._explicitContent || this._implicitContent, this._viewContainerRef); } } MatTab.decorators = [ { type: Component, args: [{ selector: 'mat-tab', template: "<!-- Create a template for the content of the <mat-tab> so that we can grab a reference to this\n TemplateRef and use it in a Portal to render the tab content in the appropriate place in the\n tab-group. -->\n<ng-template><ng-content></ng-content></ng-template>\n", inputs: ['disabled'], // tslint:disable-next-line:validate-decorators changeDetection: ChangeDetectionStrategy.Default, encapsulation: ViewEncapsulation.None, exportAs: 'matTab' }] } ]; /** @nocollapse */ MatTab.ctorParameters = () => [ { type: ViewContainerRef }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [MAT_TAB_GROUP,] }] } ]; MatTab.propDecorators = { templateLabel: [{ type: ContentChild, args: [MatTabLabel,] }], _explicitContent: [{ type: ContentChild, args: [MatTabContent, { read: TemplateRef, static: true },] }], _implicitContent: [{ type: ViewChild, args: [TemplateRef, { static: true },] }], textLabel: [{ type: Input, args: ['label',] }], ariaLabel: [{ type: Input, args: ['aria-label',] }], ariaLabelledby: [{ type: Input, args: ['aria-labelledby',] }] }; if (false) { /** @type {?} */ MatTab.ngAcceptInputType_disabled; /** * @type {?} * @private */ MatTab.prototype._templateLabel; /** * Template provided in the tab content that will be used if present, used to enable lazy-loading * @type {?} */ MatTab.prototype._explicitContent; /** * Template inside the MatTab view that contains an `<ng-content>`. * @type {?} */ MatTab.prototype._implicitContent; /** * Plain text label for the tab, used when there is no template label. * @type {?} */ MatTab.prototype.textLabel; /** * Aria label for the tab. * @type {?} */ MatTab.prototype.ariaLabel; /** * Reference to the element that the tab is labelled by. * Will be cleared if `aria-label` is set at the same time. * @type {?} */ MatTab.prototype.ariaLabelledby; /** * Portal that will be the hosted content of the tab * @type {?} * @private */ MatTab.prototype._contentPortal; /** * Emits whenever the internal state of the tab changes. * @type {?} */ MatTab.prototype._stateChanges; /** * The relatively indexed position where 0 represents the center, negative is left, and positive * represents the right. * @type {?} */ MatTab.prototype.position; /** * The initial relatively index origin of the tab if it was created and selected after there * was already a selected tab. Provides context of what position the tab should originate from. * @type {?} */ MatTab.prototype.origin; /** * Whether the tab is currently active. * @type {?} */ MatTab.prototype.isActive; /** * @type {?} * @private */ MatTab.prototype._viewContainerRef; /** * @deprecated `_closestTabGroup` parameter to become required. * \@breaking-change 10.0.0 * @type {?} */ MatTab.prototype._closestTabGroup; } /** * @fileoverview added by tsickle * Generated from: src/material/tabs/tabs-animations.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Animations used by the Material tabs. * \@docs-private * @type {?} */ const matTabsAnimations = { /** * Animation translates a tab along the X axis. */ translateTab: trigger('translateTab', [ // Note: transitions to `none` instead of 0, because some browsers might blur the content. state('center, void, left-origin-center, right-origin-center', style({ transform: 'none' })), // If the tab is either on the left or right, we additionally add a `min-height` of 1px // in order to ensure that the element has a height before its state changes. This is // necessary because Chrome does seem to skip the transition in RTL mode if the element does // not have a static height and is not rendered. See related issue: #9465 state('left', style({ transform: 'translate3d(-100%, 0, 0)', minHeight: '1px' })), state('right', style({ transform: 'translate3d(100%, 0, 0)', minHeight: '1px' })), transition('* => left, * => right, left => center, right => center', animate('{{animationDuration}} cubic-bezier(0.35, 0, 0.25, 1)')), transition('void => left-origin-center', [ style({ transform: 'translate3d(-100%, 0, 0)' }), animate('{{animationDuration}} cubic-bezier(0.35, 0, 0.25, 1)') ]), transition('void => right-origin-center', [ style({ transform: 'translate3d(100%, 0, 0)' }), animate('{{animationDuration}} cubic-bezier(0.35, 0, 0.25, 1)') ]) ]) }; /** * @fileoverview added by tsickle * Generated from: src/material/tabs/tab-body.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * The portal host directive for the contents of the tab. * \@docs-private */ class MatTabBodyPortal extends CdkPortalOutlet { /** * @param {?} componentFactoryResolver * @param {?} viewContainerRef * @param {?} _host * @param {?=} _document */ constructor(componentFactoryResolver, viewContainerRef, _host, /** * @deprecated `_document` parameter to be made required. * @breaking-change 9.0.0 */ _document) { super(componentFactoryResolver, viewContainerRef, _document); this._host = _host; /** * Subscription to events for when the tab body begins centering. */ this._centeringSub = Subscription.EMPTY; /** * Subscription to events for when the tab body finishes leaving from center position. */ this._leavingSub = Subscription.EMPTY; } /** * Set initial visibility or set up subscription for changing visibility. * @return {?} */ ngOnInit() { super.ngOnInit(); this._centeringSub = this._host._beforeCentering .pipe(startWith(this._host._isCenterPosition(this._host._position))) .subscribe((/** * @param {?} isCentering * @return {?} */ (isCentering) => { if (isCentering && !this.hasAttached()) { this.attach(this._host._content); } })); this._leavingSub = this._host._afterLeavingCenter.subscribe((/** * @return {?} */ () => { this.detach(); })); } /** * Clean up centering subscription. * @return {?} */ ngOnDestroy() { super.ngOnDestroy(); this._centeringSub.unsubscribe(); this._leavingSub.unsubscribe(); } } MatTabBodyPortal.decorators = [ { type: Directive, args: [{ selector: '[matTabBodyHost]' },] } ]; /** @nocollapse */ MatTabBodyPortal.ctorParameters = () => [ { type: ComponentFactoryResolver }, { type: ViewContainerRef }, { type: MatTabBody, decorators: [{ type: Inject, args: [forwardRef((/** * @return {?} */ () => MatTabBody)),] }] }, { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] } ]; if (false) { /** * Subscription to events for when the tab body begins centering. * @type {?} * @private */ MatTabBodyPortal.prototype._centeringSub; /** * Subscription to events for when the tab body finishes leaving from center position. * @type {?} * @private */ MatTabBodyPortal.prototype._leavingSub; /** * @type {?} * @private */ MatTabBodyPortal.prototype._host; } /** * Base class with all of the `MatTabBody` functionality. * \@docs-private * @abstract */ // tslint:disable-next-line:class-name class _MatTabBodyBase { /** * @param {?} _elementRef * @param {?} _dir * @param {?} changeDetectorRef */ constructor(_elementRef, _dir, changeDetectorRef) { this._elementRef = _elementRef; this._dir = _dir; /** * Subscription to the directionality change observable. */ this._dirChangeSubscription = Subscription.EMPTY; /** * Emits when an animation on the tab is complete. */ this._translateTabComplete = new Subject(); /** * Event emitted when the tab begins to animate towards the center as the active tab. */ this._onCentering = new EventEmitter(); /** * Event emitted before the centering of the tab begins. */ this._beforeCentering = new EventEmitter(); /** * Event emitted before the centering of the tab begins. */ this._afterLeavingCenter = new EventEmitter(); /** * Event emitted when the tab completes its animation towards the center. */ this._onCentered = new EventEmitter(true); // Note that the default value will always be overwritten by `MatTabBody`, but we need one // anyway to prevent the animations module from throwing an error if the body is used on its own. /** * Duration for the tab's animation. */ this.animationDuration = '500ms'; if (_dir) { this._dirChangeSubscription = _dir.change.subscribe((/** * @param {?} dir * @return {?} */ (dir) => { this._computePositionAnimationState(dir); changeDetectorRef.markForCheck(); })); } // Ensure that we get unique animation events, because the `.done` callback can get // invoked twice in some browsers. See https://github.com/angular/angular/issues/24084. this._translateTabComplete.pipe(distinctUntilChanged((/** * @param {?} x * @param {?} y * @return {?} */ (x, y) => { return x.fromState === y.fromState && x.toState === y.toState; }))).subscribe((/** * @param {?} event * @return {?} */ event => { // If the transition to the center is complete, emit an event. if (this._isCenterPosition(event.toState) && this._isCenterPosition(this._position)) { this._onCentered.emit(); } if (this._isCenterPosition(event.fromState) && !this._isCenterPosition(this._position)) { this._afterLeavingCenter.emit(); } })); } /** * The shifted index position of the tab body, where zero represents the active center tab. * @param {?} position * @return {?} */ set position(position) { this._positionIndex = position; this._computePositionAnimationState(); } /** * After initialized, check if the content is centered and has an origin. If so, set the * special position states that transition the tab from the left or right before centering. * @return {?} */ ngOnInit() { if (this._position == 'center' && this.origin != null) { this._position = this._computePositionFromOrigin(this.origin); } } /** * @return {?} */ ngOnDestroy() { this._dirChangeSubscription.unsubscribe(); this._translateTabComplete.complete(); } /** * @param {?} event * @return {?} */ _onTranslateTabStarted(event) { /** @type {?} */ const isCentering = this._isCenterPosition(event.toState); this._beforeCentering.emit(isCentering); if (isCentering) { this._onCentering.emit(this._elementRef.nativeElement.clientHeight); } } /** * The text direction of the containing app. * @return {?} */ _getLayoutDirection() { return this._dir && this._dir.value === 'rtl' ? 'rtl' : 'ltr'; } /** * Whether the provided position state is considered center, regardless of origin. * @param {?} position * @return {?} */ _isCenterPosition(position) { return position == 'center' || position == 'left-origin-center' || position == 'right-origin-center'; } /** * Computes the position state that will be used for the tab-body animation trigger. * @private * @param {?=} dir * @return {?} */ _computePositionAnimationState(dir = this._getLayoutDirection()) { if (this._positionIndex < 0) { this._position = dir == 'ltr' ? 'left' : 'right'; } else if (this._positionIndex > 0) { this._position = dir == 'ltr' ? 'right' : 'left'; } else { this._position = 'center'; } } /** * Computes the position state based on the specified origin position. This is used if the * tab is becoming visible immediately after creation. * @private * @param {?} origin * @return {?} */ _computePositionFromOrigin(origin) { /** @type {?} */ const dir = this._getLayoutDirection(); if ((dir == 'ltr' && origin <= 0) || (dir == 'rtl' && origin > 0)) { return 'left-origin-center'; } return 'right-origin-center'; } } _MatTabBodyBase.decorators = [ { type: Directive } ]; /** @nocollapse */ _MatTabBodyBase.ctorParameters = () => [ { type: ElementRef }, { type: Directionality, decorators: [{ type: Optional }] }, { type: ChangeDetectorRef } ]; _MatTabBodyBase.propDecorators = { _onCentering: [{ type: Output }], _beforeCentering: [{ type: Output }], _afterLeavingCenter: [{ type: Output }], _onCentered: [{ type: Output }], _content: [{ type: Input, args: ['content',] }], origin: [{ type: Input }], animationDuration: [{ type: Input }], position: [{ type: Input }] }; if (false) { /** * Current position of the tab-body in the tab-group. Zero means that the tab is visible. * @type {?} * @private */ _MatTabBodyBase.prototype._positionIndex; /** * Subscription to the directionality change observable. * @type {?} * @private */ _MatTabBodyBase.prototype._dirChangeSubscription; /** * Tab body position state. Used by the animation trigger for the current state. * @type {?} */ _MatTabBodyBase.prototype._position; /** * Emits when an animation on the tab is complete. * @type {?} */ _MatTabBodyBase.prototype._translateTabComplete; /** * Event emitted when the tab begins to animate towards the center as the active tab. * @type {?} */ _MatTabBodyBase.prototype._onCentering; /** * Event emitted before the centering of the tab begins. * @type {?} */ _MatTabBodyBase.prototype._beforeCentering; /** * Event emitted before the centering of the tab begins. * @type {?} */ _MatTabBodyBase.prototype._afterLeavingCenter; /** * Event emitted when the tab completes its animation towards the center. * @type {?} */ _MatTabBodyBase.prototype._onCentered; /** * The portal host inside of this container into which the tab body content will be loaded. * @type {?} */ _MatTabBodyBase.prototype._portalHost; /** * The tab body content to display. * @type {?} */ _MatTabBodyBase.prototype._content; /** * Position that will be used when the tab is immediately becoming visible after creation. * @type {?} */ _MatTabBodyBase.prototype.origin; /** * Duration for the tab's animation. * @type {?} */ _MatTabBodyBase.prototype.animationDuration; /** * @type {?} * @private */ _MatTabBodyBase.prototype._elementRef; /** * @type {?} * @private */ _MatTabBodyBase.prototype._dir; } /** * Wrapper for the contents of a tab. * \@docs-private */ class MatTabBody extends _MatTabBodyBase { /** * @param {?} elementRef * @param {?} dir * @param {?} changeDetectorRef */ constructor(elementRef, dir, changeDetectorRef) { super(elementRef, dir, changeDetectorRef); } } MatTabBody.decorators = [ { type: Component, args: [{ selector: 'mat-tab-body', template: "<div class=\"mat-tab-body-content\" #content\n [@translateTab]=\"{\n value: _position,\n params: {animationDuration: animationDuration}\n }\"\n (@translateTab.start)=\"_onTranslateTabStarted($event)\"\n (@translateTab.done)=\"_translateTabComplete.next($event)\">\n <ng-template matTabBodyHost></ng-template>\n</div>\n", encapsulation: ViewEncapsulation.None, // tslint:disable-next-line:validate-decorators changeDetection: ChangeDetectionStrategy.Default, animations: [matTabsAnimations.translateTab], host: { 'class': 'mat-tab-body', }, styles: [".mat-tab-body-content{height:100%;overflow:auto}.mat-tab-group-dynamic-height .mat-tab-body-content{overflow:hidden}\n"] }] } ]; /** @nocollapse */ MatTabBody.ctorParameters = () => [ { type: ElementRef }, { type: Directionality, decorators: [{ type: Optional }] }, { type: ChangeDetectorRef } ]; MatTabBody.propDecorators = { _portalHost: [{ type: ViewChild, args: [PortalHostDirective,] }] }; if (false) { /** @type {?} */ MatTabBody.prototype._portalHost; } /** * @fileoverview added by tsickle * Generated from: src/material/tabs/tab-config.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Object that can be used to configure the default options for the tabs module. * @record */ function MatTabsConfig() { } if (false) { /** * Duration for the tab animation. Must be a valid CSS value (e.g. 600ms). * @type {?|undefined} */ MatTabsConfig.prototype.animationDuration; /** * Whether pagination should be disabled. This can be used to avoid unnecessary * layout recalculations if it's known that pagination won't be required. * @type {?|undefined} */ MatTabsConfig.prototype.disablePagination; /** * Whether the ink bar should fit its width to the size of the tab label content. * This only applies to the MDC-based tabs. * @type {?|undefined} */ MatTabsConfig.prototype.fitInkBarToContent; } /** * Injection token that can be used to provide the default options the tabs module. * @type {?} */ const MAT_TABS_CONFIG = new InjectionToken('MAT_TABS_CONFIG'); /** * @fileoverview added by tsickle * Generated from: src/material/tabs/tab-group.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Used to generate unique ID's for each tab component * @type {?} */ let nextId = 0; /** * A simple change event emitted on focus or selection changes. */ class MatTabChangeEvent { } if (false) { /** * Index of the currently-selected tab. * @type {?} */ MatTabChangeEvent.prototype.index; /** * Reference to the currently-selected tab. * @type {?} */ MatTabChangeEvent.prototype.tab; } // Boilerplate for applying mixins to MatTabGroup. /** * \@docs-private */ class MatTabGroupMixinBase { /** * @param {?} _elementRef */ constructor(_elementRef) { this._elementRef = _elementRef; } } if (false) { /** @type {?} */ MatTabGroupMixinBase.prototype._elementRef; } /** @type {?} */ const _MatTabGroupMixinBase = mixinColor(mixinDisableRipple(MatTabGroupMixinBase), 'primary'); /** * @record */ function MatTabGroupBaseHeader() { } if (false) { /** @type {?} */ MatTabGroupBaseHeader.prototype._alignInkBarToSelectedTab; /** @type {?} */ MatTabGroupBaseHeader.prototype.focusIndex; } /** * Base class with all of the `MatTabGroupBase` functionality. * \@docs-private * @abstract */ // tslint:disable-next-line:class-name class _MatTabGroupBase extends _MatTabGroupMixinBase { /** * @param {?} elementRef * @param {?} _changeDetectorRef * @param {?=} defaultConfig * @param {?=} _animationMode */ constructor(elementRef, _changeDetectorRef, defaultConfig, _animationMode) { super(elementRef); this._changeDetectorRef = _changeDetectorRef; this._animationMode = _animationMode; /** * All of the tabs that belong to the group. */ this._tabs = new QueryList(); /** * The tab index that should be selected after the content has been checked. */ this._indexToSelect = 0; /** * Snapshot of the height of the tab body wrapper before another tab is activated. */ this._tabBodyWrapperHeight = 0; /** * Subscription to tabs being added/removed. */ this._tabsSubscription = Subscription.EMPTY; /** * Subscription to changes in the tab labels. */ this._tabLabelSubscription = Subscription.EMPTY; this._dynamicHeight = false; this._selectedIndex = null; /** * Position of the tab header. */ this.headerPosition = 'above'; /** * Output to enable support for two-way binding on `[(selectedIndex)]` */ this.selectedIndexChange = new EventEmitter(); /** * Event emitted when focus has changed within a tab group. */ this.focusChange = new EventEmitter(); /** * Event emitted when the body animation has completed */ this.animationDone = new EventEmitter(); /** * Event emitted when the tab selection has changed. */ this.selectedTabChange = new EventEmitter(true); this._groupId = nextId++; this.animationDuration = defaultConfig && defaultConfig.animationDuration ? defaultConfig.animationDuration : '500ms'; this.disablePagination = defaultConfig && defaultConfig.disablePagination != null ? defaultConfig.disablePagination : false; } /** * Whether the tab group should grow to the size of the active tab. * @return {?} */ get dynamicHeight() { return this._dynamicHeight; } /** * @param {?} value * @return {?} */ set dynamicHeight(value) { this._dynamicHeight = coerceBooleanProperty(value); } /** * The index of the active tab. * @return {?} */ get selectedIndex() { return this._selectedIndex; } /** * @param {?} value * @return {?} */ set selectedIndex(value) { this._indexToSelect = coerceNumberProperty(value, null); } /** * Duration for the tab animation. Will be normalized to milliseconds if no units are set. * @return {?} */ get animationDuration() { return this._animationDuration; } /** * @param {?} value * @return {?} */ set animationDuration(value) { this._animationDuration = /^\d+$/.test(value) ? value + 'ms' : value; } /** * Background color of the tab group. * @return {?} */ get backgroundColor() { return this._backgroundColor; } /** * @param {?} value * @return {?} */ set backgroundColor(value) { /** @type {?} */ const nativeElement = this._elementRef.nativeElement; nativeElement.classList.remove(`mat-background-${this.backgroundColor}`); if (value) { nativeElement.classList.add(`mat-background-${value}`); } this._backgroundColor = value; } /** * After the content is checked, this component knows what tabs have been defined * and what the selected index should be. This is where we can know exactly what position * each tab should be in according to the new selected index, and additionally we know how * a new selected tab should transition in (from the left or right). * @return {?} */ ngAfterContentChecked() { // Don't clamp the `indexToSelect` immediately in the setter because it can happen that // the amount of tabs changes before the actual change detection runs. /** @type {?} */ const indexToSelect = this._indexToSelect = this._clampTabIndex(this._indexToSelect); // If there is a change in selected index, emit a change event. Should not trigger if // the selected index has not yet been initialized. if (this._selectedIndex != indexToSelect) { /** @type {?} */ const isFirstRun = this._selectedIndex == null; if (!isFirstRun) { this.selectedTabChange.emit(this._createChangeEvent(indexToSelect)); } // Changing these values after change detection has run // since the checked content may contain references to them. Promise.resolve().then((/** * @return {?} */ () => { this._tabs.forEach((/** * @param {?} tab * @param {?} index * @return {?} */ (tab, index) => tab.isActive = index === indexToSelect)); if (!isFirstRun) { this.selectedIndexChange.emit(indexToSelect); } })); } // Setup the position for each tab and optionally setup an origin on the next selected tab. this._tabs.forEach((/** * @param {?} tab * @param {?} index * @return {?} */ (tab, index) => { tab.position = index - indexToSelect; // If there is already a selected tab, then set up an origin for the next selected tab // if it doesn't have one already. if (this._selectedIndex != null && tab.position == 0 && !tab.origin) { tab.origin = indexToSelect - this._selectedIndex; } })); if (this._selectedIndex !== indexToSelect) { this._selectedIndex = indexToSelect; this._changeDetectorRef.markForCheck(); } } /** * @return {?} */ ngAfterContentInit() { this._subscribeToAllTabChanges(); this._subscribeToTabLabels(); // Subscribe to changes in the amount of tabs, in order to be // able to re-render the content as new tabs are added or removed. this._tabsSubscription = this._tabs.changes.subscribe((/** * @return {?} */ () => { /** @type {?} */ const indexToSelect = this._clampTabIndex(this._indexToSelect); // Maintain the previously-selected tab if a new tab is added or removed and there is no // explicit change that selects a different tab. if (indexToSelect === this._selectedIndex) { /** @type {?} */ const tabs = this._tabs.toArray(); for (let i = 0; i < tabs.length; i++) { if (tabs[i].isActive) { // Assign both to the `_indexToSelect` and `_selectedIndex` so we don't fire a changed // event, otherwise the consumer may end up in an infinite loop in some edge cases like // adding a tab within the `selectedIndexChange` event. this._indexToSelect = this._selectedIndex = i; break; } } } this._changeDetectorRef.markForCheck(); })); } /** * Listens to changes in all of the tabs. * @private * @return {?} */ _subscribeToAllTabChanges() { // Since we use a query with `descendants: true` to pick up the tabs, we may end up catching // some that are inside of nested tab groups. We filter them out manually by checking that // the closest group to the tab is the current one. this._allTabs.changes .pipe(startWith(this._allTabs)) .subscribe((/** * @param {?} tabs * @return {?} */ (tabs) => { this._tabs.reset(tabs.filter((/** * @param {?} tab * @return {?} */ tab => { // @breaking-change 10.0.0 Remove null check for `_closestTabGroup` // once it becomes a required parameter in MatTab. return !tab._closestTabGroup || tab._closestTabGroup === this; }))); this._tabs.notifyOnChanges(); })); } /** * @return {?} */ ngOnDestroy() { this._tabs.destroy(); this._tabsSubscription.unsubscribe(); this._tabLabelSubscription.unsubscribe(); } /** * Re-aligns the ink bar to the selected tab element. * @return {?} */ realignInkBar() { if (this._tabHeader) { this._tabHeader._alignInkBarToSelectedTab(); } } /** * @param {?} index * @return {?} */ _focusChanged(index) { this.focusChange.emit(this._createChangeEvent(index)); } /** * @private * @param {?} index * @return {?} */ _createChangeEvent(index) { /** @type {?} */ const event = new MatTabChangeEvent; event.index = index; if (this._tabs && this._tabs.length) { event.tab = this._tabs.toArray()[index]; } return event; } /** * Subscribes to changes in the tab labels. This is needed, because the \@Input for the label is * on the MatTab component, whereas the data binding is inside the MatTabGroup. In order for the * binding to be updated, we need to subscribe to changes in it and trigger change detection * manually. * @private * @return {?} */ _subscribeToTabLabels() { if (this._tabLabelSubscription) { this._tabLabelSubscription.unsubscribe(); } this._tabLabelSubscription = merge(...this._tabs.map((/** * @param {?} tab * @return {?} */ tab => tab._stateChanges))) .subscribe((/** * @return {?} */ () => this._changeDetectorRef.markForCheck())); } /** * Clamps the given index to the bounds of 0 and the tabs length. * @private * @param {?} index * @return {?} */ _clampTabIndex(index) { // Note the `|| 0`, which ensures that values like NaN can't get through // and which would otherwise throw the component into an infinite loop // (since Math.max(NaN, 0) === NaN). return Math.min(this._tabs.length - 1, Math.max(index || 0, 0)); } /** * Returns a unique id for each tab label element * @param {?} i * @return {?} */ _getTabLabelId(i) { return `mat-tab-label-${this._groupId}-${i}`; } /** * Returns a unique id for each tab content element * @param {?} i * @return {?} */ _getTabContentId(i) { return `mat-tab-content-${this._groupId}-${i}`; } /** * Sets the height of the body wrapper to the height of the activating tab if dynamic * height property is true. * @param {?} tabHeight * @return {?} */ _setTabBodyWrapperHeight(tabHeight) { if (!this._dynamicHeight || !this._tabBodyWrapperHeight) { return; } /** @type {?} */ const wrapper = this._tabBodyWrapper.nativeElement; wrapper.style.height = this._tabBodyWrapperHeight + 'px'; // This conditional forces the browser to paint the height so that // the animation to the new height can have an origin. if (this._tabBodyWrapper.nativeElement.offsetHeight) { wrapper.style.height = tabHeight + 'px'; } } /** * Removes the height of the tab body wrapper. * @return {?} */ _removeTabBodyWrapperHeight() { /** @type {?} */ const wrapper = this._tabBodyWrapper.nativeElement; this._tabBodyWrapperHeight = wrapper.clientHeight; wrapper.style.height = ''; this.animationDone.emit(); } /** * Handle click events, setting new selected index if appropriate. * @param {?} tab * @param {?} tabHeader * @param {?} index * @return {?} */ _handleClick(tab, tabHeader, index) { if (!tab.disabled) { this.selectedIndex = tabHeader.focusIndex = index; } } /** * Retrieves the tabindex for the tab. * @param {?} tab * @param {?} idx * @return {?} */ _getTabIndex(tab, idx) { if (tab.disabled) { return null; } return this.selectedIndex === idx ? 0 : -1; } } _MatTabGroupBase.decorators = [ { type: Directive } ]; /** @nocollapse */ _MatTabGroupBase.ctorParameters = () => [ { type: ElementRef }, { type: ChangeDetectorRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_TABS_CONFIG,] }, { type: Optional }] }, { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ANIMATION_MODULE_TYPE,] }] } ]; _MatTabGroupBase.propDecorators = { dynamicHeight: [{ type: Input }], selectedIndex: [{ type: Input }], headerPosition: [{ type: Input }], animationDuration: [{ type: Input }], disablePagination: [{ type: Input }], backgroundColor: [{ type: Input }], selectedIndexChange: [{ type: Output }], focusChange: [{ type: Output }], animationDone: [{ type: Output }], selectedTabChange: [{ type: Output }] }; if (false) { /** @type {?} */ _MatTabGroupBase.ngAcceptInputType_dynamicHeight; /** @type {?} */ _MatTabGroupBase.ngAcceptInputType_animationDuration; /** @type {?} */ _MatTabGroupBase.ngAcceptInputType_selectedIndex; /** @type {?} */ _MatTabGroupBase.ngAcceptInputType_disableRipple; /** * All tabs inside the tab group. This includes tabs that belong to groups that are nested * inside the current one. We filter out only the tabs that belong to this group in `_tabs`. * @type {?} */ _MatTabGroupBase.prototype._allTabs; /** @type {?} */ _MatTabGroupBase.prototype._tabBodyWrapper; /** @type {?} */ _MatTabGroupBase.prototype._tabHeader; /** * All of the tabs that belong to the group. * @type {?} */ _MatTabGroupBase.prototype._tabs; /** * The tab index that should be selected after the content has been checked. * @type {?} * @private */ _MatTabGroupBase.prototype._indexToSelect; /** * Snapshot of the height of the tab body wrapper before another tab is activated. * @type {?} * @private */ _MatTabGroupBase.prototype._tabBodyWrapperHeight; /** * Subscription to tabs being added/removed. * @type {?} * @private */ _MatTabGroupBase.prototype._tabsSubscription; /** * Subscription to changes in the tab labels. * @type {?} * @private */ _MatTabGroupBase.prototype._tabLabelSubscription; /** * @type {?} * @private */ _MatTabGroupBase.prototype._dynamicHeight; /** * @type {?} * @private */ _MatTabGroupBase.prototype._selectedIndex; /** * Position of the tab header. * @type {?} */ _MatTabGroupBase.prototype.headerPosition; /** * @type {?} * @private */ _MatTabGroupBase.prototype._animationDuration; /** * Whether pagination should be disabled. This can be used to avoid unnecessary * layout recalculations if it's known that pagination won't be required. * @type {?} */ _MatTabGroupBase.prototype.disablePagination; /** * @type {?} * @private */ _MatTabGroupBase.prototype._backgroundColor; /** * Output to enable support for two-way binding on `[(selectedIndex)]` * @type {?} */ _MatTabGroupBase.prototype.selectedIndexChange; /** * Event emitted when focus has changed within a tab group. * @type {?} */ _MatTabGroupBase.prototype.focusChange; /** * Event emitted when the body animation has completed * @type {?} */ _MatTabGroupBase.prototype.animationDone; /** * Event emitted when the tab selection has changed. * @type {?} */ _MatTabGroupBase.prototype.selectedTabChange; /** * @type {?} * @private */ _MatTabGroupBase.prototype._groupId; /** * @type {?} * @protected */ _MatTabGroupBase.prototype._changeDetectorRef; /** @type {?} */ _MatTabGroupBase.prototype._animationMode; } /** * Material design tab-group component. Supports basic tab pairs (label + content) and includes * animated ink-bar, keyboard navigation, and screen reader. * See: https://material.io/design/components/tabs.html */ class MatTabGroup extends _MatTabGroupBase { /** * @param {?} elementRef * @param {?} changeDetectorRef * @param {?=} defaultConfig * @param {?=} animationMode */ constructor(elementRef, changeDetectorRef, defaultConfig, animationMode) { super(elementRef, changeDetectorRef, defaultConfig, animationMode); } } MatTabGroup.decorators = [ { type: Component, args: [{ selector: 'mat-tab-group', exportAs: 'matTabGroup', template: "<mat-tab-header #tabHeader\n [selectedIndex]=\"selectedIndex || 0\"\n [disableRipple]=\"disableRipple\"\n [disablePagination]=\"disablePagination\"\n (indexFocused)=\"_focusChanged($event)\"\n (selectFocusedIndex)=\"selectedIndex = $event\">\n <div class=\"mat-tab-label\" role=\"tab\" matTabLabelWrapper mat-ripple cdkMonitorElementFocus\n *ngFor=\"let tab of _tabs; let i = index\"\n [id]=\"_getTabLabelId(i)\"\n [attr.tabIndex]=\"_getTabIndex(tab, i)\"\n [attr.aria-posinset]=\"i + 1\"\n [attr.aria-setsize]=\"_tabs.length\"\n [attr.aria-controls]=\"_getTabContentId(i)\"\n [attr.aria-selected]=\"selectedIndex == i\"\n [attr.aria-label]=\"tab.ariaLabel || null\"\n [attr.aria-labelledby]=\"(!tab.ariaLabel && tab.ariaLabelledby) ? tab.ariaLabelledby : null\"\n [class.mat-tab-label-active]=\"selectedIndex == i\"\n [disabled]=\"tab.disabled\"\n [matRippleDisabled]=\"tab.disabled || disableRipple\"\n (click)=\"_handleClick(tab, tabHeader, i)\">\n\n\n <div class=\"mat-tab-label-content\">\n <!-- If there is a label template, use it. -->\n <ng-template [ngIf]=\"tab.templateLabel\">\n <ng-template [cdkPortalOutlet]=\"tab.templateLabel\"></ng-template>\n </ng-template>\n\n <!-- If there is not a label template, fall back to the text label. -->\n <ng-template [ngIf]=\"!tab.templateLabel\">{{tab.textLabel}}</ng-template>\n </div>\n </div>\n</mat-tab-header>\n\n<div\n class=\"mat-tab-body-wrapper\"\n [class._mat-animation-noopable]=\"_animationMode === 'NoopAnimations'\"\n #tabBodyWrapper>\n <mat-tab-body role=\"tabpanel\"\n *ngFor=\"let tab of _tabs; let i = index\"\n [id]=\"_getTabContentId(i)\"\n [attr.aria-labelledby]=\"_getTabLabelId(i)\"\n [class.mat-tab-body-active]=\"selectedIndex == i\"\n [content]=\"tab.content!\"\n [position]=\"tab.position!\"\n [origin]=\"tab.origi