Skip to content

Commit

Permalink
out of range value corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
shachiniM committed Aug 25, 2023
1 parent 347136c commit 8d5a776
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions components/src/core/components/Input/Number/Number.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineComponent({
},
modelValue: {
type: String,
default: ''
default: '',
},
disabled: {
type: Boolean,
Expand Down Expand Up @@ -62,6 +62,16 @@ export default defineComponent({
let matchingNumber = value.match(/^[0-9]*(?:\.[0-9]+)?/);
return matchingNumber ? matchingNumber[0] : '';
};
const getCorrectedValue = (value: number) => {
if (value > props.max) {
value = props.max;
}
if (value < props.min) {
value = props.min;
}
return value;
};
watch(
() => props.modelValue,
value => {
Expand Down Expand Up @@ -91,11 +101,11 @@ export default defineComponent({
) {
number.value = Number(number.value);
if (!Number.isNaN(number.value)) {
if (number.value <= props.min) return;
number.value--;
if (number.value > props.min) number.value--;
number.value = getCorrectedValue(number.value);
}
} else {
number.value = props.max;
number.value = props.min;
}
emit('update:modelValue', number.value);
},
Expand Down Expand Up @@ -138,8 +148,8 @@ export default defineComponent({
) {
number.value = Number(number.value);
if (!Number.isNaN(number.value)) {
if (number.value >= props.max) return;
number.value++;
if (props.max > number.value) number.value++;
number.value = getCorrectedValue(number.value);
}
} else {
number.value = props.min;
Expand Down

0 comments on commit 8d5a776

Please sign in to comment.