Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Dropdown: ensure reactivity of components 'selectedItem' prop #1111

Merged
merged 9 commits into from
Jun 25, 2024
6 changes: 6 additions & 0 deletions src/components/Dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const Dropdown = ({ className, header, icon, items, onSelect, open, placeholder,

const dropdownId = id || useId();

// ensure reactivity of 'selectedItem' prop is preserved
useEffect(() => {
selectItem(selectedItem || { title: '', id: '' });
johnnadeluy marked this conversation as resolved.
Show resolved Hide resolved
setActiveOption(selectedItem || { title: '', id: '' });
}, [selectedItem]);

const filterOptions = value => {
updateInputValue(value);
filterAvailableOptions(items.filter(it => it.title.toLowerCase().includes(value.toLowerCase())));
Expand Down