Skip to content

Commit

Permalink
fix(module:slider): fix keydown not trigger nzOnAfterChange (#7252)
Browse files Browse the repository at this point in the history
close #7251
* fix(module:slider): fix keydown not trigger nzOnAfterChange

* chore: clean up the code

* test(module:slider): add test case

* fix(module:slider): test case failed

* chore: remove unused code
  • Loading branch information
chenc041 authored Feb 15, 2022
1 parent a7a0b41 commit f419c07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/slider/slider.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export class NzSliderComponent implements ControlValueAccessor, OnInit, OnChange
? (this.value as number[])[this.activeValueIndex!] + step
: (this.value as number) + step;
this.setActiveValue(ensureNumberInRange(newVal, this.nzMin, this.nzMax));
this.nzOnAfterChange.emit(this.getValue(true));
}

onHandleFocusIn(index: number): void {
Expand Down
10 changes: 10 additions & 0 deletions components/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,16 @@ describe('nz-slider', () => {
expect(sliderInstance.value).toEqual([2, 99]);
});

it('should trigger nzOnAfterChange', () => {
const onChangeSpy = jasmine.createSpy('slider onChange');

sliderInstance.nzOnAfterChange.subscribe(onChangeSpy);
dispatchKeyboardEvent(sliderNativeElement, 'keydown', RIGHT_ARROW);
fixture.detectChanges();

expect(onChangeSpy).toHaveBeenCalledTimes(1);
});

it('should work for range slider when activeValueIndex is undefined', () => {
testComponent.range = true;
fixture.detectChanges();
Expand Down

0 comments on commit f419c07

Please sign in to comment.