Skip to content

Commit

Permalink
Improved combobox behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Civolilah committed Dec 5, 2023
1 parent 87256b5 commit 3bd9ae2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/forms/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ export function Combobox<T = any>({
setIsOpen(false);

if (selectedOption && selectedOption.value) {
if (inputValue !== selectedOption.label) {
setInputValue(selectedOption.label.toString());
}

return;
}

Expand All @@ -263,6 +267,8 @@ export function Combobox<T = any>({
onChange(option);
});

console.log(selectedOption);

useDebounce(
() => {
if (inputValue === '' && filteredOptions.length > 0) {
Expand Down Expand Up @@ -311,9 +317,7 @@ export function Combobox<T = any>({
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={{
Expand Down

0 comments on commit 3bd9ae2

Please sign in to comment.