From 60b391097c171fec753ea00abd5ab0a345419040 Mon Sep 17 00:00:00 2001 From: bhavabhuthi Date: Tue, 15 Oct 2024 14:56:24 +0530 Subject: [PATCH] Fix changing of label while selection and duplicate creation for existing items in combobox creatable --- .../src/components/Combobox/Combobox.tsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/opub-ui/src/components/Combobox/Combobox.tsx b/packages/opub-ui/src/components/Combobox/Combobox.tsx index 7998a492..aa22ec4c 100644 --- a/packages/opub-ui/src/components/Combobox/Combobox.tsx +++ b/packages/opub-ui/src/components/Combobox/Combobox.tsx @@ -190,22 +190,12 @@ export const Combobox = React.forwardRef( // for multi select const selectedArr = e.map((value: string) => { - if (comboboxList.findIndex((item) => item.value === value) > 0) { - return comboboxList.find((item) => item.value === value); - } else { - setComboboxList([ - ...comboboxList, - { - label: value, - value: value, - }, - ]); - - return { + return ( + comboboxList.find((item) => item.value === value) || { label: value, value: value, - }; - } + } + ); }); setSelectedValues(selectedArr);