1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { Input } from '@material-ui/core';
7 import { InputProps } from '@material-ui/core/Input';
9 export class FloatInput extends React.Component<InputProps> {
11 endsWithDecimalSeparator: false,
14 handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
15 const { onChange = () => { return; } } = this.props;
16 const [, fraction] = event.target.value.split('.');
17 this.setState({ endsWithDecimalSeparator: fraction === '' });
24 value: this.props.value + (this.state.endsWithDecimalSeparator ? '.' : ''),
25 onChange: this.handleChange,
27 return <Input {...props} />;