Skip to content

Commit

Permalink
[useAutocomplete] pass only valid values for the getOptionLabel prop
Browse files Browse the repository at this point in the history
Fixes #36045
  • Loading branch information
rangoo94 committed Feb 7, 2023
1 parent d4d8512 commit d78cb1a
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,20 @@ export default function useAutocomplete(props) {
},
);

const isSameValue = (value1, value2) => {
const label1 = value1 === null ? '' : getOptionLabel(value1);
const label2 = value2 === null ? '' : getOptionLabel(value2);
return label1 === label2;
};

const checkHighlightedOptionExists = () => {
if (
highlightedIndexRef.current !== -1 &&
previousProps.filteredOptions &&
previousProps.filteredOptions.length !== filteredOptions.length &&
(multiple
? previousProps.value.every((val, i) => getOptionLabel(value[i]) === getOptionLabel(val))
: getOptionLabel(previousProps.value ?? '') === getOptionLabel(value ?? ''))
: isSameValue(previousProps.value, value))
) {
const previousHighlightedOption = previousProps.filteredOptions[highlightedIndexRef.current];

Expand Down

0 comments on commit d78cb1a

Please sign in to comment.