Combobox: Fix an issue where custom values would accumulate as typed (#103891)

This commit is contained in:
Josh Hunt
2025-04-11 16:27:37 +01:00
committed by GitHub
parent 4c21e7f8c2
commit 57a275f1cf
@@ -65,10 +65,12 @@ export function useOptions<T extends string | number>(rawOptions: AsyncOptions<T
(opts: Array<ComboboxOption<T>>) => {
let currentOptions: Array<ComboboxOption<T>> = opts;
if (createCustomValue && userTypedSearch) {
//Since the label of a normal option does not have to match its value and a custom option has the same value and label,
//we just focus on the value to check if the option already exists
// Since the label of a normal option does not have to match its value and a custom option has the same value and label,
// we just focus on the value to check if the option already exists
const customValueExists = opts.some((opt) => opt.value === userTypedSearch);
if (!customValueExists) {
// Make sure to clone the array first to avoid mutating the original array!
currentOptions = currentOptions.slice();
currentOptions.unshift({
label: userTypedSearch,
value: userTypedSearch as T,