mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:48:55 +08:00
fix: input-number 光标漂移问题
This commit is contained in:
parent
aabc616051
commit
9f1941f433
@ -317,8 +317,37 @@ export default class NumberControl extends React.Component<
|
||||
}
|
||||
|
||||
onChange(resultValue);
|
||||
|
||||
setTimeout(() => {
|
||||
this.changeCursorPos(+resultValue);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// 取真实用户输入的值去改变光标的位置
|
||||
@autobind
|
||||
changeCursorPos(value: number) {
|
||||
if (isNaN(value)) {
|
||||
return;
|
||||
}
|
||||
const {kilobitSeparator, prefix} = this.props;
|
||||
let pos = `${value}`.length;
|
||||
|
||||
if (prefix) {
|
||||
pos += prefix.length;
|
||||
}
|
||||
|
||||
if (kilobitSeparator) {
|
||||
// 处理有千分符的情况 123,456,789
|
||||
const ksLen = Math.floor((`${Math.abs(value)}`.length - 1) / 3);
|
||||
if (ksLen > 0) {
|
||||
pos += ksLen;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.input) {
|
||||
this.input.setSelectionRange?.(pos, pos);
|
||||
}
|
||||
}
|
||||
filterNum(value: number | string | undefined): number | undefined;
|
||||
filterNum(
|
||||
value: number | string | undefined,
|
||||
|
Loading…
Reference in New Issue
Block a user