Skip to content

Commit f9547dd

Browse files
rafaelss95wagnermaciel
authored andcommitted
fix(tabs): some bugs with docs and coercion (#20356)
* fix(tabs): add missing coercion for active input * fix(tabs): add missing docs (cherry picked from commit 0ee25a2)
1 parent 95cc020 commit f9547dd

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/material/tabs/tab-content.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ export const MAT_TAB_CONTENT = new InjectionToken<MatTabContent>('MatTabContent'
2121
providers: [{provide: MAT_TAB_CONTENT, useExisting: MatTabContent}],
2222
})
2323
export class MatTabContent {
24-
constructor(public template: TemplateRef<any>) { }
24+
constructor(
25+
/** Content for the tab. */ public template: TemplateRef<any>) {}
2526
}

src/material/tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8+
import {FocusableOption, FocusMonitor} from '@angular/cdk/a11y';
89
import {Directionality} from '@angular/cdk/bidi';
10+
import {BooleanInput, coerceBooleanProperty, NumberInput} from '@angular/cdk/coercion';
911
import {Platform} from '@angular/cdk/platform';
1012
import {ViewportRuler} from '@angular/cdk/scrolling';
1113
import {
1214
AfterContentChecked,
1315
AfterContentInit,
16+
AfterViewInit,
1417
Attribute,
1518
ChangeDetectionStrategy,
1619
ChangeDetectorRef,
@@ -27,7 +30,6 @@ import {
2730
QueryList,
2831
ViewChild,
2932
ViewEncapsulation,
30-
AfterViewInit,
3133
} from '@angular/core';
3234
import {
3335
CanDisable, CanDisableCtor,
@@ -42,12 +44,10 @@ import {
4244
RippleTarget,
4345
ThemePalette,
4446
} from '@angular/material/core';
45-
import {BooleanInput, coerceBooleanProperty, NumberInput} from '@angular/cdk/coercion';
46-
import {FocusMonitor, FocusableOption} from '@angular/cdk/a11y';
4747
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
48+
import {startWith, takeUntil} from 'rxjs/operators';
4849
import {MatInkBar} from '../ink-bar';
4950
import {MatPaginatedTabHeader, MatPaginatedTabHeaderItem} from '../paginated-tab-header';
50-
import {startWith, takeUntil} from 'rxjs/operators';
5151

5252
/**
5353
* Base class with all of the `MatTabNav` functionality.
@@ -201,7 +201,9 @@ export class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewIn
201201
@Input()
202202
get active(): boolean { return this._isActive; }
203203
set active(value: boolean) {
204-
if (value !== this._isActive) {
204+
const newValue = coerceBooleanProperty(value);
205+
206+
if (newValue !== this._isActive) {
205207
this._isActive = value;
206208
this._tabNavBar.updateActiveLink(this.elementRef);
207209
}
@@ -225,7 +227,8 @@ export class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewIn
225227
}
226228

227229
constructor(
228-
private _tabNavBar: _MatTabNavBase, public elementRef: ElementRef,
230+
private _tabNavBar: _MatTabNavBase,
231+
/** @docs-private */ public elementRef: ElementRef,
229232
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalRippleOptions: RippleGlobalOptions|null,
230233
@Attribute('tabindex') tabIndex: string, private _focusMonitor: FocusMonitor,
231234
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
@@ -239,6 +242,7 @@ export class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewIn
239242
}
240243
}
241244

245+
/** Focuses the tab link. */
242246
focus() {
243247
this.elementRef.nativeElement.focus();
244248
}
@@ -251,6 +255,7 @@ export class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewIn
251255
this._focusMonitor.stopMonitoring(this.elementRef);
252256
}
253257

258+
static ngAcceptInputType_active: BooleanInput;
254259
static ngAcceptInputType_disabled: BooleanInput;
255260
static ngAcceptInputType_disableRipple: BooleanInput;
256261
static ngAcceptInputType_tabIndex: NumberInput;

tools/public_api_guard/material/tabs.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ export declare abstract class _MatTabHeaderBase extends MatPaginatedTabHeader im
8282
export declare class _MatTabLinkBase extends _MatTabLinkMixinBase implements AfterViewInit, OnDestroy, CanDisable, CanDisableRipple, HasTabIndex, RippleTarget, FocusableOption {
8383
protected _isActive: boolean;
8484
get active(): boolean;
85-
set active(value: boolean);
86-
elementRef: ElementRef;
85+
set active(value: boolean); elementRef: ElementRef;
8786
rippleConfig: RippleConfig & RippleGlobalOptions;
8887
get rippleDisabled(): boolean;
8988
constructor(_tabNavBar: _MatTabNavBase, elementRef: ElementRef, globalRippleOptions: RippleGlobalOptions | null, tabIndex: string, _focusMonitor: FocusMonitor, animationMode?: string);
9089
focus(): void;
9190
ngAfterViewInit(): void;
9291
ngOnDestroy(): void;
92+
static ngAcceptInputType_active: BooleanInput;
9393
static ngAcceptInputType_disableRipple: BooleanInput;
9494
static ngAcceptInputType_disabled: BooleanInput;
9595
static ngAcceptInputType_tabIndex: NumberInput;
@@ -180,9 +180,8 @@ export declare class MatTabChangeEvent {
180180
tab: MatTab;
181181
}
182182

183-
export declare class MatTabContent {
184-
template: TemplateRef<any>;
185-
constructor(template: TemplateRef<any>);
183+
export declare class MatTabContent { template: TemplateRef<any>;
184+
constructor( template: TemplateRef<any>);
186185
static ɵdir: i0.ɵɵDirectiveDefWithMeta<MatTabContent, "[matTabContent]", never, {}, {}, never>;
187186
static ɵfac: i0.ɵɵFactoryDef<MatTabContent, never>;
188187
}

0 commit comments

Comments
 (0)