Open hs-dev-web opened 1 year ago
Could you please follow the issue template and provide a reproduction sandbox?
@slax57 I've found same issue while working with React-Admin v4.
I've reproduced it both for v4 and v5.
It seems that AutocompleteInput doesn't support any other optionValue
than id
when create
or onCreate
is used. The root cause is hardcoded item data structure in useSupportCreateSuggestion
: https://github.com/marmelab/react-admin/blob/6472e3af0a8b06e3168a19f3b30115b8b4c6f7f2/packages/ra-ui-materialui/src/input/useSupportCreateSuggestion.tsx#L73
Links to sandboxes:
Steps:
Actual result: Warning: Each child in a list should have a unique "key" prop
is displayed.
Workaround: use optionValue="id"
for AutocompleteInput (and change the data structure of choices
).
Test code:
const testChoices = [
{ label: 'item 1', value: 1, id: 1 },
{ label: 'item 2', value: 2, id: 2 },
{ label: 'item 3', value: 3, id: 3 },
];
// ...
<AutocompleteInput
source="testValue"
label="Test autocomplete"
optionText="label"
optionValue="value"
// Comment the line above and uncomment the line below to fix key prop warning
// optionValue="id"
choices={testChoices}
onCreate={(filter) => {
const nextValue =
[...testChoices].sort((a, b) => b.value - a.value)[0].value + 1;
const newChoice = {
label: filter ?? '',
value: nextValue,
id: nextValue,
};
testChoices.push(newChoice);
return newChoice;
}}
/>
Hi @mikhail-fedosenko
Thanks to your detailed report I could reproduce the issue, and confirm the analysis.
I agree the bug seems to be located in useSupportCreateSuggestion
.
Would you like to open a PR to fix it?
Thanks!
This is my setting for the element:
The first time I type inside AutocompleteInput and then click anywhere outside of it (so that the component get blured) it throws an error warning like this: