Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helperText prop to ArrayInput #4262

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/ra-ui-materialui/src/input/ArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { cloneElement, Children } from 'react';
import PropTypes from 'prop-types';
import { isRequired, FieldTitle, composeValidators } from 'ra-core';
import { useFieldArray } from 'react-final-form-arrays';
import { InputLabel, FormControl } from '@material-ui/core';
import { InputLabel, FormControl, FormHelperText } from '@material-ui/core';
import InputHelperText from './InputHelperText';

import sanitizeRestProps from './sanitizeRestProps';

Expand Down Expand Up @@ -51,6 +52,7 @@ export const ArrayInput = ({
className,
defaultValue,
label,
helperText,
children,
record,
resource,
Expand All @@ -70,21 +72,37 @@ export const ArrayInput = ({
...rest,
});

const { touched, error } = fieldProps.meta;

return (
<FormControl
fullWidth
margin="normal"
className={className}
{...sanitizeRestProps(rest)}
>
<InputLabel htmlFor={source} shrink>
<InputLabel
htmlFor={source}
shrink
variant={variant}
error={touched && !!error}
>
<FieldTitle
label={label}
source={source}
resource={resource}
isRequired={isRequired(validate)}
/>
</InputLabel>
{(touched && error) || helperText ? (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency shouldn't this be under the items? For other inputs we don't put the helper text between the label and the form control. @fzaninotto what do you think ?

<FormHelperText error={touched && !!error}>
<InputHelperText
touched={touched}
error={error}
helperText={helperText}
/>
</FormHelperText>
) : null}
{cloneElement(Children.only(children), {
...fieldProps,
record,
Expand All @@ -103,6 +121,7 @@ ArrayInput.propTypes = {
defaultValue: PropTypes.any,
isRequired: PropTypes.bool,
label: PropTypes.string,
helperText: PropTypes.string,
resource: PropTypes.string,
source: PropTypes.string,
record: PropTypes.object,
Expand Down