Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions goldens/material/tabs/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,7 @@ export class MatTabLink extends InkBarItem implements AfterViewInit, OnDestroy,
// @public
export class MatTabNav extends MatPaginatedTabHeader implements AfterContentInit, AfterViewInit {
constructor();
// (undocumented)
get animationDuration(): string;
set animationDuration(value: string | number);
animationDuration: string;
get backgroundColor(): ThemePalette;
set backgroundColor(value: ThemePalette);
color: ThemePalette;
Expand All @@ -472,6 +470,8 @@ export class MatTabNav extends MatPaginatedTabHeader implements AfterContentInit
// (undocumented)
_nextPaginator: ElementRef<HTMLElement>;
// (undocumented)
static ngAcceptInputType_animationDuration: string | number;
// (undocumented)
static ngAcceptInputType_disableRipple: unknown;
// (undocumented)
static ngAcceptInputType_fitInkBarToContent: unknown;
Expand Down
13 changes: 13 additions & 0 deletions src/material/tabs/paginated-tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ const HEADER_SCROLL_INTERVAL = 100;
/** Item inside a paginated tab header. */
export type MatPaginatedTabHeaderItem = FocusableOption & {elementRef: ElementRef};

/** Normalizes an animation duration value. */
export function normalizeDuration(value: string | number): string {
const stringValue = value + '';

if (/^[0-9]+(?:\.[0-9]+)?$/.test(stringValue)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be /^[0-9]*? * instead of + because number like .5 is valid in CSS

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, although we also didn't support it until now either. I'll keep it simple for now and we can revisit if anybody runs into it.

return `${value}ms`;
} else if (/^[0-9]+(?:\.[0-9]+)?(?:ms|s)$/.test(stringValue)) {
return stringValue;
} else {
return '';
}
}

/**
* Base class for a tab header that supported pagination.
* @docs-private
Expand Down
7 changes: 1 addition & 6 deletions src/material/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {MatTabBody} from './tab-body';
import {CdkPortalOutlet} from '@angular/cdk/portal';
import {MatTabLabelWrapper} from './tab-label-wrapper';
import {Platform} from '@angular/cdk/platform';
import {normalizeDuration} from './paginated-tab-header';

/** @docs-private */
export interface MatTabGroupBaseHeader {
Expand Down Expand Up @@ -606,9 +607,3 @@ export class MatTabChangeEvent {
/** Reference to the currently-selected tab. */
tab!: MatTab;
}

/** Normalizes an animation duration value. */
function normalizeDuration(value: string | number): string {
const stringValue = value + '';
return /^\d+$/.test(stringValue) ? value + 'ms' : stringValue;
}
19 changes: 7 additions & 12 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ import {BehaviorSubject, Subject} from 'rxjs';
import {startWith, takeUntil} from 'rxjs/operators';
import {ENTER, SPACE} from '@angular/cdk/keycodes';
import {MAT_TABS_CONFIG, MatTabsConfig} from '../tab-config';
import {MatPaginatedTabHeader, MatPaginatedTabHeaderItem} from '../paginated-tab-header';
import {
MatPaginatedTabHeader,
MatPaginatedTabHeaderItem,
normalizeDuration,
} from '../paginated-tab-header';
import {CdkObserveContent} from '@angular/cdk/observers';
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';

Expand Down Expand Up @@ -89,17 +93,8 @@ export class MatTabNav extends MatPaginatedTabHeader implements AfterContentInit
@Input({alias: 'mat-stretch-tabs', transform: booleanAttribute})
stretchTabs: boolean = true;

@Input()
get animationDuration(): string {
return this._animationDuration;
}

set animationDuration(value: string | number) {
const stringValue = value + '';
this._animationDuration = /^\d+$/.test(stringValue) ? value + 'ms' : stringValue;
}

private _animationDuration!: string;
/** Duration for the header animation. Will be normalized to milliseconds if no units are set. */
@Input({transform: normalizeDuration}) animationDuration: string = '';

/** Query list of all tab links of the tab navigation. */
@ContentChildren(forwardRef(() => MatTabLink), {descendants: true})
Expand Down
Loading