From 63f2dfffda8769753995fa17484b0220b4e94ee3 Mon Sep 17 00:00:00 2001 From: Yi Date: Sun, 16 Jan 2022 16:24:53 +0000 Subject: [PATCH] fix(module:input): do not set box-sizing when measuring --- components/input/autosize.spec.ts | 50 ++++++++++++------------------- components/input/style/patch.less | 1 - 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/components/input/autosize.spec.ts b/components/input/autosize.spec.ts index f7aac3d9e03..1c0a8544b1c 100644 --- a/components/input/autosize.spec.ts +++ b/components/input/autosize.spec.ts @@ -90,6 +90,20 @@ describe('autoresize', () => { expect(textarea.clientHeight).toBe(textarea.scrollHeight, 'Expected textarea height to match its scrollHeight'); })); + it('should not resize the textarea if it is hidden', fakeAsync(() => { + testComponent.hidden = true; + fixture.detectChanges(); + let previousHeight = textarea.clientHeight; + testComponent.value = '1\n'.repeat(10); + flush(); + fixture.detectChanges(); + flush(); + autosize.resizeToFitContent(); + zone.simulateZoneExit(); + fixture.detectChanges(); + expect(textarea.clientHeight).toEqual(previousHeight, 'Expected textarea is not resized.'); + })); + it('should trigger a resize when the window is resized', fakeAsync(() => { spyOn(autosize, 'resizeToFitContent'); @@ -215,36 +229,19 @@ describe('autoresize', () => { }); @Component({ - template: ` `, + template: ` `, encapsulation: ViewEncapsulation.None, - styles: [ - ` - textarea.cdk-textarea-autosize-measuring { - height: auto !important; - overflow: hidden !important; - padding: 2px 0 !important; - box-sizing: content-box !important; - } - ` - ] + styleUrls: ['../ng-zorro-antd.less'] }) export class NzTestInputWithTextAreaAutoSizeStringComponent { value = ''; + hidden = false; } @Component({ template: ` `, encapsulation: ViewEncapsulation.None, - styles: [ - ` - textarea.cdk-textarea-autosize-measuring { - height: auto !important; - overflow: hidden !important; - padding: 2px 0 !important; - box-sizing: content-box !important; - } - ` - ] + styleUrls: ['../ng-zorro-antd.less'] }) export class NzTestInputWithTextAreaAutoSizeObjectComponent { minRows = 2; @@ -254,16 +251,7 @@ export class NzTestInputWithTextAreaAutoSizeObjectComponent { @Component({ template: ` `, encapsulation: ViewEncapsulation.None, - styles: [ - ` - textarea.cdk-textarea-autosize-measuring { - height: auto !important; - overflow: hidden !important; - padding: 2px 0 !important; - box-sizing: content-box !important; - } - ` - ] + styleUrls: ['../ng-zorro-antd.less'] }) export class NzTestInputWithTextAreaAutoSizeBooleanComponent { value = ''; diff --git a/components/input/style/patch.less b/components/input/style/patch.less index 5d8fac27601..9f71d9c726f 100644 --- a/components/input/style/patch.less +++ b/components/input/style/patch.less @@ -4,7 +4,6 @@ textarea.nz-textarea-autosize-measuring { // Having 2px top and bottom padding seems to fix a bug where Chrome gets an incorrect // measurement. We just have to account for it later and subtract it off the final result. padding: 2px 0 !important; - box-sizing: content-box !important; } .@{search-prefix} {