diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx
index 1f672157612..47e1b85d24b 100644
--- a/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx
+++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx
@@ -1,10 +1,13 @@
import * as React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import { AutocompleteInput } from './AutocompleteInput';
import { Form } from 'react-final-form';
-import { TestTranslationProvider } from 'ra-core';
+import { FormDataConsumer, TestTranslationProvider } from 'ra-core';
import { useCreateSuggestionContext } from './useSupportCreateSuggestion';
+import { renderWithRedux } from 'ra-test';
+import { SimpleForm } from '../form';
describe('', () => {
// Fix document.createRange is not a function error on fireEvent usage (Fixed in jsdom v16.0.0)
@@ -923,4 +926,41 @@ describe('', () => {
expect(queryByText('New Kid On The Block')).not.toBeNull();
});
+
+ it("should allow to edit the input if it's inside a FormDataConsumer", () => {
+ const { getByLabelText } = renderWithRedux(
+
+
+ {({ formData, ...rest }) => {
+ return (
+
+ );
+ }}
+
+
+ );
+ const input = getByLabelText('Id', {
+ selector: 'input',
+ }) as HTMLInputElement;
+ fireEvent.focus(input);
+ userEvent.type(input, 'Hello World!');
+ expect(input.value).toEqual('Hello World!');
+ });
});
diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
index 58c598011fd..4788269da33 100644
--- a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
+++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx
@@ -323,8 +323,6 @@ export const AutocompleteInput = (props: AutocompleteInputProps) => {
? inputText(getChoiceText(selectedItem).props.record)
: getChoiceText(selectedItem)
);
-
- inputEl.current.blur();
}, [
input.value,
handleFilterChange,
@@ -333,6 +331,10 @@ export const AutocompleteInput = (props: AutocompleteInputProps) => {
inputText,
]);
+ useEffect(() => {
+ inputEl.current.blur();
+ }, [input.value]);
+
// This function ensures that the suggestion list stay aligned to the
// input element even if it moves (because user scrolled for example)
const updateAnchorEl = () => {