Skip to content

Commit b949d17

Browse files
ZeeshanTamboliaarongarciahmichaldudak
authored
[material-ui][Autocomplete] Remove autocomplete warning regarding value not equal to option (#43314)
Signed-off-by: Zeeshan Tamboli <[email protected]> Co-authored-by: Aarón García Hervás <[email protected]> Co-authored-by: Michał Dudak <[email protected]>
1 parent 8451673 commit b949d17

File tree

3 files changed

+2
-47
lines changed

3 files changed

+2
-47
lines changed

docs/data/material/components/autocomplete/autocomplete.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const options = ['The Godfather', 'Pulp Fiction'];
5050

5151
However, you can use different structures by providing a `getOptionLabel` prop.
5252

53+
If your options are objects, you must provide the `isOptionEqualToValue` prop to ensure correct selection and highlighting. By default, it uses strict equality to compare options with the current value.
54+
5355
### Playground
5456

5557
Each of the following examples demonstrates one feature of the Autocomplete component.

packages/mui-material/src/Autocomplete/Autocomplete.test.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,31 +1719,6 @@ describe('<Autocomplete />', () => {
17191719
);
17201720
});
17211721

1722-
it('warn if value does not exist in options list', () => {
1723-
const value = 'not a good value';
1724-
const options = ['first option', 'second option'];
1725-
1726-
const errorMessage = 'None of the options match with `"not a good value"`';
1727-
1728-
let expectedOccurrences = 4;
1729-
1730-
if (reactMajor === 18) {
1731-
expectedOccurrences = 6;
1732-
} else if (reactMajor === 17) {
1733-
expectedOccurrences = 2;
1734-
}
1735-
1736-
expect(() => {
1737-
render(
1738-
<Autocomplete
1739-
value={value}
1740-
options={options}
1741-
renderInput={(params) => <TextField {...params} />}
1742-
/>,
1743-
);
1744-
}).toWarnDev(Array(expectedOccurrences).fill(errorMessage));
1745-
});
1746-
17471722
it('warn if groups options are not sorted', () => {
17481723
const data = [
17491724
{ group: 1, value: 'A' },

packages/mui-material/src/useAutocomplete/useAutocomplete.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -243,28 +243,6 @@ function useAutocomplete(props) {
243243

244244
const listboxAvailable = open && filteredOptions.length > 0 && !readOnly;
245245

246-
if (process.env.NODE_ENV !== 'production') {
247-
if (value !== null && !freeSolo && options.length > 0) {
248-
const missingValue = (multiple ? value : [value]).filter(
249-
(value2) => !options.some((option) => isOptionEqualToValue(option, value2)),
250-
);
251-
252-
if (missingValue.length > 0) {
253-
console.warn(
254-
[
255-
`MUI: The value provided to ${componentName} is invalid.`,
256-
`None of the options match with \`${
257-
missingValue.length > 1
258-
? JSON.stringify(missingValue)
259-
: JSON.stringify(missingValue[0])
260-
}\`.`,
261-
'You can use the `isOptionEqualToValue` prop to customize the equality test.',
262-
].join('\n'),
263-
);
264-
}
265-
}
266-
}
267-
268246
const focusTag = useEventCallback((tagToFocus) => {
269247
if (tagToFocus === -1) {
270248
inputRef.current.focus();

0 commit comments

Comments
 (0)