From 6b776717f90baa1dec8190e4dbcd4badfcf5d57e Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:11:33 +0800 Subject: [PATCH] Fix removing a choice didn't work properly when it was part of a group --- CHANGELOG.md | 1 + src/scripts/reducers/choices.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5832f3dc..1f16c5c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fix regression of `UnhighlightItem` event not firing [#1173](https://github.com/Choices-js/Choices/issues/1173) * Fix `clearChoices()` would remove items, and clear the search flag. * Fixes for opt-group handling/rendering +* Fix `removeChoice()` did not properly remove a choice which was part of a group ### Chore * Add e2e tests for "no choices" behavior to match v10 diff --git a/src/scripts/reducers/choices.ts b/src/scripts/reducers/choices.ts index 20f2463e..961575d8 100644 --- a/src/scripts/reducers/choices.ts +++ b/src/scripts/reducers/choices.ts @@ -22,6 +22,9 @@ export default function choices(s: StateType, action: ActionTypes, context?: Opt case ActionType.REMOVE_CHOICE: { action.choice.choiceEl = undefined; + if (action.choice.group) { + action.choice.group.choices = action.choice.group.choices.filter((obj) => obj.id !== action.choice.id); + } state = state.filter((obj) => obj.id !== action.choice.id); break; }