Skip to content

Commit

Permalink
fix(MultiComboBox): itemの比較にitem.labelを参照していたのをやめる
Browse files Browse the repository at this point in the history
  • Loading branch information
eatski committed Dec 13, 2024
1 parent d10d1be commit ebef884
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/smarthr-ui/src/components/ComboBox/MultiComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ const ActualMultiComboBox = <T,>(
requestAnimationFrame(() => {
if (onDelete) onDelete(item)
if (onChangeSelected)
onChangeSelected(
selectedItems.filter(
(selected) => selected.label !== item.label || selected.value !== item.value,
),
)
onChangeSelected(selectedItems.filter((selected) => selected.value !== item.value))
})
},
[onChangeSelected, onDelete, selectedItems],
Expand All @@ -211,9 +207,7 @@ const ActualMultiComboBox = <T,>(
// HINT: Dropdown系コンポーネント内でComboBoxを使うと、選択肢がportalで表現されている関係上Dropdownが閉じてしまう
// requestAnimationFrameを追加、処理を遅延させることで正常に閉じる/閉じないの判定を行えるようにする
requestAnimationFrame(() => {
const matchedSelectedItem = selectedItems.find(
(item) => item.label === selected.label && item.value === selected.value,
)
const matchedSelectedItem = selectedItems.find((item) => item.value === selected.value)
if (matchedSelectedItem !== undefined) {
if (matchedSelectedItem.deletable !== false) {
handleDelete(selected)
Expand Down Expand Up @@ -468,7 +462,7 @@ const ActualMultiComboBox = <T,>(
className={selectedListStyle}
>
{selectedItems.map((selectedItem, i) => (
<li key={`${selectedItem.label}-${selectedItem.value}`}>
<li key={selectedItem.value}>
<MultiSelectedItem
item={selectedItem}
disabled={disabled}
Expand Down

0 comments on commit ebef884

Please sign in to comment.