@angular/material
Version:
Angular Material
1,306 lines (1,293 loc) • 85.7 kB
JavaScript
/**
* @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/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/keycodes'), require('@angular/cdk/scrolling'), require('@angular/cdk/platform'), require('@angular/cdk/observers'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('@angular/material/tabs', ['exports', '@angular/core', '@angular/cdk/portal', '@angular/material/core', 'rxjs', '@angular/animations', '@angular/cdk/bidi', 'rxjs/operators', '@angular/cdk/coercion', '@angular/cdk/keycodes', '@angular/cdk/scrolling', '@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.cdk.portal,global.ng.material.core,global.Rx,global.ng.animations,global.ng.cdk.bidi,global.Rx.operators,global.ng.cdk.coercion,global.ng.cdk.keycodes,global.ng.cdk.scrolling,global.ng.cdk.platform,global.ng.cdk.observers,global.ng.common));
}(this, (function (exports,core,portal,core$1,rxjs,animations,bidi,operators,coercion,keycodes,scrolling,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 = 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]; };
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} checked by tsc
*/
/**
* Injection token for the MatInkBar's Positioner.
*/
var /** @type {?} */ _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() {
var /** @type {?} */ method = 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) {
this._elementRef = _elementRef;
this._ngZone = _ngZone;
this._inkBarPositioner = _inkBarPositioner;
}
/**
* 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(function () {
requestAnimationFrame(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
* @return {?}
*/
MatInkBar.prototype._setStyles = /**
* Sets the proper styles to the ink bar element.
* @param {?} element
* @return {?}
*/
function (element) {
var /** @type {?} */ positions = this._inkBarPositioner(element);
var /** @type {?} */ 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',
},
},] },
];
/** @nocollapse */
MatInkBar.ctorParameters = function () { return [
{ type: core.ElementRef, },
{ type: core.NgZone, },
{ type: undefined, decorators: [{ type: core.Inject, args: [_MAT_INK_BAR_POSITIONER,] },] },
]; };
return MatInkBar;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Used to flag tab labels for use with the portal directive
*/
var MatTabLabel = /** @class */ (function (_super) {
__extends(MatTabLabel, _super);
function MatTabLabel(templateRef, viewContainerRef) {
return _super.call(this, templateRef, viewContainerRef) || this;
}
MatTabLabel.decorators = [
{ type: core.Directive, args: [{
selector: '[mat-tab-label], [matTabLabel]',
},] },
];
/** @nocollapse */
MatTabLabel.ctorParameters = function () { return [
{ type: core.TemplateRef, },
{ type: core.ViewContainerRef, },
]; };
return MatTabLabel;
}(portal.CdkPortal));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} 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} checked by tsc
*/
/**
* \@docs-private
*/
var /**
* \@docs-private
*/
MatTabBase = /** @class */ (function () {
function MatTabBase() {
}
return MatTabBase;
}());
var /** @type {?} */ _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;
/**
* The plain text label for the tab, used when there is no template label.
*/
_this.textLabel = '';
/**
* The portal that will be the hosted content of the tab
*/
_this._contentPortal = null;
/**
* Emits whenever the label changes.
*/
_this._labelChange = new rxjs.Subject();
/**
* Emits whenever the disable changes
*/
_this._disableChange = 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')) {
this._labelChange.next();
}
if (changes.hasOwnProperty('disabled')) {
this._disableChange.next();
}
};
/**
* @return {?}
*/
MatTab.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this._disableChange.complete();
this._labelChange.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,] },],
"_explicitContent": [{ type: core.ContentChild, args: [MatTabContent, { read: core.TemplateRef },] },],
"_implicitContent": [{ type: core.ViewChild, args: [core.TemplateRef,] },],
"textLabel": [{ type: core.Input, args: ['label',] },],
};
return MatTab;
}(_MatTabMixinBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Animations used by the Material tabs.
*/
var /** @type {?} */ matTabsAnimations = {
/** Animation translates a tab along the X axis. */
translateTab: animations.trigger('translateTab', [
// Note: transitions to `none` instead of 0, because some browsers might blur the content.
animations.state('center, void, left-origin-center, right-origin-center', animations.style({ transform: 'none' })),
animations.state('left', animations.style({ transform: 'translate3d(-100%, 0, 0)' })),
animations.state('right', animations.style({ transform: 'translate3d(100%, 0, 0)' })),
animations.transition('* => left, * => right, left => center, right => center', animations.animate('500ms cubic-bezier(0.35, 0, 0.25, 1)')),
animations.transition('void => left-origin-center', [
animations.style({ transform: 'translate3d(-100%, 0, 0)' }),
animations.animate('500ms cubic-bezier(0.35, 0, 0.25, 1)')
]),
animations.transition('void => right-origin-center', [
animations.style({ transform: 'translate3d(100%, 0, 0)' }),
animations.animate('500ms cubic-bezier(0.35, 0, 0.25, 1)')
])
])
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} 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(function (isCentering) {
if (isCentering && !_this.hasAttached()) {
_this.attach(_this._host._content);
}
});
this._leavingSub = this._host._afterLeavingCenter.subscribe(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(function () { return MatTabBody; }),] },] },
]; };
return MatTabBodyPortal;
}(portal.CdkPortalOutlet));
/**
* Wrapper for the contents of a tab.
* \@docs-private
*/
var MatTabBody = /** @class */ (function () {
function MatTabBody(_elementRef, _dir) {
this._elementRef = _elementRef;
this._dir = _dir;
/**
* 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);
}
Object.defineProperty(MatTabBody.prototype, "position", {
set: /**
* The shifted index position of the tab body, where zero represents the active center tab.
* @param {?} position
* @return {?}
*/
function (position) {
if (position < 0) {
this._position = this._getLayoutDirection() == 'ltr' ? 'left' : 'right';
}
else if (position > 0) {
this._position = this._getLayoutDirection() == 'ltr' ? 'right' : 'left';
}
else {
this._position = 'center';
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MatTabBody.prototype, "origin", {
set: /**
* The origin position from which this tab should appear when it is centered into view.
* @param {?} origin
* @return {?}
*/
function (origin) {
if (origin == null) {
return;
}
var /** @type {?} */ dir = this._getLayoutDirection();
if ((dir == 'ltr' && origin <= 0) || (dir == 'rtl' && origin > 0)) {
this._origin = 'left';
}
else {
this._origin = 'right';
}
},
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 {?}
*/
MatTabBody.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) {
this._position = this._origin == 'left' ? 'left-origin-center' : 'right-origin-center';
}
};
/**
* @param {?} e
* @return {?}
*/
MatTabBody.prototype._onTranslateTabStarted = /**
* @param {?} e
* @return {?}
*/
function (e) {
var /** @type {?} */ isCentering = this._isCenterPosition(e.toState);
this._beforeCentering.emit(isCentering);
if (isCentering) {
this._onCentering.emit(this._elementRef.nativeElement.clientHeight);
}
};
/**
* @param {?} e
* @return {?}
*/
MatTabBody.prototype._onTranslateTabComplete = /**
* @param {?} e
* @return {?}
*/
function (e) {
// If the transition to the center is complete, emit an event.
if (this._isCenterPosition(e.toState) && this._isCenterPosition(this._position)) {
this._onCentered.emit();
}
if (this._isCenterPosition(e.fromState) && !this._isCenterPosition(this._position)) {
this._afterLeavingCenter.emit();
}
};
/** The text direction of the containing app. */
/**
* The text direction of the containing app.
* @return {?}
*/
MatTabBody.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 {?}
*/
MatTabBody.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';
};
MatTabBody.decorators = [
{ type: core.Component, args: [{selector: 'mat-tab-body',
template: "<div class=\"mat-tab-body-content\" #content [@translateTab]=\"_position\" (@translateTab.start)=\"_onTranslateTabStarted($event)\" (@translateTab.done)=\"_onTranslateTabComplete($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 },] },
]; };
MatTabBody.propDecorators = {
"_onCentering": [{ type: core.Output },],
"_beforeCentering": [{ type: core.Output },],
"_afterLeavingCenter": [{ type: core.Output },],
"_onCentered": [{ type: core.Output },],
"_portalHost": [{ type: core.ViewChild, args: [portal.PortalHostDirective,] },],
"_content": [{ type: core.Input, args: ['content',] },],
"position": [{ type: core.Input },],
"origin": [{ type: core.Input },],
};
return MatTabBody;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* \@docs-private
*/
var /**
* \@docs-private
*/
MatTabLabelWrapperBase = /** @class */ (function () {
function MatTabLabelWrapperBase() {
}
return MatTabLabelWrapperBase;
}());
var /** @type {?} */ _MatTabLabelWrapperMixinBase = core$1.mixinDisabled(MatTabLabelWrapperBase);
/**
* Used in the `mat-tab-group` view to display tab labels.
* \@docs-private
*/
var MatTabLabelWrapper = /** @class */ (function (_super) {
__extends(MatTabLabelWrapper, _super);
function MatTabLabelWrapper(elementRef) {
var _this = _super.call(this) || this;
_this.elementRef = elementRef;
return _this;
}
/** Sets focus on the wrapper element */
/**
* Sets focus on the wrapper element
* @return {?}
*/
MatTabLabelWrapper.prototype.focus = /**
* Sets focus on the wrapper element
* @return {?}
*/
function () {
this.elementRef.nativeElement.focus();
};
/**
* @return {?}
*/
MatTabLabelWrapper.prototype.getOffsetLeft = /**
* @return {?}
*/
function () {
return this.elementRef.nativeElement.offsetLeft;
};
/**
* @return {?}
*/
MatTabLabelWrapper.prototype.getOffsetWidth = /**
* @return {?}
*/
function () {
return this.elementRef.nativeElement.offsetWidth;
};
MatTabLabelWrapper.decorators = [
{ type: core.Directive, args: [{
selector: '[matTabLabelWrapper]',
inputs: ['disabled'],
host: {
'[class.mat-tab-disabled]': 'disabled'
}
},] },
];
/** @nocollapse */
MatTabLabelWrapper.ctorParameters = function () { return [
{ type: core.ElementRef, },
]; };
return MatTabLabelWrapper;
}(_MatTabLabelWrapperMixinBase));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* The distance in pixels that will be overshot when scrolling a tab label into view. This helps
* provide a small affordance to the label next to it.
*/
var /** @type {?} */ EXAGGERATED_OVERSCROLL = 60;
/**
* \@docs-private
*/
var /**
* \@docs-private
*/
MatTabHeaderBase = /** @class */ (function () {
function MatTabHeaderBase() {
}
return MatTabHeaderBase;
}());
var /** @type {?} */ _MatTabHeaderMixinBase = core$1.mixinDisableRipple(MatTabHeaderBase);
/**
* The header of the tab group which displays a list of all the tabs in the tab group. Includes
* an ink bar that follows the currently selected tab. When the tabs list's width exceeds the
* width of the header container, then arrows will be displayed to allow the user to scroll
* left and right across the header.
* \@docs-private
*/
var MatTabHeader = /** @class */ (function (_super) {
__extends(MatTabHeader, _super);
function MatTabHeader(_elementRef, _changeDetectorRef, _viewportRuler, _dir) {
var _this = _super.call(this) || this;
_this._elementRef = _elementRef;
_this._changeDetectorRef = _changeDetectorRef;
_this._viewportRuler = _viewportRuler;
_this._dir = _dir;
/**
* The tab index that is focused.
*/
_this._focusIndex = 0;
/**
* The distance in pixels that the tab labels should be translated to the left.
*/
_this._scrollDistance = 0;
/**
* Whether the header should scroll to the selected index after the view has been checked.
*/
_this._selectedIndexChanged = false;
/**
* Combines listeners that will re-align the ink bar whenever they're invoked.
*/
_this._realignInkBar = rxjs.Subscription.EMPTY;
/**
* Whether the controls for pagination should be displayed
*/
_this._showPaginationControls = false;
/**
* Whether the tab list can be scrolled more towards the end of the tab label list.
*/
_this._disableScrollAfter = true;
/**
* Whether the tab list can be scrolled more towards the beginning of the tab label list.
*/
_this._disableScrollBefore = true;
_this._selectedIndex = 0;
/**
* Event emitted when the option is selected.
*/
_this.selectFocusedIndex = new core.EventEmitter();
/**
* Event emitted when a label is focused.
*/
_this.indexFocused = new core.EventEmitter();
return _this;
}
Object.defineProperty(MatTabHeader.prototype, "selectedIndex", {
get: /**
* The index of the active tab.
* @return {?}
*/
function () { return this._selectedIndex; },
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
value = coercion.coerceNumberProperty(value);
this._selectedIndexChanged = this._selectedIndex != value;
this._selectedIndex = value;
this._focusIndex = value;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
MatTabHeader.prototype.ngAfterContentChecked = /**
* @return {?}
*/
function () {
// If the number of tab labels have changed, check if scrolling should be enabled
if (this._tabLabelCount != this._labelWrappers.length) {
this._updatePagination();
this._tabLabelCount = this._labelWrappers.length;
this._changeDetectorRef.markForCheck();
}
// If the selected index has changed, scroll to the label and check if the scrolling controls
// should be disabled.
if (this._selectedIndexChanged) {
this._scrollToLabel(this._selectedIndex);
this._checkScrollingControls();
this._alignInkBarToSelectedTab();
this._selectedIndexChanged = false;
this._changeDetectorRef.markForCheck();
}
// If the scroll distance has been changed (tab selected, focused, scroll controls activated),
// then translate the header to reflect this.
if (this._scrollDistanceChanged) {
this._updateTabScrollPosition();
this._scrollDistanceChanged = false;
this._changeDetectorRef.markForCheck();
}
};
/**
* @param {?} event
* @return {?}
*/
MatTabHeader.prototype._handleKeydown = /**
* @param {?} event
* @return {?}
*/
function (event) {
switch (event.keyCode) {
case keycodes.RIGHT_ARROW:
this._focusNextTab();
break;
case keycodes.LEFT_ARROW:
this._focusPreviousTab();
break;
case keycodes.HOME:
this._focusFirstTab();
event.preventDefault();
break;
case keycodes.END:
this._focusLastTab();
event.preventDefault();
break;
case keycodes.ENTER:
case keycodes.SPACE:
this.selectFocusedIndex.emit(this.focusIndex);
event.preventDefault();
break;
}
};
/**
* Aligns the ink bar to the selected tab on load.
*/
/**
* Aligns the ink bar to the selected tab on load.
* @return {?}
*/
MatTabHeader.prototype.ngAfterContentInit = /**
* Aligns the ink bar to the selected tab on load.
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ dirChange = this._dir ? this._dir.change : rxjs.of(null);
var /** @type {?} */ resize = this._viewportRuler.change(150);
var /** @type {?} */ realign = function () {
_this._updatePagination();
_this._alignInkBarToSelectedTab();
};
// Defer the first call in order to allow for slower browsers to lay out the elements.
// This helps in cases where the user lands directly on a page with paginated tabs.
typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame(realign) : realign();
this._realignInkBar = rxjs.merge(dirChange, resize).subscribe(realign);
};
/**
* @return {?}
*/
MatTabHeader.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this._realignInkBar.unsubscribe();
};
/**
* Callback for when the MutationObserver detects that the content has changed.
*/
/**
* Callback for when the MutationObserver detects that the content has changed.
* @return {?}
*/
MatTabHeader.prototype._onContentChanges = /**
* Callback for when the MutationObserver detects that the content has changed.
* @return {?}
*/
function () {
this._updatePagination();
this._alignInkBarToSelectedTab();
this._changeDetectorRef.markForCheck();
};
/**
* Updating the view whether pagination should be enabled or not
*/
/**
* Updating the view whether pagination should be enabled or not
* @return {?}
*/
MatTabHeader.prototype._updatePagination = /**
* Updating the view whether pagination should be enabled or not
* @return {?}
*/
function () {
this._checkPaginationEnabled();
this._checkScrollingControls();
this._updateTabScrollPosition();
};
Object.defineProperty(MatTabHeader.prototype, "focusIndex", {
/** Tracks which element has focus; used for keyboard navigation */
get: /**
* Tracks which element has focus; used for keyboard navigation
* @return {?}
*/
function () { return this._focusIndex; },
/** When the focus index is set, we must manually send focus to the correct label */
set: /**
* When the focus index is set, we must manually send focus to the correct label
* @param {?} value
* @return {?}
*/
function (value) {
if (!this._isValidIndex(value) || this._focusIndex == value) {
return;
}
this._focusIndex = value;
this.indexFocused.emit(value);
this._setTabFocus(value);
},
enumerable: true,
configurable: true
});
/**
* Determines if an index is valid. If the tabs are not ready yet, we assume that the user is
* providing a valid index and return true.
*/
/**
* Determines if an index is valid. If the tabs are not ready yet, we assume that the user is
* providing a valid index and return true.
* @param {?} index
* @return {?}
*/
MatTabHeader.prototype._isValidIndex = /**
* Determines if an index is valid. If the tabs are not ready yet, we assume that the user is
* providing a valid index and return true.
* @param {?} index
* @return {?}
*/
function (index) {
if (!this._labelWrappers) {
return true;
}
var /** @type {?} */ tab = this._labelWrappers ? this._labelWrappers.toArray()[index] : null;
return !!tab && !tab.disabled;
};
/**
* Sets focus on the HTML element for the label wrapper and scrolls it into the view if
* scrolling is enabled.
*/
/**
* Sets focus on the HTML element for the label wrapper and scrolls it into the view if
* scrolling is enabled.
* @param {?} tabIndex
* @return {?}
*/
MatTabHeader.prototype._setTabFocus = /**
* Sets focus on the HTML element for the label wrapper and scrolls it into the view if
* scrolling is enabled.
* @param {?} tabIndex
* @return {?}
*/
function (tabIndex) {
if (this._showPaginationControls) {
this._scrollToLabel(tabIndex);
}
if (this._labelWrappers && this._labelWrappers.length) {
this._labelWrappers.toArray()[tabIndex].focus();
// Do not let the browser manage scrolling to focus the element, this will be handled
// by using translation. In LTR, the scroll left should be 0. In RTL, the scroll width
// should be the full width minus the offset width.
var /** @type {?} */ containerEl = this._tabListContainer.nativeElement;
var /** @type {?} */ dir = this._getLayoutDirection();
if (dir == 'ltr') {
containerEl.scrollLeft = 0;
}
else {
containerEl.scrollLeft = containerEl.scrollWidth - containerEl.offsetWidth;
}
}
};
/**
* Moves the focus towards the beginning or the end of the list depending on the offset provided.
* Valid offsets are 1 and -1.
*/
/**
* Moves the focus towards the beginning or the end of the list depending on the offset provided.
* Valid offsets are 1 and -1.
* @param {?} offset
* @return {?}
*/
MatTabHeader.prototype._moveFocus = /**
* Moves the focus towards the beginning or the end of the list depending on the offset provided.
* Valid offsets are 1 and -1.
* @param {?} offset
* @return {?}
*/
function (offset) {
if (this._labelWrappers) {
var /** @type {?} */ tabs = this._labelWrappers.toArray();
for (var /** @type {?} */ i = this.focusIndex + offset; i < tabs.length && i >= 0; i += offset) {
if (this._isValidIndex(i)) {
this.focusIndex = i;
return;
}
}
}
};
/** Increment the focus index by 1 until a valid tab is found. */
/**
* Increment the focus index by 1 until a valid tab is found.
* @return {?}
*/
MatTabHeader.prototype._focusNextTab = /**
* Increment the focus index by 1 until a valid tab is found.
* @return {?}
*/
function () {
this._moveFocus(this._getLayoutDirection() == 'ltr' ? 1 : -1);
};
/** Decrement the focus index by 1 until a valid tab is found. */
/**
* Decrement the focus index by 1 until a valid tab is found.
* @return {?}
*/
MatTabHeader.prototype._focusPreviousTab = /**
* Decrement the focus index by 1 until a valid tab is found.
* @return {?}
*/
function () {
this._moveFocus(this._getLayoutDirection() == 'ltr' ? -1 : 1);
};
/**
* Focuses the first tab.
* @return {?}
*/
MatTabHeader.prototype._focusFirstTab = /**
* Focuses the first tab.
* @return {?}
*/
function () {
for (var /** @type {?} */ i = 0; i < this._labelWrappers.length; i++) {
if (this._isValidIndex(i)) {
this.focusIndex = i;
break;
}
}
};
/**
* Focuses the last tab.
* @return {?}
*/
MatTabHeader.prototype._focusLastTab = /**
* Focuses the last tab.
* @return {?}
*/
function () {
for (var /** @type {?} */ i = this._labelWrappers.length - 1; i > -1; i--) {
if (this._isValidIndex(i)) {
this.focusIndex = i;
break;
}
}
};
/** The layout direction of the containing app. */
/**
* The layout direction of the containing app.
* @return {?}
*/
MatTabHeader.prototype._getLayoutDirection = /**
* The layout direction of the containing app.
* @return {?}
*/
function () {
return this._dir && this._dir.value === 'rtl' ? 'rtl' : 'ltr';
};
/** Performs the CSS transformation on the tab list that will cause the list to scroll. */
/**
* Performs the CSS transformation on the tab list that will cause the list to scroll.
* @return {?}
*/
MatTabHeader.prototype._updateTabScrollPosition = /**
* Performs the CSS transformation on the tab list that will cause the list to scroll.
* @return {?}
*/
function () {
var /** @type {?} */ scrollDistance = this.scrollDistance;
var /** @type {?} */ translateX = this._getLayoutDirection() === 'ltr' ? -scrollDistance : scrollDistance;
this._tabList.nativeElement.style.transform = "translate3d(" + translateX + "px, 0, 0)";
};
Object.defineProperty(MatTabHeader.prototype, "scrollDistance", {
/** Sets the distance in pixels that the tab header should be transformed in the X-axis. */
get: /**
* Sets the distance in pixels that the tab header should be transformed in the X-axis.
* @return {?}
*/
function () { return this._scrollDistance; },
set: /**
* @param {?} v
* @return {?}
*/
function (v) {
this._scrollDistance = Math.max(0, Math.min(this._getMaxScrollDistance(), v));
// Mark that the scroll distance has changed so that after the view is checked, the CSS
// transformation can move the header.
this._scrollDistanceChanged = true;
this._checkScrollingControls();
},
enumerable: true,
configurable: true
});
/**
* Moves the tab list in the 'before' or 'after' direction (towards the beginning of the list or
* the end of the list, respectively). The distance to scroll is computed to be a third of the
* length of the tab list view window.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
*/
/**
* Moves the tab list in the 'before' or 'after' direction (towards the beginning of the list or
* the end of the list, respectively). The distance to scroll is computed to be a third of the
* length of the tab list view window.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @param {?} scrollDir
* @return {?}
*/
MatTabHeader.prototype._scrollHeader = /**
* Moves the tab list in the 'before' or 'after' direction (towards the beginning of the list or
* the end of the list, respectively). The distance to scroll is computed to be a third of the
* length of the tab list view window.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @param {?} scrollDir
* @return {?}
*/
function (scrollDir) {
var /** @type {?} */ viewLength = this._tabListContainer.nativeElement.offsetWidth;
// Move the scroll distance one-third the length of the tab list's viewport.
this.scrollDistance += (scrollDir == 'before' ? -1 : 1) * viewLength / 3;
};
/**
* Moves the tab list such that the desired tab label (marked by index) is moved into view.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
*/
/**
* Moves the tab list such that the desired tab label (marked by index) is moved into view.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @param {?} labelIndex
* @return {?}
*/
MatTabHeader.prototype._scrollToLabel = /**
* Moves the tab list such that the desired tab label (marked by index) is moved into view.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @param {?} labelIndex
* @return {?}
*/
function (labelIndex) {
var /** @type {?} */ selectedLabel = this._labelWrappers ? this._labelWrappers.toArray()[labelIndex] : null;
if (!selectedLabel) {
return;
}
// The view length is the visible width of the tab labels.
var /** @type {?} */ viewLength = this._tabListContainer.nativeElement.offsetWidth;
var /** @type {?} */ labelBeforePos, /** @type {?} */ labelAfterPos;
if (this._getLayoutDirection() == 'ltr') {
labelBeforePos = selectedLabel.getOffsetLeft();
labelAfterPos = labelBeforePos + selectedLabel.getOffsetWidth();
}
else {
labelAfterPos = this._tabList.nativeElement.offsetWidth - selectedLabel.getOffsetLeft();
labelBeforePos = labelAfterPos - selectedLabel.getOffsetWidth();
}
var /** @type {?} */ beforeVisiblePos = this.scrollDistance;
var /** @type {?} */ afterVisiblePos = this.scrollDistance + viewLength;
if (labelBeforePos < beforeVisiblePos) {
// Scroll header to move label to the before direction
this.scrollDistance -= beforeVisiblePos - labelBeforePos + EXAGGERATED_OVERSCROLL;
}
else if (labelAfterPos > afterVisiblePos) {
// Scroll header to move label to the after direction
this.scrollDistance += labelAfterPos - afterVisiblePos + EXAGGERATED_OVERSCROLL;
}
};
/**
* Evaluate whether the pagination controls should be displayed. If the scroll width of the
* tab list is wider than the size of the header container, then the pagination controls should
* be shown.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
*/
/**
* Evaluate whether the pagination controls should be displayed. If the scroll width of the
* tab list is wider than the size of the header container, then the pagination controls should
* be shown.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @return {?}
*/
MatTabHeader.prototype._checkPaginationEnabled = /**
* Evaluate whether the pagination controls should be displayed. If the scroll width of the
* tab list is wider than the size of the header container, then the pagination controls should
* be shown.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @return {?}
*/
function () {
var /** @type {?} */ isEnabled = this._tabList.nativeElement.scrollWidth > this._elementRef.nativeElement.offsetWidth;
if (!isEnabled) {
this.scrollDistance = 0;
}
if (isEnabled !== this._showPaginationControls) {
this._changeDetectorRef.markForCheck();
}
this._showPaginationControls = isEnabled;
};
/**
* Evaluate whether the before and after controls should be enabled or disabled.
* If the header is at the beginning of the list (scroll distance is equal to 0) then disable the
* before button. If the header is at the end of the list (scroll distance is equal to the
* maximum distance we can scroll), then disable the after button.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
*/
/**
* Evaluate whether the before and after controls should be enabled or disabled.
* If the header is at the beginning of the list (scroll distance is equal to 0) then disable the
* before button. If the header is at the end of the list (scroll distance is equal to the
* maximum distance we can scroll), then disable the after button.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @return {?}
*/
MatTabHeader.prototype._checkScrollingControls = /**
* Evaluate whether the before and after controls should be enabled or disabled.
* If the header is at the beginning of the list (scroll distance is equal to 0) then disable the
* before button. If the header is at the end of the list (scroll distance is equal to the
* maximum distance we can scroll), then disable the after button.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @return {?}
*/
function () {
// Check if the pagination arrows should be activated.
this._disableScrollBefore = this.scrollDistance == 0;
this._disableScrollAfter = this.scrollDistance == this._getMaxScrollDistance();
this._changeDetectorRef.markForCheck();
};
/**
* Determines what is the maximum length in pixels that can be set for the scroll distance. This
* is equal to the difference in width between the tab list container and tab header container.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
*/
/**
* Determines what is the maximum length in pixels that can be set for the scroll distance. This
* is equal to the difference in width between the tab list container and tab header container.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @return {?}
*/
MatTabHeader.prototype._getMaxScrollDistance = /**
* Determines what is the maximum length in pixels that can be set for the scroll distance. This
* is equal to the difference in width between the tab list container and tab header container.
*
* This is an expensive call that forces a layout reflow to compute box and scroll metrics and
* should be called sparingly.
* @return {?}
*/
function () {
var /** @type {?} */ lengthOfTabList = this._tabList.nativeElement.scrollWidth;
var /** @type {?} */ viewLength = this._tabListContainer.nativeElement.offsetWidth;
return (lengthOfTabList - viewLength) || 0;
};
/** Tells the ink-bar to align itself to the current label wrapper */
/**
* Tells the ink-bar to align itself to the current label wrapper
* @return {?}
*/
MatTabHeader.prototype._alignInkBarToSelectedTab = /**
* Tells the ink-bar to align itself to the current label wrapper
* @return {?}
*/
function () {
var /** @type {?} */ selectedLabelWrapper = this._labelWrappers && this._labelWrappers.length ?
this._labelWrappers.toArray()[this.selectedIndex].elementRef.nativeElement :
null;
this._inkBar.alignToElement(selectedLabelWrapper);
};
MatTabHeader.decorators = [
{ type: core.Component, args: [{selector: 'mat-tab-header',
template: "<div class=\"mat-tab-header-pagination mat-tab-header-pagination-before mat-elevation-z4\" aria-hidden=\"true\" mat-ripple [matRippleDisabled]=\"_disableScrollBefore || disableRipple\" [class.mat-tab-header-pagination-disabled]=\"_disableScrollBefore\" (click)=\"_scrollHeader('before')\"><div class=\"mat-tab-header-pagination-chevron\"></div></div><div class=\"mat-tab-label-container\" #tabListContainer (keydown)=\"_handleKeydown($event)\"><div class=\"mat-tab-list\" #tabList role=\"tablist\" (cdkObserveContent)=\"_onContentChanges()\"><div class=\"mat-tab-labels\"><ng-content></ng-content></div><mat-ink-bar></mat-ink-bar></div></div><div class=\"mat-tab-header-pagination mat-tab-header-pagination-after mat-elevation-z4\" aria-hidden=\"true\" mat-ripple [matRippleDisabled]=\"_disableScrollAfter || disableRipple\" [class.mat-tab-header-