Combobox: Fix an issue where custom values would accumulate as typed (#103891)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user