diff --git a/.changeset/yellow-carrots-play.md b/.changeset/yellow-carrots-play.md new file mode 100644 index 000000000..8d2aedb06 --- /dev/null +++ b/.changeset/yellow-carrots-play.md @@ -0,0 +1,13 @@ +--- +'@equinor/fusion-wc-searchable-dropdown': patch +'@equinor/fusion-wc-storybook': patch +--- + +### @equinor/fusion-wc-searchable-dropdown + +Fix: support for setting selectedId in initalItems +Fix: better handling of multiple selections + +### @equinor/fusion-wc-storybook + +Fix: can use selectedId in stories and eslint diff --git a/packages/searchable-dropdown/src/provider/controller.ts b/packages/searchable-dropdown/src/provider/controller.ts index 05dce2cde..0eb801c1e 100644 --- a/packages/searchable-dropdown/src/provider/controller.ts +++ b/packages/searchable-dropdown/src/provider/controller.ts @@ -155,7 +155,7 @@ export class SearchableDropdownController implements ReactiveController { return child; }); } else { - if (selectedId === item.id) {'' + if (selectedId === item.id) { item.isSelected = true; if (isMultiple) { this._selectedItems.push(item); @@ -237,21 +237,6 @@ export class SearchableDropdownController implements ReactiveController { this._selectedItems = [selectedItem]; } } - - // if (this.#host.multiple) { - // if (this._selectedItems.find((si) => si.id === selectedItem?.id)) { - // /* Already selected so clear it from selections */ - // selectedItem.isSelected = false; - // this._selectedItems = this._selectedItems.filter((i) => i.id !== selectedItem?.id); - // } else { - // /* Adds new item to selections */ - // selectedItem.isSelected = true; - // this._selectedItems.push(selectedItem); - // } - // } else { - // /* Adds new item to selections */ - // this._selectedItems = [selectedItem]; - // } } else { /* Clear selected states if any */ this._selectedItems = [];