Skip to content

Commit

Permalink
fix: resolved conf
Browse files Browse the repository at this point in the history
  • Loading branch information
meenakshi-deriv committed Aug 22, 2024
1 parent 0e5b1e4 commit 4d47850
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/components/Input/dropdown-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface TDropdownProps extends InputProps {
onSelectOption: (value: string) => void;
isAutocomplete?: boolean;
options: TOptionList[];
defaultOption?: TOptionList;
listHeight?: string;
}

Expand All @@ -25,6 +26,7 @@ export const InputDropdown = forwardRef<HTMLInputElement, TDropdownProps>(
disabled,
label,
options,
defaultOption,
textAlignment = "left",
inputSize = "md",
status = "neutral",
Expand All @@ -41,7 +43,7 @@ export const InputDropdown = forwardRef<HTMLInputElement, TDropdownProps>(
const [items, setItems] = useState<TOptionList[]>(options);
const [shouldFilterList, setShouldFilterList] = useState(false);
const [selectedItem, setSelectedItem] = useState<TOptionList | null>(
null,
defaultOption ?? null,
);
const [isAnimating, setIsAnimating] = useState(false);

Expand All @@ -60,8 +62,7 @@ export const InputDropdown = forwardRef<HTMLInputElement, TDropdownProps>(
openMenu,
highlightedIndex,
} = useCombobox({
defaultSelectedItem:
options.find((item) => item.value === value) ?? null,
defaultSelectedItem: defaultOption ?? null,
items,
itemToString(item) {
return item ? reactNodeToString(item.text) : "";
Expand Down Expand Up @@ -112,8 +113,10 @@ export const InputDropdown = forwardRef<HTMLInputElement, TDropdownProps>(
(option) => option.value === value,
);
defaultItem && setSelectedItem(defaultItem);
} else if (defaultOption) {
setSelectedItem(defaultOption);
}
}, [options]);
}, [options, value, defaultOption]);

return (
<div className="dropdown__wrapper" {...getToggleButtonProps()}>
Expand All @@ -133,7 +136,7 @@ export const InputDropdown = forwardRef<HTMLInputElement, TDropdownProps>(
onKeyDown={() => setShouldFilterList(true)}
readOnly={!isAutocomplete}
type="select"
value={value}
value={selectedItem?.value}
{...getInputProps()}
{...rest}
/>
Expand Down

0 comments on commit 4d47850

Please sign in to comment.