Skip to content

Commit 1bab466

Browse files
Copilotfzaninotto
andauthored
fix: Restore ArrayField TypeScript type to accept FieldProps (including label prop)
Agent-Logs-Url: https://github.com/marmelab/react-admin/sessions/09a2d7a3-86fe-49c6-addb-bdcb7bad1a27 Co-authored-by: fzaninotto <99944+fzaninotto@users.noreply.github.com>
1 parent 11ac0cd commit 1bab466

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/ra-ui-materialui/src/field/ArrayField.spec.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ describe('<ArrayField />', () => {
4848
);
4949
});
5050

51+
it('should accept label prop (FieldProps)', () => {
52+
// This test ensures that ArrayField accepts the label prop from FieldProps
53+
// Regression test for https://github.com/marmelab/react-admin/issues/11197
54+
render(
55+
<Wrapper>
56+
<ArrayField
57+
source="arr"
58+
label="My Array"
59+
record={{ id: 123, arr: [{ id: 1, foo: 'bar' }] }}
60+
>
61+
<DummyIterator />
62+
</ArrayField>
63+
</Wrapper>
64+
);
65+
});
66+
5167
it('should not fail when value is null', () => {
5268
render(
5369
<Wrapper>

packages/ra-ui-materialui/src/field/ArrayField.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as React from 'react';
12
import { ArrayFieldBase, type ArrayFieldBaseProps } from 'ra-core';
23

34
import type { FieldProps } from './types';
@@ -23,7 +24,9 @@ import type { FieldProps } from './types';
2324
*
2425
* @see useListContext
2526
*/
26-
export const ArrayField = ArrayFieldBase;
27+
export const ArrayField = ArrayFieldBase as unknown as <
28+
RecordType extends Record<string, any> = Record<string, any>,
29+
>(props: ArrayFieldProps<RecordType>) => React.ReactElement;
2730

2831
export interface ArrayFieldProps<
2932
RecordType extends Record<string, any> = Record<string, any>,

0 commit comments

Comments
 (0)