Skip to content

Commit

Permalink
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -988,4 +988,43 @@ describe('<AutocompleteArrayInput />', () => {

expect(noOptionsAppeared).toBe(false);
});

it('should not crash if its value is not an array', () => {
render(
<AdminContext dataProvider={testDataProvider()}>
<SimpleForm
onSubmit={jest.fn()}
defaultValues={{ tags: 'programming' }}
>
<AutocompleteArrayInput
choices={[
{ id: 'programming', name: 'Programming' },
{ id: 'lifestyle', name: 'Lifestyle' },
{ id: 'photography', name: 'Photography' },
]}
{...defaultProps}
/>
</SimpleForm>
</AdminContext>
);
expect(screen.queryByRole('textbox')).not.toBeNull();
});

it('should not crash if its value is not an array and is empty', () => {
render(
<AdminContext dataProvider={testDataProvider()}>
<SimpleForm onSubmit={jest.fn()} defaultValues={{ tags: '' }}>
<AutocompleteArrayInput
choices={[
{ id: 'programming', name: 'Programming' },
{ id: 'lifestyle', name: 'Lifestyle' },
{ id: 'photography', name: 'Photography' },
]}
{...defaultProps}
/>
</SimpleForm>
</AdminContext>
);
expect(screen.queryByRole('textbox')).not.toBeNull();
});
});
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit 8a0c81c

Please sign in to comment.