Optimize decimal point number input
This commit is contained in:
parent
0e1aa51d4b
commit
8f5fff920f
@ -3,8 +3,10 @@ import { FontLevel, Theme } from "@Component/Theme/Theme";
|
||||
import "./AttrInput.scss";
|
||||
import { Icon } from "@fluentui/react";
|
||||
import { Localization, AllI18nKeys } from "@Component/Localization/Localization";
|
||||
import { ObjectID } from "@Model/Renderer";
|
||||
|
||||
interface IAttrInputProps {
|
||||
id?: ObjectID;
|
||||
keyI18n: AllI18nKeys;
|
||||
infoI18n?: AllI18nKeys;
|
||||
value?: number | string;
|
||||
@ -35,7 +37,7 @@ class AttrInput extends Component<IAttrInputProps> {
|
||||
const praseNumber = (value as any) / 1;
|
||||
|
||||
// 数字校验
|
||||
if (isNaN(praseNumber)) {
|
||||
if (isNaN(praseNumber) || /\.0*$/.test(value)) {
|
||||
return <Localization i18nKey="Input.Error.Not.Number" />
|
||||
}
|
||||
|
||||
@ -127,7 +129,16 @@ class AttrInput extends Component<IAttrInputProps> {
|
||||
}
|
||||
|
||||
public shouldComponentUpdate(nextProps: IAttrInputProps) {
|
||||
this.updateValueFromProps(nextProps.value);
|
||||
|
||||
// ID 都为空时更新
|
||||
if (!nextProps.id && !this.props.id) {
|
||||
this.updateValueFromProps(nextProps.value);
|
||||
}
|
||||
|
||||
// ID 变换时更新 State 到最新的 Props
|
||||
if (nextProps.id !== this.props.id) {
|
||||
this.updateValueFromProps(nextProps.value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ class RangeDetails extends Component<IMixinStatusProps> {
|
||||
private renderFrom(range: Range) {
|
||||
return <>
|
||||
<AttrInput
|
||||
id={range.id}
|
||||
keyI18n="Common.Attr.Key.Display.Name"
|
||||
value={range.displayName}
|
||||
valueChange={(e) => {
|
||||
@ -28,6 +29,7 @@ class RangeDetails extends Component<IMixinStatusProps> {
|
||||
}}
|
||||
/>
|
||||
<AttrInput
|
||||
id={range.id}
|
||||
isNumber={true}
|
||||
step={.1}
|
||||
keyI18n="Common.Attr.Key.Position.X"
|
||||
@ -40,6 +42,7 @@ class RangeDetails extends Component<IMixinStatusProps> {
|
||||
}}
|
||||
/>
|
||||
<AttrInput
|
||||
id={range.id}
|
||||
isNumber={true}
|
||||
step={.1}
|
||||
keyI18n="Common.Attr.Key.Position.Y"
|
||||
@ -52,6 +55,7 @@ class RangeDetails extends Component<IMixinStatusProps> {
|
||||
}}
|
||||
/>
|
||||
<AttrInput
|
||||
id={range.id}
|
||||
isNumber={true}
|
||||
step={.1}
|
||||
keyI18n="Common.Attr.Key.Position.Z"
|
||||
|
Loading…
Reference in New Issue
Block a user