diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx index b445fde9dc3..b722ec57158 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.spec.tsx @@ -408,7 +408,7 @@ describe('', () => { it('should allow customized rendering of suggesting item', () => { const SuggestionItem = ({ record }: { record?: any }) => ( -
+
); const { getByLabelText, queryByLabelText } = render( @@ -418,8 +418,8 @@ describe('', () => { } - inputText={record => record.name} - matchSuggestion={(filter, choice) => true} + inputText={record => record && record.name} + matchSuggestion={() => true} choices={[ { id: 1, name: 'bar' }, { id: 2, name: 'foo' }, @@ -572,4 +572,22 @@ describe('', () => { expect(getByLabelText('My Sugggestions Container')).not.toBeNull(); }); + + describe('Fix issue #4660', () => { + it('should accept 0 as an input value', () => { + const { queryByDisplayValue } = render( +
( + + )} + /> + ); + expect(queryByDisplayValue('foo')).not.toBeNull(); + }); + }); }); diff --git a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx index 0819cc8fafa..c8b2a1e3502 100644 --- a/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx +++ b/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx @@ -138,6 +138,7 @@ const AutocompleteInput: FunctionComponent< variant = 'filled', ...rest } = props; + if (isValidElement(optionText) && !inputText) { throw new Error(`If the optionText prop is a React element, you must also specify the inputText prop: { handleFilterChange(''); + // If we had a value before, set the filter back to its text so that // Downshift displays it correctly setFilterValue(