Skip to content

Commit

Permalink
[AutoComplete]: Add verbose warning for defaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
vedadeepta committed Aug 23, 2021
1 parent 531f455 commit 9898167
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/material-ui/src/Autocomplete/Autocomplete.js
Expand Up @@ -718,7 +718,17 @@ Autocomplete.propTypes /* remove-proptypes */ = {
* The default value. Use when the component is not controlled.
* @default props.multiple ? [] : null
*/
defaultValue: PropTypes.any,
defaultValue: chainPropTypes(PropTypes.any, (props) => {
if (props.multiple && props.defaultValue !== undefined && !Array.isArray(props.defaultValue)) {
return new Error(
[
'Material-UI: The Autocomplete expects the `defaultValue` prop to be an array or undefined.',
`However, ${props.defaultValue} was provided.`,
].join('\n'),
);
}
return null;
}),
/**
* If `true`, the input can't be cleared.
* @default false
Expand Down

0 comments on commit 9898167

Please sign in to comment.