Skip to content

Commit

Permalink
fix: multiselect in ComboBox
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Sobolewski committed Jun 29, 2023
1 parent 96d2e9f commit d8c98d0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions js/src/inputs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,22 @@ export const ColorPicker = InputAdapter(Fluent.ColorPicker, (value, setValue) =>
onChange: (e, v) => setValue(v.str),
}), { policy: debounce, delay: 250 });

export const ComboBox = InputAdapter(Fluent.ComboBox, (value, setValue) => ({
export const ComboBox = InputAdapter(Fluent.ComboBox, (value, setValue, props) => ({
selectedKey: value && value.key,
text: value && value.text,
onChange: (e, option, i, text) => setValue(option || (text ? { text } : null)),
onChange: (e, option, i, text) => {
if (props.multiSelect) {
const options = new Set(props.options.map((item) => item.key));
let newValue = (Array.isArray(value) ? value : [value])
.filter((key) => options.has(key)); // Some options might have been removed.
newValue = option.selected
? [...newValue, option.key]
: newValue.filter((key) => key !== option.key);
setValue(newValue);
} else {
setValue(option || (text ? { text } : null));
}
},
}), { policy: debounce, delay: 250 });

export const DatePicker = InputAdapter(Fluent.DatePicker, (value, setValue) => ({
Expand Down

0 comments on commit d8c98d0

Please sign in to comment.