From 3bd9ae23739895387fe02536485a301539259c71 Mon Sep 17 00:00:00 2001 From: Civolilah Date: Tue, 5 Dec 2023 10:14:07 +0100 Subject: [PATCH] Improved combobox behavior --- src/components/forms/Combobox.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/forms/Combobox.tsx b/src/components/forms/Combobox.tsx index c374763b5b..347c8672a2 100644 --- a/src/components/forms/Combobox.tsx +++ b/src/components/forms/Combobox.tsx @@ -243,6 +243,10 @@ export function Combobox({ setIsOpen(false); if (selectedOption && selectedOption.value) { + if (inputValue !== selectedOption.label) { + setInputValue(selectedOption.label.toString()); + } + return; } @@ -263,6 +267,8 @@ export function Combobox({ onChange(option); }); + console.log(selectedOption); + useDebounce( () => { if (inputValue === '' && filteredOptions.length > 0) { @@ -311,9 +317,7 @@ export function Combobox({ onFocus={() => setIsOpen(true)} placeholder={inputOptions.placeholder} disabled={readonly} - defaultValue={ - selectedOption ? selectedOption.label : inputValue?.toString() - } + value={inputValue} className="w-full border-0 rounded py-1.5 pl-3 pr-10 shadow-sm sm:text-sm sm:leading-6" ref={inputRef} style={{