Skip to content

Commit

Permalink
feat(module: textarea): modify warp style (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
sWhite01111 authored and Guoyuanqiang committed Apr 11, 2019
1 parent 0c4b966 commit bcd5d1f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
4 changes: 1 addition & 3 deletions components/textarea-item/textarea-item.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div [ngClass]="wrapCls">
<div *ngIf="title && isTitleString" [ngClass]="labelCls">{{title}}</div>
<div *ngIf="title && isTitleString" [ngClass]="labelCls">{{title}}</div>
<div *ngIf="title && !isTitleString" [ngClass]="labelCls">
<ng-template [ngTemplateOutlet]="title"></ng-template>
</div>
Expand Down Expand Up @@ -27,4 +26,3 @@
<span *ngIf="hasCount" class="{{prefixCls}}-count">
<span>{{characterLength}}</span>/{{count}}
</span>
</div>
4 changes: 2 additions & 2 deletions components/textarea-item/textarea-item.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('TextareaComponent', () => {
it('should disabled work', () => {
component.disabled = true;
fixture.detectChanges();
textareaItem = textareaEle.nativeElement.querySelector('.am-textarea-item');
textareaItem = textareaEle.nativeElement;
expect(textareaItem.classList).toContain('am-textarea-disabled');
});
it('should clear work', () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('TextareaComponent', () => {
it('should prefixListCls work', () => {
component.prefixListCls = 'am-test';
fixture.detectChanges();
const inputDivEle = textareaEle.nativeElement.querySelector('.am-textarea-item');
const inputDivEle = textareaEle.nativeElement;
expect(inputDivEle.classList).toContain('am-test-item');
});
it('should autoFocus work', () => {
Expand Down
38 changes: 27 additions & 11 deletions components/textarea-item/textarea-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
ViewChild,
TemplateRef,
AfterContentChecked,
forwardRef
forwardRef,
HostBinding,
ElementRef,
Renderer2
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

Expand All @@ -33,6 +36,7 @@ export class TextareaItem implements OnInit, AfterContentChecked, ControlValueAc
isTitleString: boolean = true;
maxLength: number = Infinity;

private _el: ElementRef;
private _prefixListCls = 'am-list';
private _value: string;
private _defaultValue: string = '';
Expand Down Expand Up @@ -187,21 +191,33 @@ export class TextareaItem implements OnInit, AfterContentChecked, ControlValueAc
@Output()
onErrorClick: EventEmitter<any> = new EventEmitter<any>();

constructor() {}
@HostBinding('class.am-textarea-item')
clsItem: boolean = true;
@HostBinding('class.am-textarea-disabled')
clsDisabled: boolean;
@HostBinding('class.am-textarea-error')
clsError: boolean ;
@HostBinding('class.am-textarea-focus')
clsFocus: boolean ;
@HostBinding('class.am-textarea-item-single-line')
clsSingleLine: boolean;
@HostBinding('class.am-textarea-has-count')
clsHasCount: boolean ;

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

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

setCls() {
this.hasCount = this._count > 0 && this._rows > 1;
this.wrapCls = {
[`${this._prefixListCls}-item`]: true,
[`${this.prefixCls}-item`]: true,
[`${this.prefixCls}-disabled`]: this._disabled,
[`${this.prefixCls}-error`]: this._error,
[`${this.prefixCls}-focus`]: this._focus,
[`${this.prefixCls}-item-single-line`]: this._rows === 1 && !this._autoHeight,
[`${this.prefixCls}-has-count`]: this.hasCount
};
this.render.addClass(this._el, this._prefixListCls + '-item');
this.clsSingleLine = this._rows === 1 && !this._autoHeight;
this.clsDisabled = this._disabled;
this.clsError = this._error;
this.clsFocus = this._focus;
this.clsHasCount = this.hasCount;
this.labelCls = {
[`${this.prefixCls}-label`]: true,
[`${this.prefixCls}-label-2`]: this._labelNumber === 2,
Expand Down

0 comments on commit bcd5d1f

Please sign in to comment.