Skip to content

Commit

Permalink
fix(input-number): NzAutoFocus doesn't work or work as expected (#1833)
Browse files Browse the repository at this point in the history
close #1706
  • Loading branch information
Wendell authored and 执衡 committed Jul 22, 2018
1 parent 5305723 commit 739b353
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 7 additions & 6 deletions components/input-number/nz-input-number.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,10 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn
}

updateAutoFocus(): void {
if (this.isInit) {
if (this.nzAutoFocus) {
this.renderer.setAttribute(this.inputElement.nativeElement, 'autofocus', 'autofocus');
} else {
this.renderer.removeAttribute(this.inputElement.nativeElement, 'autofocus');
}
if (this.nzAutoFocus) {
this.renderer.setAttribute(this.inputElement.nativeElement, 'autofocus', 'autofocus');
} else {
this.renderer.removeAttribute(this.inputElement.nativeElement, 'autofocus');
}
}

Expand Down Expand Up @@ -365,5 +363,8 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn

ngAfterViewInit(): void {
this.isInit = true;
if (this._autoFocus) {
this.focus();
}
}
}
3 changes: 3 additions & 0 deletions components/input-number/nz-input-number.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ describe('input number', () => {
it('should autofocus work', () => {
fixture.detectChanges();
testComponent.autofocus = true;
testComponent.nzInputNumberComponent._autoFocus = true;
testComponent.nzInputNumberComponent.ngAfterViewInit();
fixture.detectChanges();
expect(inputElement === document.activeElement).toBe(true);
expect(inputElement.attributes.getNamedItem('autofocus').name).toBe('autofocus');
testComponent.autofocus = false;
fixture.detectChanges();
Expand Down

0 comments on commit 739b353

Please sign in to comment.