Skip to content
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

fix(module: textarea-item): fix autoHeight error. (#501) #502

Merged
merged 4 commits into from
Jul 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
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