Skip to content

Commit

Permalink
fix(multi-select): Update selected state when pill is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasBoll committed Dec 17, 2024
1 parent 49c3b36 commit 8943a2b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
4 changes: 2 additions & 2 deletions modules/preview-react/multi-select/lib/MultiSelectedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export interface MultiSelectedListProps
extends MultiSelectedItemProps,
React.HTMLAttributes<HTMLDivElement> {}

export const MultiSelectedList = createSubcomponent()({
export const MultiSelectedList = createSubcomponent('div')({
modelHook: useMultiSelectModel,
})<MultiSelectedListProps>(({'aria-labelledby': ariaLabelledBy, removeLabel}, Element, model) => {
return model.selected.state.items.length ? (
<>
<div data-part="separator" />
<ListBox
model={model.selected}
as="div"
as={Element}
role="listbox"
aria-orientation="horizontal"
aria-labelledby={ariaLabelledBy}
Expand Down
11 changes: 1 addition & 10 deletions modules/preview-react/multi-select/lib/useMultiSelectModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,12 @@ export const useMultiSelectModel = createModelHook({
orientation: 'horizontal',
onRemove({id}) {
model.events.select({id});
setSelectedItems(cachedSelected.filter(item => item.id !== id));
},
shouldVirtualize: false,
items: model.state.visibility === 'hidden' ? cachedSelected : selectedItems,
});

const state = {
...model.state,
};

const events = {
...model.events,
};

return {
selected: {
...selected,
Expand All @@ -94,7 +87,5 @@ export const useMultiSelectModel = createModelHook({
},
},
...model,
state,
events,
};
});

0 comments on commit 8943a2b

Please sign in to comment.