Rename sortFilter to sortFn

This commit is contained in:
Josh Johnson 2017-12-19 12:19:43 +00:00
parent beeeeb87ad
commit e3aa6e723e
2 changed files with 8 additions and 8 deletions

View file

@ -82,7 +82,7 @@ Or include Choices directly:
regexFilter: null,
shouldSort: true,
shouldSortItems: false,
sortFilter: () => {...},
sortFn: () => {...},
placeholder: true,
placeholderValue: null,
searchPlaceholderValue: null,
@ -345,7 +345,7 @@ Pass an array of objects:
**Usage:** Whether items should be sorted. If false, items will appear in the order they were selected.
### sortFilter
### sortFn
**Type:** `Function` **Default:** sortByAlpha
**Input types affected:** `select-one`, `select-multiple`
@ -357,7 +357,7 @@ Pass an array of objects:
```js
// Sorting via length of label from largest to smallest
const example = new Choices(element, {
sortFilter: function(a, b) {
sortFn: function(a, b) {
return b.label.length - a.label.length;
},
};

View file

@ -52,7 +52,7 @@ class Choices {
items: [],
choices: [],
classNames: DEFAULT_CLASSNAMES,
sortFilter: sortByAlpha,
sortFn: sortByAlpha,
};
// Merge options with user options
@ -281,7 +281,7 @@ class Choices {
*/
renderGroups(groups, choices, fragment) {
const groupFragment = fragment || document.createDocumentFragment();
const filter = this.config.sortFilter;
const filter = this.config.sortFn;
const getGroupChoices = group => choices.filter((choice) => {
if (this.isSelectOneElement) {
return choice.groupId === group.id;
@ -318,7 +318,7 @@ class Choices {
// Create a fragment to store our list items (so we don't have to update the DOM for each item)
const choicesFragment = fragment || document.createDocumentFragment();
const { renderSelectedChoices, searchResultLimit, renderChoiceLimit } = this.config;
const filter = this.isSearching ? sortByScore : this.config.sortFilter;
const filter = this.isSearching ? sortByScore : this.config.sortFn;
const appendChoice = (choice) => {
const shouldRender = renderSelectedChoices === 'auto' ?
(this.isSelectOneElement || !choice.selected) :
@ -384,7 +384,7 @@ class Choices {
// If sorting is enabled, filter items
if (this.config.shouldSortItems && !this.isSelectOneElement) {
items.sort(this.config.sortFilter);
items.sort(this.config.sortFn);
}
if (this.isTextElement) {
@ -2245,7 +2245,7 @@ class Choices {
});
} else {
const passedOptions = this.passedElement.getOptions();
const filter = this.config.sortFilter;
const filter = this.config.sortFn;
const allChoices = this.presetChoices;
// Create array of options from option elements