Skip to content

Commit

Permalink
fix(inputnumber): 修复超过 min, max 范围问题(#2606) (#2607)
Browse files Browse the repository at this point in the history
  • Loading branch information
Formulaaa authored Oct 24, 2023
1 parent ecc0288 commit 3f3821e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/packages/__VUE/inputnumber/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default create({
const emitChange = (value: string | number, event: Event) => {
let output_value: number | string = fixedDecimalPlaces(value);
emit('update:modelValue', output_value, event);
emit('change', output_value, event);
if (Number(props.modelValue) !== Number(output_value)) emit('change', output_value, event);
};
const addAllow = (value = Number(props.modelValue)): boolean => {
return value < Number(props.max) && !props.disabled;
Expand All @@ -112,19 +112,21 @@ export default create({
};
const reduce = (event: Event) => {
emit('reduce', event);
if (reduceAllow()) {
let output_value = Number(props.modelValue) - Number(props.step);
let output_value = Number(props.modelValue) - Number(props.step);
if (reduceAllow() && output_value >= Number(props.min)) {
emitChange(output_value, event);
} else {
emitChange(Number(props.min), event);
emit('overlimit', event, 'reduce');
}
};
const add = (event: Event) => {
emit('add', event);
if (addAllow()) {
let output_value = Number(props.modelValue) + Number(props.step);
let output_value = Number(props.modelValue) + Number(props.step);
if (addAllow() && output_value <= Number(props.max)) {
emitChange(output_value, event);
} else {
emitChange(Number(props.max), event);
emit('overlimit', event, 'add');
}
};
Expand Down
12 changes: 7 additions & 5 deletions src/packages/__VUE/inputnumber/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default create({
const emitChange = (value: string | number, event: Event) => {
let output_value: number | string = fixedDecimalPlaces(value);
emit('update:modelValue', output_value, event);
emit('change', output_value, event);
if (Number(props.modelValue) !== Number(output_value)) emit('change', output_value, event);
};
const addAllow = (value = Number(props.modelValue)): boolean => {
return value < Number(props.max) && !props.disabled;
Expand All @@ -107,19 +107,21 @@ export default create({
};
const reduce = (event: Event) => {
emit('reduce', event);
if (reduceAllow()) {
let output_value = Number(props.modelValue) - Number(props.step);
let output_value = Number(props.modelValue) - Number(props.step);
if (reduceAllow() && output_value >= Number(props.min)) {
emitChange(output_value, event);
} else {
emitChange(Number(props.min), event);
emit('overlimit', event, 'reduce');
}
};
const add = (event: Event) => {
emit('add', event);
if (addAllow()) {
let output_value = Number(props.modelValue) + Number(props.step);
let output_value = Number(props.modelValue) + Number(props.step);
if (addAllow() && output_value <= Number(props.max)) {
emitChange(output_value, event);
} else {
emitChange(Number(props.max), event);
emit('overlimit', event, 'add');
}
};
Expand Down

0 comments on commit 3f3821e

Please sign in to comment.