Skip to content

Commit

Permalink
value modification logic optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
shachiniM committed Aug 25, 2023
1 parent 8d5a776 commit e9b0ece
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions components/src/core/components/Input/Number/Number.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ export default defineComponent({
return matchingNumber ? matchingNumber[0] : '';
};
const getCorrectedValue = (value: number) => {
if (value > props.max) {
value = props.max;
const getModifiedValue = (value: number) => {
var modifiedValue = value;
if (props.min > value) {
modifiedValue = props.min;
}
if (value < props.min) {
value = props.min;
if (props.max < value) {
modifiedValue = props.max;
}
return value;
return modifiedValue;
};
watch(
() => props.modelValue,
Expand Down Expand Up @@ -101,8 +102,7 @@ export default defineComponent({
) {
number.value = Number(number.value);
if (!Number.isNaN(number.value)) {
if (number.value > props.min) number.value--;
number.value = getCorrectedValue(number.value);
number.value = getModifiedValue(number.value + 1);
}
} else {
number.value = props.min;
Expand Down Expand Up @@ -148,8 +148,7 @@ export default defineComponent({
) {
number.value = Number(number.value);
if (!Number.isNaN(number.value)) {
if (props.max > number.value) number.value++;
number.value = getCorrectedValue(number.value);
number.value = getModifiedValue(number.value + 1);
}
} else {
number.value = props.min;
Expand Down

0 comments on commit e9b0ece

Please sign in to comment.