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:input): fix input disabled style bug #108

Merged
merged 1 commit into from
Aug 26, 2017
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
35 changes: 27 additions & 8 deletions src/components/input/nz-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

@Component({
selector : 'nz-input',
selector: 'nz-input',
encapsulation: ViewEncapsulation.None,
template : `
template: `
<span class="ant-input-group-addon" *ngIf="_addOnContentBefore">
<ng-template [ngTemplateOutlet]="_addOnContentBefore">
</ng-template>
Expand All @@ -34,7 +34,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
[attr.type]="nzType"
class="ant-input"
[class.ant-input-search]="nzType==='search'"
[ngClass]="_prefixCls+'-'+_size"
[ngClass]="_classMap"
[attr.placeholder]="nzPlaceHolder"
[(ngModel)]="nzValue">
</ng-template>
Expand All @@ -49,6 +49,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
[attr.rows]="nzRows"
[attr.cols]="nzCols"
class="ant-input"
[ngClass]="_classMap"
[attr.placeholder]="nzPlaceHolder"
[(ngModel)]="nzValue"></textarea>
</ng-template>
Expand All @@ -61,14 +62,14 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
<ng-template [ngTemplateOutlet]="_addOnContentAfter">
</ng-template>
</span>`,
providers : [
providers: [
{
provide : NG_VALUE_ACCESSOR,
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => NzInputComponent),
multi : true
multi: true
}
],
styleUrls : [
styleUrls: [
'./style/index.less',
'./style/patch.less'
]
Expand All @@ -80,6 +81,8 @@ export class NzInputComponent implements AfterContentInit, ControlValueAccessor
_size = 'default';
_prefixCls = 'ant-input';
_composing = false;
_classMap;
_disabled = false;

// ngModel Access
onChange: any = Function.prototype;
Expand All @@ -90,7 +93,6 @@ export class NzInputComponent implements AfterContentInit, ControlValueAccessor
@Input() nzId: string;
@Input() nzRows: number;
@Input() nzCols: number;
@Input() nzDisabled: boolean;

@Input()
get nzSize(): string {
Expand All @@ -101,6 +103,16 @@ export class NzInputComponent implements AfterContentInit, ControlValueAccessor
this._size = { large: 'lg', small: 'sm' }[ value ];
}

@Input()
get nzDisabled(): boolean {
return this._disabled;
};

set nzDisabled(value: boolean) {
this._disabled = value;
this.setClassMap();
}

@Output() nzBlur: EventEmitter<MouseEvent> = new EventEmitter();
@Output() nzFocus: EventEmitter<MouseEvent> = new EventEmitter();
@ContentChild('addOnBefore') _addOnContentBefore: TemplateRef<any>;
Expand Down Expand Up @@ -144,6 +156,13 @@ export class NzInputComponent implements AfterContentInit, ControlValueAccessor
this.nzFocus.emit($event);
}

setClassMap(): void {
this._classMap = {
[this._prefixCls+'-'+this._size]: true,
[`${this._prefixCls}-disabled`]: this._disabled
};
}

constructor(private _elementRef: ElementRef, private _renderer: Renderer2) {
this._el = this._elementRef.nativeElement;
}
Expand Down
18 changes: 18 additions & 0 deletions src/components/input/nz-input.directive.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
})
export class NzInputDirectiveComponent {
size = 'default';
_disabled = false;
nativeElement: HTMLElement;

@Input()
Expand All @@ -28,6 +29,23 @@ export class NzInputDirectiveComponent {
this.size = { large: 'lg', small: 'sm' }[ value ];
}

@Input()
get nzDisabled(): boolean {
return this._disabled;
};

set nzDisabled(value: boolean) {
if(value){
this.nativeElement.setAttribute('disabled','');
}
this._disabled = value;
}

@HostBinding(`class.ant-input-disabled`)
get setDisabledClass(): boolean {
return this._disabled === true;
};

@HostBinding(`class.ant-input`) _nzInput = true;


Expand Down