Skip to content

Commit

Permalink
fix(module:input): fix input disabled OnPush (NG-ZORRO#3786)
Browse files Browse the repository at this point in the history
  • Loading branch information
vthinkxie authored and Ricbet committed Apr 9, 2020
1 parent db19452 commit a176975
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
21 changes: 4 additions & 17 deletions components/input/nz-input.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { Directive, ElementRef, Input, Optional, Renderer2, Self } from '@angular/core';
import { NgControl } from '@angular/forms';
import { toBoolean, NzSizeLDSType } from 'ng-zorro-antd/core';
import { Directive, ElementRef, Input, Renderer2 } from '@angular/core';
import { InputBoolean, NzSizeLDSType } from 'ng-zorro-antd/core';

@Directive({
selector: '[nz-input]',
Expand All @@ -20,22 +19,10 @@ import { toBoolean, NzSizeLDSType } from 'ng-zorro-antd/core';
}
})
export class NzInputDirective {
private _disabled = false;
@Input() nzSize: NzSizeLDSType = 'default';
@Input() @InputBoolean() disabled = false;

@Input()
set disabled(value: boolean) {
this._disabled = toBoolean(value);
}

get disabled(): boolean {
if (this.ngControl && this.ngControl.disabled !== null) {
return this.ngControl.disabled;
}
return this._disabled;
}

constructor(@Optional() @Self() public ngControl: NgControl, renderer: Renderer2, elementRef: ElementRef) {
constructor(renderer: Renderer2, elementRef: ElementRef) {
renderer.addClass(elementRef.nativeElement, 'ant-input');
}
}
3 changes: 1 addition & 2 deletions components/input/nz-input.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NzAddOnModule } from 'ng-zorro-antd/core';

import { NzIconModule } from 'ng-zorro-antd/icon';
Expand All @@ -21,6 +20,6 @@ import { NzInputDirective } from './nz-input.directive';
@NgModule({
declarations: [NzInputDirective, NzInputGroupComponent, NzAutosizeDirective],
exports: [NzInputDirective, NzInputGroupComponent, NzAutosizeDirective],
imports: [CommonModule, FormsModule, NzIconModule, PlatformModule, NzAddOnModule]
imports: [CommonModule, NzIconModule, PlatformModule, NzAddOnModule]
})
export class NzInputModule {}
4 changes: 2 additions & 2 deletions components/input/nz-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ describe('input', () => {
});
it('should set disabled work', fakeAsync(() => {
flush();
expect(inputElement.nativeElement.classList).not.toContain('ant-input-disabled');
expect(inputElement.nativeElement.attributes.getNamedItem('disabled')).toBeNull();
testComponent.disable();
flush();
fixture.detectChanges();
expect(inputElement.nativeElement.classList).toContain('ant-input-disabled');
expect(inputElement.nativeElement.attributes.getNamedItem('disabled')).toBeDefined();
}));
});
});
Expand Down

0 comments on commit a176975

Please sign in to comment.