Skip to content

Commit

Permalink
fix(select): fixed issue in selected group options
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaRodyukov committed Oct 21, 2024
1 parent 9097936 commit 3263d52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-hairs-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alfalab/core-components-select': patch
---

Исправление проблемы с выбранными опциями в групповых опциях
12 changes: 7 additions & 5 deletions packages/select/src/components/options-list/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ export const OptionsList = forwardRef<HTMLDivElement, OptionsListProps>(
const scrollbarRef = useRef<HTMLDivElement>(null);
const counter = createCounter();
const renderGroup = (group: GroupShape) => {
const groupSelectedItems = selectedItems?.filter((item) =>
group.options.includes(item),
const groupSelectedItems = selectedItems?.filter(({ key: selectedItemKey }) =>
group.options.some((option) => option.key === selectedItemKey),
);
const handleSelectedItems = (items: OptionShape[]) => {
setSelectedItems(
(selectedItems?.filter((item) => !group.options.includes(item)) ?? []).concat(
items,
),
(
selectedItems?.filter(({ key: selectedItemKey }) =>
group.options.some((option) => option.key === selectedItemKey),
) ?? []
).concat(items),
);
};

Expand Down

0 comments on commit 3263d52

Please sign in to comment.