Skip to content

Commit

Permalink
call the custom sortby (if defined) also when there's no search query
Browse files Browse the repository at this point in the history
  • Loading branch information
yairEO committed Dec 7, 2024
1 parent 7c4ce8f commit 643f79d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/parts/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export default {
whitelist = _s.whitelist,
suggestionsCount = _sd.maxItems >= 0 ? _sd.maxItems : Infinity,
includeSelectedTags = _sd.includeSelectedTags || _s.mode == 'select',
hasCustomSort = typeof _sd.sortby == 'function',
searchKeys = _sd.searchKeys,
whitelistItem,
valueIsInWhitelist,
Expand All @@ -387,7 +388,10 @@ export default {
: whitelist.filter(item => !this.isTagDuplicate( isObject(item) ? item.value : item )) // don't include tags which have already been added.

this.state.dropdown.suggestions = list;
return list.slice(0, suggestionsCount); // respect "maxItems" dropdown setting

return hasCustomSort
? _sd.sortby(list, niddle)
: list.slice(0, suggestionsCount); // respect "maxItems" dropdown setting
}

niddle = _sd.caseSensitive
Expand Down Expand Up @@ -456,7 +460,7 @@ export default {
this.state.dropdown.suggestions = exactMatchesList.concat(list);

// custom sorting function
return typeof _sd.sortby == 'function'
return hasCustomSort
? _sd.sortby(exactMatchesList.concat(list), niddle)
: exactMatchesList.concat(list).slice(0, suggestionsCount)
},
Expand Down

0 comments on commit 643f79d

Please sign in to comment.