Skip to content

Commit 7ac83c7

Browse files
authored
fix(input-number): limiting the input of numbers exceeding the range does not trigger the blur event (#3399)
1 parent 0f53830 commit 7ac83c7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/input-number/useInputNumber.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ export default function useInputNumber(props: TdInputNumberProps, context: Setup
187187
* 2. 处理未输入完成的数字;如:2e/2+/2.等
188188
* 3. 格式化数字/数字小数点
189189
*/
190+
const emitBlur = (value: InputNumberValue, ctx: { e: FocusEvent }) => {
191+
props.onBlur?.(value, ctx);
192+
context.emit('blur', value, ctx);
193+
};
194+
190195
const handleBlur = (value: string, ctx: { e: FocusEvent }) => {
191196
const {
192197
largeNumber, max, min, decimalPlaces,
@@ -200,10 +205,12 @@ export default function useInputNumber(props: TdInputNumberProps, context: Setup
200205
});
201206
if (r === 'below-minimum') {
202207
setTValue(min, { type: 'blur', e: ctx.e });
208+
emitBlur(min, ctx);
203209
return;
204210
}
205211
if (r === 'exceed-maximum') {
206212
setTValue(max, { type: 'blur', e: ctx.e });
213+
emitBlur(max, ctx);
207214
return;
208215
}
209216
}
@@ -215,8 +222,7 @@ export default function useInputNumber(props: TdInputNumberProps, context: Setup
215222
if (newValue !== tValue.value) {
216223
setTValue(newValue, { type: 'blur', e: ctx.e });
217224
}
218-
props.onBlur?.(newValue, ctx);
219-
context.emit('blur', newValue, ctx);
225+
emitBlur(newValue, ctx);
220226
};
221227

222228
const handleFocus = (value: string, ctx: { e: FocusEvent }) => {
@@ -231,7 +237,7 @@ export default function useInputNumber(props: TdInputNumberProps, context: Setup
231237
ArrowUp: handleAdd,
232238
ArrowDown: handleReduce,
233239
};
234-
const code = e.code || e.key;
240+
const code = (e.code || e.key) as keyof typeof keyEvent;
235241
if (keyEvent[code] !== undefined) {
236242
keyEvent[code](e);
237243
}

0 commit comments

Comments
 (0)