Skip to content

Commit

Permalink
fix(module:input-number): fix focused style could not be removed afte…
Browse files Browse the repository at this point in the history
…r blur (#1453)

close #1449
  • Loading branch information
Wendell authored and vthinkxie committed May 22, 2018
1 parent cbc508b commit 80a559f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions components/input-number/nz-input-number.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,16 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn
}

down(e: MouseEvent | KeyboardEvent, ratio?: number): void {
if (!this.isFocused) {
this.focus();
}
this.step('down', e, ratio);
}

up(e: MouseEvent | KeyboardEvent, ratio?: number): void {
if (!this.isFocused) {
this.focus();
}
this.step('up', e, ratio);
}

Expand Down
21 changes: 18 additions & 3 deletions components/input-number/nz-input-number.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { NzInputNumberModule } from './nz-input-number.module';
describe('input number', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports : [ NzInputNumberModule, FormsModule, ReactiveFormsModule ],
declarations: [ NzTestInputNumberBasicComponent, NzTestInputNumberFormComponent ]
imports : [NzInputNumberModule, FormsModule, ReactiveFormsModule],
declarations: [NzTestInputNumberBasicComponent, NzTestInputNumberFormComponent]
});
TestBed.compileComponents();
}));
Expand Down Expand Up @@ -375,6 +375,21 @@ describe('input number', () => {
fixture.detectChanges();
expect(inputElement.value).toBe(newFormatter(initValue));
}));
// #1449
it('should up and down focus input', (() => {
dispatchFakeEvent(upHandler, 'mousedown');
fixture.detectChanges();
expect(inputNumber.nativeElement.classList).toContain('ant-input-number-focused');
dispatchFakeEvent(inputElement, 'blur');
fixture.detectChanges();
expect(inputNumber.nativeElement.classList).not.toContain('ant-input-number-focused');
dispatchFakeEvent(downHandler, 'mousedown');
fixture.detectChanges();
expect(inputNumber.nativeElement.classList).toContain('ant-input-number-focused');
dispatchFakeEvent(inputElement, 'blur');
fixture.detectChanges();
expect(inputNumber.nativeElement.classList).not.toContain('ant-input-number-focused');
}));
});
describe('input number form', () => {
let fixture;
Expand Down Expand Up @@ -466,7 +481,7 @@ export class NzTestInputNumberFormComponent {

constructor(private formBuilder: FormBuilder) {
this.formGroup = this.formBuilder.group({
inputNumber: [ 1 ]
inputNumber: [1]
});
}

Expand Down

0 comments on commit 80a559f

Please sign in to comment.