UNPKG

@angular/material

Version:
1,264 lines (1,252 loc) 117 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 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/platform-browser/animations'), require('@angular/cdk/portal'), require('@angular/material/core'), require('rxjs'), require('@angular/animations'), require('@angular/cdk/bidi'), require('rxjs/operators'), require('@angular/cdk/coercion'), require('@angular/cdk/scrolling'), require('@angular/cdk/a11y'), require('@angular/cdk/keycodes'), require('@angular/cdk/platform'), require('@angular/cdk/observers'), require('@angular/common')) : typeof define === 'function' && define.amd ? define('@angular/material/tabs', ['exports', '@angular/core', '@angular/platform-browser/animations', '@angular/cdk/portal', '@angular/material/core', 'rxjs', '@angular/animations', '@angular/cdk/bidi', 'rxjs/operators', '@angular/cdk/coercion', '@angular/cdk/scrolling', '@angular/cdk/a11y', '@angular/cdk/keycodes', '@angular/cdk/platform', '@angular/cdk/observers', '@angular/common'], factory) : (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.tabs = {}),global.ng.core,global.ng.platformBrowser.animations,global.ng.cdk.portal,global.ng.material.core,global.rxjs,global.ng.animations,global.ng.cdk.bidi,global.rxjs.operators,global.ng.cdk.coercion,global.ng.cdk.scrolling,global.ng.cdk.a11y,global.ng.cdk.keycodes,global.ng.cdk.platform,global.ng.cdk.observers,global.ng.common)); }(this, (function (exports,core,animations,portal,core$1,rxjs,animations$1,bidi,operators,coercion,scrolling,a11y,keycodes,platform,observers,common) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Injection token for the MatInkBar's Positioner. * @type {?} */ var _MAT_INK_BAR_POSITIONER = new core.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 {?} */ var method = (/** * @param {?} element * @return {?} */ function (element) { return ({ 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 */ var MatInkBar = /** @class */ (function () { function MatInkBar(_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 */ /** * 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 {?} */ MatInkBar.prototype.alignToElement = /** * 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 {?} */ function (element) { var _this = this; this.show(); if (typeof requestAnimationFrame !== 'undefined') { this._ngZone.runOutsideAngular((/** * @return {?} */ function () { requestAnimationFrame((/** * @return {?} */ function () { return _this._setStyles(element); })); })); } else { this._setStyles(element); } }; /** Shows the ink bar. */ /** * Shows the ink bar. * @return {?} */ MatInkBar.prototype.show = /** * Shows the ink bar. * @return {?} */ function () { this._elementRef.nativeElement.style.visibility = 'visible'; }; /** Hides the ink bar. */ /** * Hides the ink bar. * @return {?} */ MatInkBar.prototype.hide = /** * Hides the ink bar. * @return {?} */ function () { this._elementRef.nativeElement.style.visibility = 'hidden'; }; /** * Sets the proper styles to the ink bar element. * @param element */ /** * Sets the proper styles to the ink bar element. * @private * @param {?} element * @return {?} */ MatInkBar.prototype._setStyles = /** * Sets the proper styles to the ink bar element. * @private * @param {?} element * @return {?} */ function (element) { /** @type {?} */ var positions = this._inkBarPositioner(element); /** @type {?} */ var inkBar = this._elementRef.nativeElement; inkBar.style.left = positions.left; inkBar.style.width = positions.width; }; MatInkBar.decorators = [ { type: core.Directive, args: [{ selector: 'mat-ink-bar', host: { 'class': 'mat-ink-bar', '[class._mat-animation-noopable]': "_animationMode === 'NoopAnimations'", }, },] }, ]; /** @nocollapse */ MatInkBar.ctorParameters = function () { return [ { type: core.ElementRef }, { type: core.NgZone }, { type: undefined, decorators: [{ type: core.Inject, args: [_MAT_INK_BAR_POSITIONER,] }] }, { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [animations.ANIMATION_MODULE_TYPE,] }] } ]; }; return MatInkBar; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Decorates the `ng-template` tags and reads out the template from it. */ var MatTabContent = /** @class */ (function () { function MatTabContent(template) { this.template = template; } MatTabContent.decorators = [ { type: core.Directive, args: [{ selector: '[matTabContent]' },] }, ]; /** @nocollapse */ MatTabContent.ctorParameters = function () { return [ { type: core.TemplateRef } ]; }; return MatTabContent; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Used to flag tab labels for use with the portal directive */ var MatTabLabel = /** @class */ (function (_super) { __extends(MatTabLabel, _super); function MatTabLabel() { return _super !== null && _super.apply(this, arguments) || this; } MatTabLabel.decorators = [ { type: core.Directive, args: [{ selector: '[mat-tab-label], [matTabLabel]', },] }, ]; return MatTabLabel; }(portal.CdkPortal)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ // Boilerplate for applying mixins to MatTab. /** * \@docs-private */ var // Boilerplate for applying mixins to MatTab. /** * \@docs-private */ MatTabBase = /** @class */ (function () { function MatTabBase() { } return MatTabBase; }()); /** @type {?} */ var _MatTabMixinBase = core$1.mixinDisabled(MatTabBase); var MatTab = /** @class */ (function (_super) { __extends(MatTab, _super); function MatTab(_viewContainerRef) { var _this = _super.call(this) || this; _this._viewContainerRef = _viewContainerRef; /** * 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 rxjs.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; return _this; } Object.defineProperty(MatTab.prototype, "content", { /** @docs-private */ get: /** * \@docs-private * @return {?} */ function () { return this._contentPortal; }, enumerable: true, configurable: true }); /** * @param {?} changes * @return {?} */ MatTab.prototype.ngOnChanges = /** * @param {?} changes * @return {?} */ function (changes) { if (changes.hasOwnProperty('textLabel') || changes.hasOwnProperty('disabled')) { this._stateChanges.next(); } }; /** * @return {?} */ MatTab.prototype.ngOnDestroy = /** * @return {?} */ function () { this._stateChanges.complete(); }; /** * @return {?} */ MatTab.prototype.ngOnInit = /** * @return {?} */ function () { this._contentPortal = new portal.TemplatePortal(this._explicitContent || this._implicitContent, this._viewContainerRef); }; MatTab.decorators = [ { type: core.Component, args: [{selector: 'mat-tab', template: "<ng-template><ng-content></ng-content></ng-template>", inputs: ['disabled'], changeDetection: core.ChangeDetectionStrategy.OnPush, encapsulation: core.ViewEncapsulation.None, exportAs: 'matTab', },] }, ]; /** @nocollapse */ MatTab.ctorParameters = function () { return [ { type: core.ViewContainerRef } ]; }; MatTab.propDecorators = { templateLabel: [{ type: core.ContentChild, args: [MatTabLabel, { static: false },] }], _explicitContent: [{ type: core.ContentChild, args: [MatTabContent, { read: core.TemplateRef, static: true },] }], _implicitContent: [{ type: core.ViewChild, args: [core.TemplateRef, { static: true },] }], textLabel: [{ type: core.Input, args: ['label',] }], ariaLabel: [{ type: core.Input, args: ['aria-label',] }], ariaLabelledby: [{ type: core.Input, args: ['aria-labelledby',] }] }; return MatTab; }(_MatTabMixinBase)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Animations used by the Material tabs. * \@docs-private * @type {?} */ var matTabsAnimations = { /** * Animation translates a tab along the X axis. */ translateTab: animations$1.trigger('translateTab', [ // Note: transitions to `none` instead of 0, because some browsers might blur the content. animations$1.state('center, void, left-origin-center, right-origin-center', animations$1.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 animations$1.state('left', animations$1.style({ transform: 'translate3d(-100%, 0, 0)', minHeight: '1px' })), animations$1.state('right', animations$1.style({ transform: 'translate3d(100%, 0, 0)', minHeight: '1px' })), animations$1.transition('* => left, * => right, left => center, right => center', animations$1.animate('{{animationDuration}} cubic-bezier(0.35, 0, 0.25, 1)')), animations$1.transition('void => left-origin-center', [ animations$1.style({ transform: 'translate3d(-100%, 0, 0)' }), animations$1.animate('{{animationDuration}} cubic-bezier(0.35, 0, 0.25, 1)') ]), animations$1.transition('void => right-origin-center', [ animations$1.style({ transform: 'translate3d(100%, 0, 0)' }), animations$1.animate('{{animationDuration}} cubic-bezier(0.35, 0, 0.25, 1)') ]) ]) }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * The portal host directive for the contents of the tab. * \@docs-private */ var MatTabBodyPortal = /** @class */ (function (_super) { __extends(MatTabBodyPortal, _super); function MatTabBodyPortal(componentFactoryResolver, viewContainerRef, _host) { var _this = _super.call(this, componentFactoryResolver, viewContainerRef) || this; _this._host = _host; /** * Subscription to events for when the tab body begins centering. */ _this._centeringSub = rxjs.Subscription.EMPTY; /** * Subscription to events for when the tab body finishes leaving from center position. */ _this._leavingSub = rxjs.Subscription.EMPTY; return _this; } /** Set initial visibility or set up subscription for changing visibility. */ /** * Set initial visibility or set up subscription for changing visibility. * @return {?} */ MatTabBodyPortal.prototype.ngOnInit = /** * Set initial visibility or set up subscription for changing visibility. * @return {?} */ function () { var _this = this; _super.prototype.ngOnInit.call(this); this._centeringSub = this._host._beforeCentering .pipe(operators.startWith(this._host._isCenterPosition(this._host._position))) .subscribe((/** * @param {?} isCentering * @return {?} */ function (isCentering) { if (isCentering && !_this.hasAttached()) { _this.attach(_this._host._content); } })); this._leavingSub = this._host._afterLeavingCenter.subscribe((/** * @return {?} */ function () { _this.detach(); })); }; /** Clean up centering subscription. */ /** * Clean up centering subscription. * @return {?} */ MatTabBodyPortal.prototype.ngOnDestroy = /** * Clean up centering subscription. * @return {?} */ function () { _super.prototype.ngOnDestroy.call(this); this._centeringSub.unsubscribe(); this._leavingSub.unsubscribe(); }; MatTabBodyPortal.decorators = [ { type: core.Directive, args: [{ selector: '[matTabBodyHost]' },] }, ]; /** @nocollapse */ MatTabBodyPortal.ctorParameters = function () { return [ { type: core.ComponentFactoryResolver }, { type: core.ViewContainerRef }, { type: MatTabBody, decorators: [{ type: core.Inject, args: [core.forwardRef((/** * @return {?} */ function () { return MatTabBody; })),] }] } ]; }; return MatTabBodyPortal; }(portal.CdkPortalOutlet)); /** * Base class with all of the `MatTabBody` functionality. * \@docs-private * @abstract */ var _MatTabBodyBase = /** @class */ (function () { function _MatTabBodyBase(_elementRef, _dir, changeDetectorRef) { var _this = this; this._elementRef = _elementRef; this._dir = _dir; /** * Subscription to the directionality change observable. */ this._dirChangeSubscription = rxjs.Subscription.EMPTY; /** * Emits when an animation on the tab is complete. */ this._translateTabComplete = new rxjs.Subject(); /** * Event emitted when the tab begins to animate towards the center as the active tab. */ this._onCentering = new core.EventEmitter(); /** * Event emitted before the centering of the tab begins. */ this._beforeCentering = new core.EventEmitter(); /** * Event emitted before the centering of the tab begins. */ this._afterLeavingCenter = new core.EventEmitter(); /** * Event emitted when the tab completes its animation towards the center. */ this._onCentered = new core.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 {?} */ function (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(operators.distinctUntilChanged((/** * @param {?} x * @param {?} y * @return {?} */ function (x, y) { return x.fromState === y.fromState && x.toState === y.toState; }))).subscribe((/** * @param {?} event * @return {?} */ function (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(); } })); } Object.defineProperty(_MatTabBodyBase.prototype, "position", { /** The shifted index position of the tab body, where zero represents the active center tab. */ set: /** * The shifted index position of the tab body, where zero represents the active center tab. * @param {?} position * @return {?} */ function (position) { this._positionIndex = position; this._computePositionAnimationState(); }, enumerable: true, configurable: true }); /** * 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. */ /** * 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 {?} */ _MatTabBodyBase.prototype.ngOnInit = /** * 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 {?} */ function () { if (this._position == 'center' && this.origin != null) { this._position = this._computePositionFromOrigin(); } }; /** * @return {?} */ _MatTabBodyBase.prototype.ngOnDestroy = /** * @return {?} */ function () { this._dirChangeSubscription.unsubscribe(); this._translateTabComplete.complete(); }; /** * @param {?} event * @return {?} */ _MatTabBodyBase.prototype._onTranslateTabStarted = /** * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var 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. */ /** * The text direction of the containing app. * @return {?} */ _MatTabBodyBase.prototype._getLayoutDirection = /** * The text direction of the containing app. * @return {?} */ function () { return this._dir && this._dir.value === 'rtl' ? 'rtl' : 'ltr'; }; /** Whether the provided position state is considered center, regardless of origin. */ /** * Whether the provided position state is considered center, regardless of origin. * @param {?} position * @return {?} */ _MatTabBodyBase.prototype._isCenterPosition = /** * Whether the provided position state is considered center, regardless of origin. * @param {?} position * @return {?} */ function (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. */ /** * Computes the position state that will be used for the tab-body animation trigger. * @private * @param {?=} dir * @return {?} */ _MatTabBodyBase.prototype._computePositionAnimationState = /** * Computes the position state that will be used for the tab-body animation trigger. * @private * @param {?=} dir * @return {?} */ function (dir) { if (dir === void 0) { 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. */ /** * Computes the position state based on the specified origin position. This is used if the * tab is becoming visible immediately after creation. * @private * @return {?} */ _MatTabBodyBase.prototype._computePositionFromOrigin = /** * Computes the position state based on the specified origin position. This is used if the * tab is becoming visible immediately after creation. * @private * @return {?} */ function () { /** @type {?} */ var dir = this._getLayoutDirection(); if ((dir == 'ltr' && this.origin <= 0) || (dir == 'rtl' && this.origin > 0)) { return 'left-origin-center'; } return 'right-origin-center'; }; _MatTabBodyBase.decorators = [ { type: core.Directive, args: [{ // TODO(crisbeto): this selector can be removed when we update to Angular 9.0. selector: 'do-not-use-abstract-mat-tab-body-base' },] }, ]; /** @nocollapse */ _MatTabBodyBase.ctorParameters = function () { return [ { type: core.ElementRef }, { type: bidi.Directionality, decorators: [{ type: core.Optional }] }, { type: core.ChangeDetectorRef } ]; }; _MatTabBodyBase.propDecorators = { _onCentering: [{ type: core.Output }], _beforeCentering: [{ type: core.Output }], _afterLeavingCenter: [{ type: core.Output }], _onCentered: [{ type: core.Output }], _content: [{ type: core.Input, args: ['content',] }], origin: [{ type: core.Input }], animationDuration: [{ type: core.Input }], position: [{ type: core.Input }] }; return _MatTabBodyBase; }()); /** * Wrapper for the contents of a tab. * \@docs-private */ var MatTabBody = /** @class */ (function (_super) { __extends(MatTabBody, _super); function MatTabBody(elementRef, dir, changeDetectorRef) { return _super.call(this, elementRef, dir, changeDetectorRef) || this; } MatTabBody.decorators = [ { type: core.Component, args: [{selector: 'mat-tab-body', template: "<div class=\"mat-tab-body-content\" #content [@translateTab]=\"{ value: _position, params: {animationDuration: animationDuration} }\" (@translateTab.start)=\"_onTranslateTabStarted($event)\" (@translateTab.done)=\"_translateTabComplete.next($event)\"><ng-template matTabBodyHost></ng-template></div>", styles: [".mat-tab-body-content{height:100%;overflow:auto}.mat-tab-group-dynamic-height .mat-tab-body-content{overflow:hidden}"], encapsulation: core.ViewEncapsulation.None, changeDetection: core.ChangeDetectionStrategy.OnPush, animations: [matTabsAnimations.translateTab], host: { 'class': 'mat-tab-body', } },] }, ]; /** @nocollapse */ MatTabBody.ctorParameters = function () { return [ { type: core.ElementRef }, { type: bidi.Directionality, decorators: [{ type: core.Optional }] }, { type: core.ChangeDetectorRef } ]; }; MatTabBody.propDecorators = { _portalHost: [{ type: core.ViewChild, args: [portal.PortalHostDirective, { static: false },] }] }; return MatTabBody; }(_MatTabBodyBase)); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Used to generate unique ID's for each tab component * @type {?} */ var nextId = 0; /** * A simple change event emitted on focus or selection changes. */ var /** * A simple change event emitted on focus or selection changes. */ MatTabChangeEvent = /** @class */ (function () { function MatTabChangeEvent() { } return MatTabChangeEvent; }()); /** * Injection token that can be used to provide the default options the tabs module. * @type {?} */ var MAT_TABS_CONFIG = new core.InjectionToken('MAT_TABS_CONFIG'); // Boilerplate for applying mixins to MatTabGroup. /** * \@docs-private */ var // Boilerplate for applying mixins to MatTabGroup. /** * \@docs-private */ MatTabGroupMixinBase = /** @class */ (function () { function MatTabGroupMixinBase(_elementRef) { this._elementRef = _elementRef; } return MatTabGroupMixinBase; }()); /** @type {?} */ var _MatTabGroupMixinBase = core$1.mixinColor(core$1.mixinDisableRipple(MatTabGroupMixinBase), 'primary'); /** * Base class with all of the `MatTabGroupBase` functionality. * \@docs-private * @abstract */ var _MatTabGroupBase = /** @class */ (function (_super) { __extends(_MatTabGroupBase, _super); function _MatTabGroupBase(elementRef, _changeDetectorRef, defaultConfig, _animationMode) { var _this = _super.call(this, elementRef) || this; _this._changeDetectorRef = _changeDetectorRef; _this._animationMode = _animationMode; /** * 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 = rxjs.Subscription.EMPTY; /** * Subscription to changes in the tab labels. */ _this._tabLabelSubscription = rxjs.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 core.EventEmitter(); /** * Event emitted when focus has changed within a tab group. */ _this.focusChange = new core.EventEmitter(); /** * Event emitted when the body animation has completed */ _this.animationDone = new core.EventEmitter(); /** * Event emitted when the tab selection has changed. */ _this.selectedTabChange = new core.EventEmitter(true); _this._groupId = nextId++; _this.animationDuration = defaultConfig && defaultConfig.animationDuration ? defaultConfig.animationDuration : '500ms'; return _this; } Object.defineProperty(_MatTabGroupBase.prototype, "dynamicHeight", { /** Whether the tab group should grow to the size of the active tab. */ get: /** * Whether the tab group should grow to the size of the active tab. * @return {?} */ function () { return this._dynamicHeight; }, set: /** * @param {?} value * @return {?} */ function (value) { this._dynamicHeight = coercion.coerceBooleanProperty(value); }, enumerable: true, configurable: true }); Object.defineProperty(_MatTabGroupBase.prototype, "selectedIndex", { /** The index of the active tab. */ get: /** * The index of the active tab. * @return {?} */ function () { return this._selectedIndex; }, set: /** * @param {?} value * @return {?} */ function (value) { this._indexToSelect = coercion.coerceNumberProperty(value, null); }, enumerable: true, configurable: true }); Object.defineProperty(_MatTabGroupBase.prototype, "animationDuration", { /** Duration for the tab animation. Will be normalized to milliseconds if no units are set. */ get: /** * Duration for the tab animation. Will be normalized to milliseconds if no units are set. * @return {?} */ function () { return this._animationDuration; }, set: /** * @param {?} value * @return {?} */ function (value) { this._animationDuration = /^\d+$/.test(value) ? value + 'ms' : value; }, enumerable: true, configurable: true }); Object.defineProperty(_MatTabGroupBase.prototype, "backgroundColor", { /** Background color of the tab group. */ get: /** * Background color of the tab group. * @return {?} */ function () { return this._backgroundColor; }, set: /** * @param {?} value * @return {?} */ function (value) { /** @type {?} */ var nativeElement = this._elementRef.nativeElement; nativeElement.classList.remove("mat-background-" + this.backgroundColor); if (value) { nativeElement.classList.add("mat-background-" + value); } this._backgroundColor = value; }, enumerable: true, configurable: true }); /** * 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). */ /** * 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 {?} */ _MatTabGroupBase.prototype.ngAfterContentChecked = /** * 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 {?} */ function () { var _this = this; // 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 {?} */ var 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 {?} */ var isFirstRun_1 = this._selectedIndex == null; if (!isFirstRun_1) { 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 {?} */ function () { _this._tabs.forEach((/** * @param {?} tab * @param {?} index * @return {?} */ function (tab, index) { return tab.isActive = index === indexToSelect; })); if (!isFirstRun_1) { _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 {?} */ function (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 {?} */ _MatTabGroupBase.prototype.ngAfterContentInit = /** * @return {?} */ function () { var _this = this; 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 {?} */ function () { /** @type {?} */ var 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 {?} */ var tabs = _this._tabs.toArray(); for (var 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._subscribeToTabLabels(); _this._changeDetectorRef.markForCheck(); })); }; /** * @return {?} */ _MatTabGroupBase.prototype.ngOnDestroy = /** * @return {?} */ function () { this._tabsSubscription.unsubscribe(); this._tabLabelSubscription.unsubscribe(); }; /** Re-aligns the ink bar to the selected tab element. */ /** * Re-aligns the ink bar to the selected tab element. * @return {?} */ _MatTabGroupBase.prototype.realignInkBar = /** * Re-aligns the ink bar to the selected tab element. * @return {?} */ function () { if (this._tabHeader) { this._tabHeader._alignInkBarToSelectedTab(); } }; /** * @param {?} index * @return {?} */ _MatTabGroupBase.prototype._focusChanged = /** * @param {?} index * @return {?} */ function (index) { this.focusChange.emit(this._createChangeEvent(index)); }; /** * @private * @param {?} index * @return {?} */ _MatTabGroupBase.prototype._createChangeEvent = /** * @private * @param {?} index * @return {?} */ function (index) { /** @type {?} */ var 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. */ /** * 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 {?} */ _MatTabGroupBase.prototype._subscribeToTabLabels = /** * 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 {?} */ function () { var _this = this; if (this._tabLabelSubscription) { this._tabLabelSubscription.unsubscribe(); } this._tabLabelSubscription = rxjs.merge.apply(void 0, this._tabs.map((/** * @param {?} tab * @return {?} */ function (tab) { return tab._stateChanges; }))).subscribe((/** * @return {?} */ function () { return _this._changeDetectorRef.markForCheck(); })); }; /** Clamps the given index to the bounds of 0 and the tabs length. */ /** * Clamps the given index to the bounds of 0 and the tabs length. * @private * @param {?} index * @return {?} */ _MatTabGroupBase.prototype._clampTabIndex = /** * Clamps the given index to the bounds of 0 and the tabs length. * @private * @param {?} index * @return {?} */ function (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 */ /** * Returns a unique id for each tab label element * @param {?} i * @return {?} */ _MatTabGroupBase.prototype._getTabLabelId = /** * Returns a unique id for each tab label element * @param {?} i * @return {?} */ function (i) { return "mat-tab-label-" + this._groupId + "-" + i; }; /** Returns a unique id for each tab content element */ /** * Returns a unique id for each tab content element * @param {?} i * @return {?} */ _MatTabGroupBase.prototype._getTabContentId = /** * Returns a unique id for each tab content element * @param {?} i * @return {?} */ function (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. */ /** * Sets the height of the body wrapper to the height of the activating tab if dynamic * height property is true. * @param {?} tabHeight * @return {?} */ _MatTabGroupBase.prototype._setTabBodyWrapperHeight = /** * Sets the height of the body wrapper to the height of the activating tab if dynamic * height property is true. * @param {?} tabHeight * @return {?} */ function (tabHeight) { if (!this._dynamicHeight || !this._tabBodyWrapperHeight) { return; } /** @type {?} */ var 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. */ /** * Removes the height of the tab body wrapper. * @return {?} */ _MatTabGroupBase.prototype._removeTabBodyWrapperHeight = /** * Removes the height of the tab body wrapper. * @return {?} */ function () { /** @type {?} */ var wrapper = this._tabBodyWrapper.nativeElement; this._tabBodyWrapperHeight = wrapper.clientHeight; wrapper.style.height = ''; this.animationDone.emit(); }; /** Handle click events, setting new selected index if appropriate. */ /** * Handle click events, setting new selected index if appropriate. * @param {?} tab * @param {?} tabHeader * @param {?} index * @return {?} */ _MatTabGroupBase.prototype._handleClick = /** * Handle click events, setting new selected index if appropriate. * @param {?} tab * @param {?} tabHeader * @param {?} index * @return {?} */ function (tab, tabHeader, index) { if (!tab.disabled) { this.selectedIndex = tabHeader.focusIndex = index; } }; /** Retrieves the tabindex for the tab. */ /** * Retrieves the tabindex for the tab. * @param {?} tab * @param {?} idx * @return {?} */ _MatTabGroupBase.prototype._getTabIndex = /** * Retrieves the tabindex for the tab. * @param {?} tab * @param {?} idx * @return {?} */ function (tab, idx) { if (tab.disabled) { return null; } return this.selectedIndex === idx ? 0 : -1; }; _MatTabGroupBase.decorators = [ { type: core.Directive, args: [{ // TODO(crisbeto): this selector can be removed when we update to Angular 9.0. selector: 'do-not-use-abstract-mat-tab-group-base' },] }, ]; /** @nocollapse */ _MatTabGroupBase.ctorParameters = function () { return [ { type: core.ElementRef }, { type: core.ChangeDetectorRef }, { type: undefined, decorators: [{ type: core.Inject, args: [MAT_TABS_CONFIG,] }, { type: core.Optional }] }, { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [animations.ANIMATION_MODULE_TYPE,] }] } ]; }; _MatTabGroupBase.propDecorators = { dynamicHeight: [{ type: core.Input }], selectedIndex: [{ type: core.Input }], headerPosition: [{ type: core.Input }], animationDuration: [{ type: core.Input }], backgroundColor: [{ type: core.Input }], selectedIndexChange: [{ type: core.Output }], focusChange: [{ type: core.Output }], animationDone: [{ type: core.Output }], selectedTabChange: [{ type: core.Output }] }; return _MatTabGroupBase; }(_MatTabGroupMixinBase)); /** * 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 */ var MatTabGroup = /** @class */ (function (_super) { __extends(MatTabGroup, _super); function MatTabGroup(elementRef, changeDetectorRef, defaultConfig, animationMode) { return _super.call(this, elementRef, changeDetectorRef, defaultConfig, animationMode) || this; } MatTabGroup.decorators = [ { type: core.Component, args: [{selector: 'mat-tab-group', exportAs: 'matTabGroup', template: "<mat-tab-header #tabHeader [selectedIndex]=\"selectedIndex\" [disableRipple]=\"disableRipple\" (indexFocused)=\"_focusChanged($event)\" (selectFocusedIndex)=\"selectedIndex = $event\"><div class=\"mat-tab-label\" role=\"tab\" matTabLabelWrapper mat-ripple cdkMonitorElementFocus *ngFor=\"let tab of _tabs; let i = index\" [id]=\"_getTabLabelId(i)\" [attr.tabIndex]=\"_getTabIndex(tab, i)\" [attr.aria-posinset]=\"i + 1\" [attr.aria-setsize]=\"_tabs.length\" [attr.aria-controls]=\"_getTabContentId(i)\" [attr.aria-selected]=\"selectedIndex == i\" [attr.aria-label]=\"tab.ariaLabel || null\" [attr.aria-labelledby]=\"(!tab.ariaLabel && tab.ariaLabelledby) ? tab.ariaLabelledby : null\" [class.mat-tab-label-active]=\"selectedIndex == i\" [disabled]=\"tab.disabled\" [matRippleDisabled]=\"tab.disabled || disableRipple\" (click)=\"_handleClick(tab, tabHeader, i)\"><div class=\"mat-tab-label-content\"><ng-template [ngIf]=\"tab.templateLabel\"><ng-template [cdkPortalOutlet]=\"tab.templateLabel\"></ng-template></ng-template><ng-template [ngIf]=\"!tab.templateLabel\">{{tab.textLabel}}</ng-template></div></div></mat-tab-header><div class=\"mat-tab-body-wrapper\" [class._mat-animation-noopable]=\"_animationMode === 'NoopAnimations'\" #tabBodyWrapper><mat-tab-body role=\"tabpanel\" *ngFor=\"let tab of _tabs; let i = index\" [id]=\"_getTabContentId(i)\" [attr.aria-labelledby]=\"_getTabLabelId(i)\" [class.mat-tab-body-active]=\"selectedIndex == i\" [content]=\"tab.content\" [position]=\"tab.position\" [origin]=\"tab.origin\" [animationDuration]=\"animationDuration\" (_onCentered)=\"_removeTabBodyWrapperHeight()\" (_onCentering)=\"_setTabBodyWrapperHeight($event)\"></mat-tab-body></div>", styles: [".mat-tab-group{display:flex;flex-direction:column}.mat-tab-group.mat-tab-group-inverted-header{flex-direction:column-reverse}.mat-tab-label{height:48px;padding:0 24px;cursor:pointer;box-sizing:border-box;opacity:.6;min-width:160px;text-align:center;display:inline-flex;justify-content:center;align-items:center;white-space:nowrap;position:relative}.mat-tab-label:focus{outline:0}.mat-tab-label:focus:not(.mat-tab-disabled){opacity:1}@media (-ms-high-contrast:active){.mat-tab-label:focus{outline:dotted 2px}}.mat-tab-label.mat-tab-disabled{cursor:default}@media (-ms-high-contrast:active){.mat-tab-label.ma