Skip to content

Commit

Permalink
Fixed #337 - InputNumber prevents min key number
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jun 17, 2020
1 parent 6b92199 commit d6d2b92
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/components/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,10 @@ export default {
this.spin(event, dir);
},
spin(event, dir) {
spin(event, dir, value) {
let step = this.step * dir;
let currentValue = this.value || 0;
let newValue = currentValue + step;
if (this.min !== null && newValue < this.min) {
newValue = this.min;
}
if (this.max !== null && newValue > this.max) {
newValue = this.max;
}
let currentValue = this.parseValue(this.$refs.input.$el.value) || 0;
let newValue = this.validateValue(currentValue + step);
this.updateInput(newValue, 'spin');
this.updateModel(event, newValue);
Expand Down Expand Up @@ -492,16 +484,19 @@ export default {
updateValue(event, valueStr, operation) {
if (valueStr != null) {
let newValue = this.parseValue(valueStr);
let valid = this.isWithinRange(newValue);
if (valid) {
this.updateInput(newValue, operation);
this.updateModel(event, newValue);
}
this.updateInput(newValue, operation);
}
},
isWithinRange(value) {
return value == null || ((this.min == null || value > this.min) && (this.max == null || value < this.max));
validateValue(value) {
if (this.min != null && value < this.min) {
return this.min;
}
if (this.max != null && value > this.max) {
return this.max;
}
return value;
},
updateInput(value, operation) {
let currentLength = this.$refs.input.$el.value.length;
Expand Down Expand Up @@ -545,6 +540,12 @@ export default {
},
onInputBlur(event) {
this.focused = false;
let newValue = this.validateValue(this.parseValue(this.$refs.input.$el.value));
this.$refs.input.$el.value = this.formatValue(newValue);
this.$refs.input.$el.setAttribute('aria-valuenow', newValue);
this.updateModel(event, newValue);
this.$emit('blur', event);
},
clearTimer() {
Expand Down Expand Up @@ -714,4 +715,4 @@ export default {
.p-fluid .p-inputnumber-buttons-vertical .p-inputnumber-input {
width: 100%;
}
</style>
</style>

0 comments on commit d6d2b92

Please sign in to comment.