Skip to content

Commit f50fca1

Browse files
authored
Merge pull request #8276 from marmelab/arrayinput-helpertext
Fix `ArrayInput` throws an error when providing a `helperText`
2 parents 6a8e64f + 315f1d2 commit f50fca1

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/ra-ui-materialui/src/input/ArrayInput/ArrayInput.spec.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ describe('<ArrayInput />', () => {
251251
});
252252
});
253253

254+
it('should allow to have a helperText', () => {
255+
render(
256+
<AdminContext dataProvider={testDataProvider()}>
257+
<SimpleForm onSubmit={jest.fn}>
258+
<ArrayInput source="foo" helperText="test helper text">
259+
<SimpleFormIterator />
260+
</ArrayInput>
261+
</SimpleForm>
262+
</AdminContext>
263+
);
264+
expect(screen.queryByText('test helper text')).not.toBeNull();
265+
});
266+
254267
describe('used within a form with global validation', () => {
255268
it('should display an error if the array is required and empty', async () => {
256269
render(<GlobalValidation />);

packages/ra-ui-materialui/src/input/ArrayInput/ArrayInput.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ export const ArrayInput = (props: ArrayInputProps) => {
189189
// root property is applicable to built-in validation only,
190190
// Resolvers are yet to support useFieldArray root level validation.
191191
// Reference: https://react-hook-form.com/api/usefieldarray
192-
error={
193-
error.root ? error.root?.message : error?.message
194-
}
192+
error={error?.root?.message ?? error?.message}
195193
helperText={helperText}
196194
/>
197195
</FormHelperText>

0 commit comments

Comments
 (0)