#531 - fix list items

This commit is contained in:
Elio Struyf
2023-03-13 08:56:37 +01:00
parent c159d8037c
commit b9e46d551e
2 changed files with 8 additions and 7 deletions
@@ -7,6 +7,7 @@ import ListItemField from './ListItemField';
import './ListField.css';
import { LabelField } from './LabelField';
import { AutoField } from 'uniforms-unstyled';
export type ListFieldProps = HTMLFieldProps<
unknown[],
@@ -27,14 +28,13 @@ function List({
<LabelField label={label} id={props.id} required={props.required} />
{value?.map((item, itemIndex) =>
Children.map(children as React.ReactElement[], (child: React.ReactElement, childIndex) =>
Children.map(children as React.ReactElement[], (child: React.ReactElement<any>, childIndex) =>
isValidElement(child)
? cloneElement(child, {
key: `${itemIndex}-${childIndex}`,
// name: '',
// name: (child.props.name || '').replace('$', '' + itemIndex),
...itemProps
})
? cloneElement(child as React.ReactElement<any>, {
key: `${itemIndex}-${childIndex}`,
name: ((child?.props as any)?.name || "").replace('$', '' + itemIndex),
...itemProps,
})
: child
)
)}