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
29 changes: 28 additions & 1 deletion src/cdk/text-field/autosize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, ViewChild, ChangeDetectionStrategy} from '@angular/core';
import {Component, Directive, ViewChild, ChangeDetectionStrategy} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {FormsModule} from '@angular/forms';
import {By} from '@angular/platform-browser';
Expand Down Expand Up @@ -419,3 +419,30 @@ class AutosizeTextareaWithNgModel {
class AutosizeTextareaWithoutAutosize {
content: string = '';
}

@Directive({
selector: '[largeLineHeight]',
host: {'[class.large-line-height]': 'true'},
})
class LargeLineHeight {}

@Component({
template: `<textarea cdkTextareaAutosize largeLineHeight cdkAutosizeMinRows="2" cdkAutosizeMaxRows="5"></textarea>`,
styles: [`.large-line-height { font-size: 40px; line-height: 50px; padding: 0; border: 0; }`],
imports: [TextFieldModule, LargeLineHeight],
changeDetection: ChangeDetectionStrategy.Eager,
})
class AutosizeTextareaWithHostStyles {}

describe('CdkTextareaAutosize with host binding styles', () => {
it('should base row limits on the rendered line height', async () => {
const fixture = TestBed.createComponent(AutosizeTextareaWithHostStyles);
fixture.detectChanges();
await fixture.whenStable();
const textarea = fixture.nativeElement.querySelector('textarea') as HTMLTextAreaElement;
const lineHeight = parseFloat(getComputedStyle(textarea).lineHeight);
expect(lineHeight).toBe(50);
expect(parseFloat(textarea.style.minHeight)).toBe(lineHeight * 2);
expect(parseFloat(textarea.style.maxHeight)).toBe(lineHeight * 5);
});
});
2 changes: 1 addition & 1 deletion src/cdk/text-field/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
};

ngDoCheck() {
if (this._platform.isBrowser) {
if (this._platform.isBrowser && this._isViewInited) {
this.resizeToFitContent();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/material/input/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ ng_project(
"//:node_modules/@angular/platform-browser",
"//src/cdk/platform",
"//src/cdk/testing/private",
"//src/cdk/text-field",
"//src/material/core",
"//src/material/form-field",
"//src/material/icon",
Expand Down
24 changes: 24 additions & 0 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {CdkTextareaAutosize} from '@angular/cdk/text-field';
import {getSupportedInputTypes} from '@angular/cdk/platform';
import {dispatchFakeEvent, wrappedErrorMessage} from '@angular/cdk/testing/private';
import {
Expand Down Expand Up @@ -2454,3 +2455,26 @@ class MatInputWithRequiredAssignableFormControl {
this.formControl.updateValueAndValidity();
}
}

@Component({
template: `
<mat-form-field>
<textarea matInput cdkTextareaAutosize cdkAutosizeMinRows="2" cdkAutosizeMaxRows="5"></textarea>
</mat-form-field>
`,
styles: [`mat-form-field { font-size: 40px; line-height: 50px; }`],
imports: [MatFormField, MatInputModule, CdkTextareaAutosize],
changeDetection: ChangeDetectionStrategy.Eager,
})
class AutosizeMatInput {}

describe('MatInput with autosize', () => {
it('should use the inherited line height for the initial row limits', () => {
const fixture = TestBed.createComponent(AutosizeMatInput);
fixture.detectChanges();
const textarea = fixture.nativeElement.querySelector('textarea') as HTMLTextAreaElement;
expect(getComputedStyle(textarea).lineHeight).toBe('50px');
expect(textarea.style.minHeight).toBe('100px');
expect(textarea.style.maxHeight).toBe('250px');
});
});
Loading