Fix removing a choice didn't work properly when it was part of a group

This commit is contained in:
Xon 2024-09-05 12:11:33 +08:00
commit 6b776717f9
2 changed files with 4 additions and 0 deletions

View file

@ -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

View file

@ -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;
}