diff --git a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx index 38f0796f355..30643aa7ef5 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteArrayInput.spec.tsx @@ -988,4 +988,43 @@ describe('', () => { expect(noOptionsAppeared).toBe(false); }); + + it('should not crash if its value is not an array', () => { + render( + + + + + + ); + expect(screen.queryByRole('textbox')).not.toBeNull(); + }); + + it('should not crash if its value is not an array and is empty', () => { + render( + + + + + + ); + expect(screen.queryByRole('textbox')).not.toBeNull(); + }); }); diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx index da1ae1c68c9..b7b8c7c09a6 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx @@ -742,7 +742,7 @@ const getSelectedItems = ( multiple ) => { if (multiple) { - return (Array.isArray(value || []) ? value : [value]) + return (Array.isArray(value ?? []) ? value : [value]) .map(item => choices.find( choice => String(item) === String(get(choice, optionValue))