Skip to content

refactor(badge): rework to account for ivy changes #15556

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

Merged
merged 1 commit into from
Mar 22, 2019
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
25 changes: 15 additions & 10 deletions src/lib/badge/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import {
Inject,
Input,
NgZone,
OnChanges,
OnDestroy,
Optional,
Renderer2,
SimpleChanges,
} from '@angular/core';
import {ThemePalette, mixinDisabled, CanDisableCtor, CanDisable} from '@angular/material/core';
import {CanDisable, CanDisableCtor, mixinDisabled, ThemePalette} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';


Expand Down Expand Up @@ -53,7 +55,7 @@ export type MatBadgeSize = 'small' | 'medium' | 'large';
'[class.mat-badge-disabled]': 'disabled',
},
})
export class MatBadge extends _MatBadgeMixinBase implements OnDestroy, CanDisable {
export class MatBadge extends _MatBadgeMixinBase implements OnDestroy, OnChanges, CanDisable {
/** Whether the badge has any content. */
_hasContent = false;

Expand Down Expand Up @@ -81,14 +83,7 @@ export class MatBadge extends _MatBadgeMixinBase implements OnDestroy, CanDisabl
@Input('matBadgePosition') position: MatBadgePosition = 'above after';

/** The content for the badge */
@Input('matBadge')
get content(): string { return this._content; }
set content(value: string) {
this._content = value;
this._hasContent = value != null && `${value}`.trim().length > 0;
this._updateTextContent();
}
private _content: string;
@Input('matBadge') content: string;

/** Message used to describe the decorated element via aria-describedby */
@Input('matBadgeDescription')
Expand Down Expand Up @@ -144,6 +139,16 @@ export class MatBadge extends _MatBadgeMixinBase implements OnDestroy, CanDisabl
return this.position.indexOf('before') === -1;
}

ngOnChanges(changes: SimpleChanges) {
const contentChange = changes['content'];

if (contentChange) {
const value = contentChange.currentValue;
this._hasContent = value != null && `${value}`.trim().length > 0;
this._updateTextContent();
}
}

ngOnDestroy() {
const badgeElement = this._badgeElement;

Expand Down
3 changes: 2 additions & 1 deletion tools/public_api_guard/lib/badge.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export declare const _MatBadgeMixinBase: CanDisableCtor & typeof MatBadgeBase;

export declare class MatBadge extends _MatBadgeMixinBase implements OnDestroy, CanDisable {
export declare class MatBadge extends _MatBadgeMixinBase implements OnDestroy, OnChanges, CanDisable {
_hasContent: boolean;
_id: number;
color: ThemePalette;
Expand All @@ -14,6 +14,7 @@ export declare class MatBadge extends _MatBadgeMixinBase implements OnDestroy, C
_renderer?: Renderer2 | undefined, _animationMode?: string | undefined);
isAbove(): boolean;
isAfter(): boolean;
ngOnChanges(changes: SimpleChanges): void;
ngOnDestroy(): void;
}

Expand Down