refs #14161 Merge branch 'origin/14161-inputs-focus-enter-action'
[arvados-workbench2.git] / src / views / collection-panel / collection-tag-form.tsx
index 8f2540412edbbd6318c9716d400e921e6086b9b8..83ad0ca42860a1e70c8e85900411af15eea3baf0 100644 (file)
@@ -6,20 +6,15 @@ import * as React from 'react';
 import { reduxForm, Field, reset } from 'redux-form';
 import { compose, Dispatch } from 'redux';
 import { ArvadosTheme } from '~/common/custom-theme';
-import { StyleRulesCallback, withStyles, WithStyles, TextField, Button, CircularProgress } from '@material-ui/core';
+import { StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress, Grid } from '@material-ui/core';
 import { TagProperty } from '~/models/tag';
+import { TextField } from '~/components/text-field/text-field';
 import { createCollectionTag, COLLECTION_TAG_FORM_NAME } from '~/store/collection-panel/collection-panel-action';
 import { TAG_VALUE_VALIDATION, TAG_KEY_VALIDATION } from '~/validators/validators';
 
-type CssRules = 'form' | 'textField' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
+type CssRules = 'buttonWrapper' | 'saveButton' | 'circularProgress';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    form: {
-        marginBottom: theme.spacing.unit * 4
-    },
-    textField: {
-        marginRight: theme.spacing.unit
-    },
     buttonWrapper: {
         position: 'relative',
         display: 'inline-block'
@@ -47,14 +42,6 @@ interface CollectionTagFormActionProps {
     handleSubmit: any;
 }
 
-interface TextFieldProps {
-    label: string;
-    floatinglabeltext: string;
-    className?: string;
-    input?: string;
-    meta?: any;
-}
-
 type CollectionTagFormProps = CollectionTagFormDataProps & CollectionTagFormActionProps & WithStyles<CssRules>;
 
 export const CollectionTagForm = compose(
@@ -67,52 +54,41 @@ export const CollectionTagForm = compose(
     }),
     withStyles(styles))(
 
-    class CollectionTagForm extends React.Component<CollectionTagFormProps> {
+        class CollectionTagForm extends React.Component<CollectionTagFormProps> {
 
             render() {
                 const { classes, submitting, pristine, invalid, handleSubmit } = this.props;
                 return (
-                    <form className={classes.form} onSubmit={handleSubmit}>
-                        <Field name="key"
-                            disabled={submitting}
-                            component={this.renderTextField}
-                            floatinglabeltext="Key"
-                            validate={TAG_KEY_VALIDATION}
-                            className={classes.textField}
-                            label="Key" />
-                        <Field name="value"
-                            disabled={submitting}
-                            component={this.renderTextField}
-                            floatinglabeltext="Value"
-                            validate={TAG_VALUE_VALIDATION}
-                            className={classes.textField}
-                            label="Value" />
-                        <div className={classes.buttonWrapper}>
-                            <Button type="submit" className={classes.saveButton}
-                                color="primary"
-                                size='small'
-                                disabled={invalid || submitting || pristine}
-                                variant="contained">
-                                ADD
-                            </Button>
-                            {submitting && <CircularProgress size={20} className={classes.circularProgress} />}
-                        </div>
+                    <form onSubmit={handleSubmit}>
+                        <Grid container justify="flex-start" alignItems="baseline" spacing={24}>
+                            <Grid item xs={3} component={"span"}>
+                                <Field name="key"
+                                    disabled={submitting}
+                                    component={TextField}
+                                    validate={TAG_KEY_VALIDATION}
+                                    label="Key" />
+                            </Grid>
+                            <Grid item xs={5} component={"span"}>
+                                <Field name="value"
+                                    disabled={submitting}
+                                    component={TextField}
+                                    validate={TAG_VALUE_VALIDATION}
+                                    label="Value" />
+                            </Grid>
+                            <Grid item component={"span"} className={classes.buttonWrapper}>
+                                <Button type="submit" className={classes.saveButton}
+                                    color="primary"
+                                    size='small'
+                                    disabled={invalid || submitting || pristine}
+                                    variant="contained">
+                                    ADD
+                                </Button>
+                                {submitting && <CircularProgress size={20} className={classes.circularProgress} />}
+                            </Grid>
+                        </Grid>
                     </form>
                 );
             }
-
-            renderTextField = ({ input, label, meta: { touched, error }, ...custom }: TextFieldProps) => (
-                <TextField
-                    helperText={touched && error}
-                    label={label}
-                    className={this.props.classes.textField}
-                    error={touched && !!error}
-                    autoComplete='off'
-                    {...input}
-                    {...custom}
-                />
-            )
-
         }
 
     );