Skip to content

Commit 6e72240

Browse files
committed
Cleanup appending group label to choices
1 parent b6e9809 commit 6e72240

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

src/scripts/choices.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -917,16 +917,6 @@ class Choices {
917917
renderLimit = config.renderChoiceLimit;
918918
}
919919

920-
const groupLookup: string[] = [];
921-
const appendGroupInSearch = config.appendGroupInSearch && isSearching;
922-
if (appendGroupInSearch) {
923-
this._store.activeGroups.forEach((group) => {
924-
if (group.label) {
925-
groupLookup[group.id] = group.label;
926-
}
927-
});
928-
}
929-
930920
if (this._isSelectElement) {
931921
const backingOptions = this._store.activeChoices.filter((choice) => !choice.element);
932922
if (backingOptions.length) {
@@ -942,7 +932,7 @@ class Choices {
942932
);
943933

944934
let selectableChoices = this._isSelectOneElement;
945-
const renderChoices = (choices: ChoiceFull[], withinGroup: boolean): void => {
935+
const renderChoices = (choices: ChoiceFull[], withinGroup: boolean, groupLabel?: string): void => {
946936
if (isSearching) {
947937
// sortByRank is used to ensure stable sorting, as scores are non-unique
948938
// this additionally ensures fuseOptions.sortFn is not ignored
@@ -958,13 +948,7 @@ class Choices {
958948
choices.every((choice, index) => {
959949
// choiceEl being empty signals the contents has probably significantly changed
960950
const dropdownItem =
961-
choice.choiceEl ||
962-
this._templates.choice(
963-
config,
964-
choice,
965-
config.itemSelectText,
966-
appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined,
967-
);
951+
choice.choiceEl || this._templates.choice(config, choice, config.itemSelectText, groupLabel);
968952
choice.choiceEl = dropdownItem;
969953
fragment.appendChild(dropdownItem);
970954
if (isSearching || !choice.selected) {
@@ -984,7 +968,7 @@ class Choices {
984968
// If we have a placeholder choice along with groups
985969
renderChoices(
986970
this._store.activeChoices.filter((choice) => choice.placeholder && !choice.groupId),
987-
false,
971+
false, undefined,
988972
);
989973
}
990974

@@ -1003,11 +987,11 @@ class Choices {
1003987
dropdownGroup.remove();
1004988
fragment.appendChild(dropdownGroup);
1005989
}
1006-
renderChoices(groupChoices, true);
990+
renderChoices(groupChoices, true, config.appendGroupInSearch && isSearching ? group.label : undefined);
1007991
}
1008992
});
1009993
} else {
1010-
renderChoices(renderableChoices(this._store.activeChoices), false);
994+
renderChoices(renderableChoices(this._store.activeChoices), false, undefined);
1011995
}
1012996
}
1013997

0 commit comments

Comments
 (0)