From 643f79d462ae98d1cd55a0680d74c93684d220df Mon Sep 17 00:00:00 2001 From: Yair Even Or Date: Sat, 23 Nov 2024 21:47:57 +0700 Subject: [PATCH] call the custom `sortby` (if defined) also when there's no search query --- src/parts/suggestions.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/parts/suggestions.js b/src/parts/suggestions.js index a6354f3f..71678835 100644 --- a/src/parts/suggestions.js +++ b/src/parts/suggestions.js @@ -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, @@ -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 @@ -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) },