Skip to content

Commit c629315

Browse files
committed
arrayField: move label outside field
* closes zenodo/who-rdm#89
1 parent dad0840 commit c629315

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

src/lib/forms/ArrayField.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import React, { Component } from "react";
99
import PropTypes from "prop-types";
1010
import { getIn, FieldArray } from "formik";
11-
import { Form, Icon } from "semantic-ui-react";
11+
import { Form, Icon, Button } from "semantic-ui-react";
1212
import _isEmpty from "lodash/isEmpty";
1313
import _filter from "lodash/filter";
1414
import _matches from "lodash/matches";
@@ -87,50 +87,50 @@ export class ArrayField extends Component {
8787
const { nextKey } = this.state;
8888
const valuesToDisplay = this.getValues(values, fieldPath);
8989
return (
90-
<Form.Field {...uiProps} {...hasError}>
91-
<FieldLabel htmlFor={fieldPath} icon={labelIcon} label={label} />
90+
<>
91+
<Form.Field {...uiProps} {...hasError}>
92+
<FieldLabel htmlFor={fieldPath} icon={labelIcon} label={label} />
9293

93-
{valuesToDisplay.map((value, index, array) => {
94-
const arrayPath = fieldPath;
95-
const indexPath = index;
96-
const key = value.__key || index;
94+
{valuesToDisplay.map((value, index, array) => {
95+
const arrayPath = fieldPath;
96+
const indexPath = index;
97+
const key = value.__key || index;
9798

98-
return (
99-
<div key={key}>
100-
{children({
101-
array,
102-
arrayHelpers,
103-
arrayPath,
104-
indexPath,
105-
key,
106-
value,
107-
...props,
108-
})}
109-
</div>
110-
);
111-
})}
99+
return (
100+
<div key={key}>
101+
{children({
102+
array,
103+
arrayHelpers,
104+
arrayPath,
105+
indexPath,
106+
key,
107+
value,
108+
...props,
109+
})}
110+
</div>
111+
);
112+
})}
113+
</Form.Field>
112114

113-
<label className="helptext">{helpText}</label>
115+
{helpText && <label className="helptext rel-mb-1">{helpText}</label>}
114116

115-
<Form.Group>
116-
<Form.Button
117-
type="button"
118-
icon
119-
className="align-self-end"
120-
labelPosition="left"
121-
onClick={() => {
122-
arrayHelpers.push({
123-
...defaultNewValue,
124-
__key: nextKey,
125-
});
126-
this.setState((state) => ({ nextKey: state.nextKey - 1 }));
127-
}}
128-
>
129-
<Icon name="add" />
130-
{addButtonLabel}
131-
</Form.Button>
132-
</Form.Group>
133-
</Form.Field>
117+
<Button
118+
type="button"
119+
icon
120+
className="align-self-end rel-mb-1"
121+
labelPosition="left"
122+
onClick={() => {
123+
arrayHelpers.push({
124+
...defaultNewValue,
125+
__key: nextKey,
126+
});
127+
this.setState((state) => ({ nextKey: state.nextKey - 1 }));
128+
}}
129+
>
130+
<Icon name="add" />
131+
{addButtonLabel}
132+
</Button>
133+
</>
134134
);
135135
};
136136

0 commit comments

Comments
 (0)