Skip to content

Commit

Permalink
fix: keep correct dropdown value on update #1154
Browse files Browse the repository at this point in the history
resolves #1154
  • Loading branch information
aalencar committed Jan 14, 2022
1 parent 955c30d commit 6f8415f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ui/src/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const
BaseDropdown = ({ name, label, required, disabled, value, values, choices, trigger, placeholder }: Dropdown) => {
const
isMultivalued = !!values,
[singleSelection, setSingleSelection] = React.useState<S | U | undefined>(value),
selection = React.useMemo(() => isMultivalued ? new Set<S>(values) : null, [isMultivalued, values]),
[selectedOptions, setSelectedOptions] = React.useState(Array.from(selection || [])),
options = (choices || []).map(({ name, label, disabled }): Fluent.IDropdownOption => ({ key: name, text: label || name, disabled })),
Expand All @@ -97,6 +98,7 @@ const
wave.args[name] = selectedOpts
setSelectedOptions(selectedOpts)
} else {
setSingleSelection(option.key)
wave.args[name] = optionKey
}
}
Expand Down Expand Up @@ -134,8 +136,8 @@ const
required={required}
disabled={disabled}
multiSelect={isMultivalued || undefined}
defaultSelectedKey={!isMultivalued ? value : undefined}
selectedKeys={isMultivalued ? selectedOptions : undefined}
selectedKey={singleSelection}
onChange={onChange}
/>
{
Expand Down

0 comments on commit 6f8415f

Please sign in to comment.