Skip to content

Commit

Permalink
fix(module: textarea-item): fix autoHeight error(#501) (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
dodobelieve authored and fisherspy committed Jul 22, 2019
1 parent 0c9bc52 commit 50ade9b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 5 additions & 1 deletion components/textarea-item/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { Component } from '@angular/core';
<div class="am-list-body">
<TextareaItem [title]="'高度自适应'" [autoHeight]="true" [labelNumber]="5">
</TextareaItem>
<TextareaItem [editable]="false" [autoHeight]="true" [value]="readonlyValue">
</TextareaItem>
<TextareaItem [rows]="3" [placeholder]="'fixed number of lines'">
</TextareaItem>
</div>
Expand Down Expand Up @@ -120,6 +122,8 @@ import { Component } from '@angular/core';
export class DemoTextareaItemBasicComponent {
value;
error;
readonlyValue = 'This is a very very very very very very very very' +
' very very very very very very very very very very long paragraph of read-only text';
numberFocus = {
focus: false,
date: new Date()
Expand All @@ -135,7 +139,7 @@ export class DemoTextareaItemBasicComponent {
};
autoFocus = { focus: true, date: new Date() };

inputErrorClick(e) {}
inputErrorClick(e) { }

clickFocus() {
this.numberFocus = {
Expand Down
21 changes: 15 additions & 6 deletions components/textarea-item/textarea-item.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Component,
OnInit,
AfterViewInit,
Input,
Output,
EventEmitter,
Expand All @@ -25,7 +26,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
}
]
})
export class TextareaItemComponent implements OnInit, AfterContentChecked, ControlValueAccessor {
export class TextareaItemComponent implements OnInit, AfterContentChecked, ControlValueAccessor, AfterViewInit {
prefixCls: string = 'am-textarea';
wrapCls: object;
labelCls: object;
Expand Down Expand Up @@ -196,19 +197,19 @@ export class TextareaItemComponent implements OnInit, AfterContentChecked, Contr
@HostBinding('class.am-textarea-disabled')
clsDisabled: boolean;
@HostBinding('class.am-textarea-error')
clsError: boolean ;
clsError: boolean;
@HostBinding('class.am-textarea-focus')
clsFocus: boolean ;
clsFocus: boolean;
@HostBinding('class.am-textarea-item-single-line')
clsSingleLine: boolean;
@HostBinding('class.am-textarea-has-count')
clsHasCount: boolean ;
clsHasCount: boolean;

constructor(private element: ElementRef, private render: Renderer2) {
this._el = element.nativeElement;
}

_onChange = (_: any) => {};
_onChange = (_: any) => { };

setCls() {
this.hasCount = this._count > 0 && this._rows > 1;
Expand Down Expand Up @@ -303,14 +304,22 @@ export class TextareaItemComponent implements OnInit, AfterContentChecked, Contr
this._onChange = fn;
}

registerOnTouched(fn: any): void {}
registerOnTouched(fn: any): void { }

ngOnInit() {
this.setCls();
this.setCharacterLength();
this.textRef.nativeElement.value = this._value;
}

ngAfterViewInit() {
setTimeout(() => {
if (this._autoHeight) {
this.reAlignHeight();
}
}, 100);
}

ngAfterContentChecked() {
if (this._autoHeight && this._focus) {
this.reAlignHeight();
Expand Down

0 comments on commit 50ade9b

Please sign in to comment.