From 48d305e7e3a53577b7e358501b245501882726c9 Mon Sep 17 00:00:00 2001 From: NikitaRodyukov Date: Tue, 22 Oct 2024 09:20:34 +0300 Subject: [PATCH] fix(select): fixed issue in selected group options --- .changeset/tiny-hairs-tickle.md | 5 +++++ .../src/components/options-list/Component.tsx | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/tiny-hairs-tickle.md diff --git a/.changeset/tiny-hairs-tickle.md b/.changeset/tiny-hairs-tickle.md new file mode 100644 index 0000000000..10820f096b --- /dev/null +++ b/.changeset/tiny-hairs-tickle.md @@ -0,0 +1,5 @@ +--- +'@alfalab/core-components-select': patch +--- + +Исправление проблемы с выбранными опциями в групповых опциях diff --git a/packages/select/src/components/options-list/Component.tsx b/packages/select/src/components/options-list/Component.tsx index cec0d3721a..8b507821fb 100644 --- a/packages/select/src/components/options-list/Component.tsx +++ b/packages/select/src/components/options-list/Component.tsx @@ -85,14 +85,17 @@ export const OptionsList = forwardRef( const scrollbarRef = useRef(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), ); };