Merge branch 'master' into 14129-inputs-modal-new
[arvados.git] / src / components / float-input / float-input.tsx
index b032319a7e1c83c37c5890990c1192e647210b46..16e18cb1451f143f5267281266ae1d4a7278de9a 100644 (file)
@@ -15,13 +15,17 @@ export class FloatInput extends React.Component<InputProps> {
         const { onChange = () => { return; } } = this.props;
         const [, fraction] = event.target.value.split('.');
         this.setState({ endsWithDecimalSeparator: fraction === '' });
+        const parsedValue = parseFloat(event.target.value).toString();
+        event.target.value = parsedValue;
         onChange(event);
     }
 
     render() {
+        const parsedValue = parseFloat(typeof this.props.value === 'string' ? this.props.value : '');
+        const value = isNaN(parsedValue) ? '' : parsedValue.toString();
         const props = {
             ...this.props,
-            value: this.props.value + (this.state.endsWithDecimalSeparator ? '.' : ''),
+            value: value + (this.state.endsWithDecimalSeparator ? '.' : ''),
             onChange: this.handleChange,
         };
         return <Input {...props} />;