diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx index e153104e22d..ef01ff4dad4 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx @@ -901,10 +901,10 @@ describe('', () => { ); }); - it('should accept 0 as an input value', () => { + it('should accept 0 as an input value', async () => { render( - + ', () => { ); - expect(screen.queryByDisplayValue('foo')).not.toBeNull(); + const input = screen.getByLabelText( + 'resources.users.fields.role' + ) as HTMLInputElement; + input.focus(); + fireEvent.change(input, { target: { value: 'foo' } }); + await waitFor( + () => { + expect(screen.getByRole('listbox').children).toHaveLength(1); + }, + { timeout: 2000 } + ); + fireEvent.click(screen.getByText('foo')); + await waitFor(() => { + expect(input.value).toEqual('foo'); + }); }); it('should support creation of a new choice through the onCreate event', async () => { diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx index 5026c23a9a9..5f01ebbe1fd 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx @@ -278,7 +278,7 @@ If you provided a React element for the optionText prop, you must also provide t ]); } } else { - field.onChange(getChoiceValue(newValue) || ''); + field.onChange(getChoiceValue(newValue) ?? ''); } };