Skip to content

Commit

Permalink
Make getOptionLabel always return a string (#1064)
Browse files Browse the repository at this point in the history
MUI expects the label to always be a string, even if the option value is a number. Failing to provide a string gives the warning:

MUI: The `getOptionLabel` method of Autocomplete returned number(x) instead of a string for x.
  • Loading branch information
dalen authored Jun 19, 2024
1 parent 7cfcfc4 commit d4690b1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/ui/modules/hooks/useListValuesAutocomplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ const useListValuesAutocomplete = ({
}
if (!option && allowCustomValues) {
// there is just string value, it's not item from list
return valueOrOption;
return valueOrOption.toString();
}
if (!option) {
// weird
return valueOrOption;
return valueOrOption.toString();
}
return option.title || option.label || option.value; // fallback to value
return option.title || option.label || option.value.toString(); // fallback to value
};

const fixedOptions = uif === "mui" ? fixListValuesGroupOrder(options) : options;
Expand Down

0 comments on commit d4690b1

Please sign in to comment.