Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/tabs): allow coercing of booleans for all inputs #24377

Merged
merged 1 commit into from
Feb 14, 2022
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>Start the video in the first tab and navigate to the second one to see how it keeps playing.</p>

<mat-tab-group [preserveContent]="true">
<mat-tab-group preserveContent>
<mat-tab label="First">
<iframe
width="560"
Expand Down
15 changes: 13 additions & 2 deletions src/material/tabs/paginated-tab-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import {
Input,
} from '@angular/core';
import {Direction, Directionality} from '@angular/cdk/bidi';
import {coerceNumberProperty, NumberInput} from '@angular/cdk/coercion';
import {
BooleanInput,
coerceBooleanProperty,
coerceNumberProperty,
NumberInput,
} from '@angular/cdk/coercion';
import {ViewportRuler} from '@angular/cdk/scrolling';
import {FocusKeyManager, FocusableOption} from '@angular/cdk/a11y';
import {ENTER, SPACE, hasModifierKey} from '@angular/cdk/keycodes';
Expand Down Expand Up @@ -121,7 +126,13 @@ export abstract class MatPaginatedTabHeader
* layout recalculations if it's known that pagination won't be required.
*/
@Input()
disablePagination: boolean = false;
get disablePagination(): boolean {
return this._disablePagination;
}
set disablePagination(value: BooleanInput) {
this._disablePagination = coerceBooleanProperty(value);
}
private _disablePagination: boolean = false;

/** The index of the active tab. */
get selectedIndex(): number {
Expand Down
18 changes: 15 additions & 3 deletions src/material/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export abstract class _MatTabGroupBase
set dynamicHeight(value: BooleanInput) {
this._dynamicHeight = coerceBooleanProperty(value);
}
private _dynamicHeight: boolean;
private _dynamicHeight: boolean = false;

/** The index of the active tab. */
@Input()
Expand Down Expand Up @@ -161,15 +161,27 @@ export abstract class _MatTabGroupBase
* layout recalculations if it's known that pagination won't be required.
*/
@Input()
disablePagination: boolean;
get disablePagination(): boolean {
return this._disablePagination;
}
set disablePagination(value: BooleanInput) {
this._disablePagination = coerceBooleanProperty(value);
}
private _disablePagination: boolean = false;

/**
* By default tabs remove their content from the DOM while it's off-screen.
* Setting this to `true` will keep it in the DOM which will prevent elements
* like iframes and videos from reloading next time it comes back into the view.
*/
@Input()
preserveContent: boolean;
get preserveContent(): boolean {
return this._preserveContent;
}
set preserveContent(value: BooleanInput) {
this._preserveContent = coerceBooleanProperty(value);
}
private _preserveContent: boolean = false;

/** Background color of the tab group. */
@Input()
Expand Down
6 changes: 4 additions & 2 deletions tools/public_api_guard/material/tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
protected _changeDetectorRef: ChangeDetectorRef;
get contentTabIndex(): number | null;
set contentTabIndex(value: NumberInput);
disablePagination: boolean;
get disablePagination(): boolean;
set disablePagination(value: BooleanInput);
get dynamicHeight(): boolean;
set dynamicHeight(value: BooleanInput);
readonly focusChange: EventEmitter<MatTabChangeEvent>;
Expand All @@ -250,7 +251,8 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
ngAfterContentInit(): void;
// (undocumented)
ngOnDestroy(): void;
preserveContent: boolean;
get preserveContent(): boolean;
set preserveContent(value: BooleanInput);
realignInkBar(): void;
_removeTabBodyWrapperHeight(): void;
get selectedIndex(): number | null;
Expand Down