Skip to content

Commit

Permalink
[Autocomplete] Simplify error for wrong getOptionLabel (mui#20103)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored and EsoterikStare committed Mar 30, 2020
1 parent 238058a commit 6b3cc7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ describe('<Autocomplete />', () => {
expect(handleChange.args[0][1]).to.equal('a');
expect(consoleErrorMock.callCount()).to.equal(2); // strict mode renders twice
expect(consoleErrorMock.messages()[0]).to.include(
'For the input option: "a", `getOptionLabel` returns: undefined',
'the `getOptionLabel` method of Autocomplete returned undefined instead of a string',
);
});

Expand Down
11 changes: 5 additions & 6 deletions packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,12 @@ export default function useAutocomplete(props) {

if (process.env.NODE_ENV !== 'production') {
if (typeof optionLabel !== 'string') {
const erroneousReturn =
optionLabel === undefined ? 'undefined' : `${typeof optionLabel} (${optionLabel})`;
console.error(
[
'Material-UI: the `getOptionLabel` method of useAutocomplete do not handle the options correctly.',
`The component expect a string but received ${typeof optionLabel}.`,
`For the input option: ${JSON.stringify(
newValue,
)}, \`getOptionLabel\` returns: ${optionLabel}.`,
`Material-UI: the \`getOptionLabel\` method of ${componentName} returned ${erroneousReturn} instead of a string for`,
JSON.stringify(newValue),
].join('\n'),
);
}
Expand Down Expand Up @@ -465,7 +464,7 @@ export default function useAutocomplete(props) {
if (matches.length > 1) {
console.error(
[
'Material-UI: the `getOptionSelected` method of useAutocomplete do not handle the arguments correctly.',
`Material-UI: the \`getOptionSelected\` method of ${componentName} do not handle the arguments correctly.`,
`The component expects a single value to match a given option but found ${
matches.length
} matches.`,
Expand Down

0 comments on commit 6b3cc7d

Please sign in to comment.