Skip to content

Commit

Permalink
fix(module: stepper): fix button status when the user enters (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
sWhite01111 authored and fisherspy committed Aug 23, 2019
1 parent 53cde92 commit 0739e2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/stepper/stepper.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
[max]="max"
[min]="min"
[(ngModel)]="value"
(change)="inputChange($event)"
(ngModelChange)="inputChange($event)"
/>
</div>
6 changes: 3 additions & 3 deletions components/stepper/stepper.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ describe('StepperComponent', () => {
fixture.detectChanges();

inputEle.value = 34;
inputEle.dispatchEvent(new UIEvent('change'));
inputEle.dispatchEvent(new UIEvent('input'));
expect(component.value).toBe(20, 'set input');

inputEle.value = 4;
inputEle.dispatchEvent(new UIEvent('change'));
inputEle.dispatchEvent(new UIEvent('input'));
expect(component.value).toBe(10, 'set input');

inputEle.value = 15;
inputEle.dispatchEvent(new UIEvent('change'));
inputEle.dispatchEvent(new UIEvent('input'));
expect(component.value).toBe(15, 'set input');

component.readOnly = true;
Expand Down
11 changes: 7 additions & 4 deletions components/stepper/stepper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ export class StepperComponent implements OnChanges, ControlValueAccessor {
}

inputChange(event) {
const value = event.target.value;
this._value = value ? parseInt(value, null) : 0;
if (value < this._min) {
const value = event;
this._value = value ? +value : 0;
if (this._value < this._min) {
this._value = this._min;
}
if (value > this._max) {
if (this._value > this._max) {
this._value = this._max;
}
this._upDisabled = this.plus(this._value, this._step) > this._max ? true : false;
this._downDisabled = this.minus(this._value, this._step) < this._min ? true : false;
this.setCls();
this.onChange.emit(this._value);
this.onChangeFn(this._value);
}
Expand Down

0 comments on commit 0739e2c

Please sign in to comment.