Skip to content

Commit

Permalink
refactor(cdk/text-field): switch to input transforms
Browse files Browse the repository at this point in the history
Switches inputs in cdk/text-field to use transforms instead of getters/setters.
  • Loading branch information
crisbeto committed Sep 8, 2023
1 parent fbff562 commit 36dc52c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
14 changes: 4 additions & 10 deletions src/cdk/text-field/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {
BooleanInput,
coerceBooleanProperty,
coerceNumberProperty,
NumberInput,
} from '@angular/cdk/coercion';
import {NumberInput, coerceNumberProperty} from '@angular/cdk/coercion';
import {
Directive,
ElementRef,
Expand All @@ -22,6 +17,7 @@ import {
NgZone,
Optional,
Inject,
booleanAttribute,
} from '@angular/core';
import {Platform} from '@angular/cdk/platform';
import {auditTime, takeUntil} from 'rxjs/operators';
Expand Down Expand Up @@ -80,13 +76,11 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
}

/** Whether autosizing is enabled or not */
@Input('cdkTextareaAutosize')
@Input({alias: 'cdkTextareaAutosize', transform: booleanAttribute})
get enabled(): boolean {
return this._enabled;
}
set enabled(value: BooleanInput) {
value = coerceBooleanProperty(value);

set enabled(value: boolean) {
// Only act if the actual value changed. This specifically helps to not run
// resizeToFitContent too early (i.e. before ngAfterViewInit)
if (this._enabled !== value) {
Expand Down
5 changes: 3 additions & 2 deletions tools/public_api_guard/cdk/text-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
```ts

import { AfterViewInit } from '@angular/core';
import { BooleanInput } from '@angular/cdk/coercion';
import { DoCheck } from '@angular/core';
import { ElementRef } from '@angular/core';
import { EventEmitter } from '@angular/core';
Expand Down Expand Up @@ -58,12 +57,14 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
document?: any);
protected _document?: Document;
get enabled(): boolean;
set enabled(value: BooleanInput);
set enabled(value: boolean);
get maxRows(): number;
set maxRows(value: NumberInput);
get minRows(): number;
set minRows(value: NumberInput);
// (undocumented)
static ngAcceptInputType_enabled: unknown;
// (undocumented)
ngAfterViewInit(): void;
// (undocumented)
ngDoCheck(): void;
Expand Down

0 comments on commit 36dc52c

Please sign in to comment.