1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { getInputLabel, FloatCommandInputParameter, isRequiredInput } from '~/models/workflow';
7 import { Field, WrappedFieldProps } from 'redux-form';
8 import { TextField } from '~/components/text-field/text-field';
9 import { isNumber } from '~/validators/is-number';
10 export interface FloatInputProps {
11 input: FloatCommandInputParameter;
13 export const FloatInput = ({ input }: FloatInputProps) =>
16 label={getInputLabel(input)}
17 component={DecimalInput}
19 format={value => isNaN(value) ? '' : JSON.stringify(value)}
21 isRequiredInput(input)
23 : () => undefined,]} />;
25 class DecimalInput extends React.Component<WrappedFieldProps & { label?: string }> {
27 endsWithDecimalSeparator: false,
30 handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
31 const [base, fraction] = event.target.value.split('.');
32 this.setState({ endsWithDecimalSeparator: fraction === '' });
33 this.props.input.onChange(event);
41 value: this.props.input.value + (this.state.endsWithDecimalSeparator ? '.' : ''),
42 onChange: this.handleChange,
45 return <TextField {...props} />;