Cleanup searchRenderSelectedChoices option to just be a boolean with backwards compatible defaults

This commit is contained in:
Xon 2026-01-01 02:34:43 +08:00
commit b47ae9214e
6 changed files with 8 additions and 68 deletions

View file

@ -3,7 +3,7 @@
## [Unreleased]
### Features
- Add `searchRenderSelectedChoices` configuration option to control whether selected choices appear in search results for select-multiple inputs. Defaults to `'auto'` (backward compatible behavior). Set to `false` to hide selected choices from search results.
- Add `searchRenderSelectedChoices` configuration option to control whether selected choices appear in search results for select-multiple inputs. Defaults to `true` (backward compatible behavior). Set to `false` to hide selected choices from search results.
## [11.2.0]

View file

@ -176,7 +176,7 @@ import "choices.js/public/assets/styles/choices.css";
prependValue: null,
appendValue: null,
renderSelectedChoices: 'auto',
searchRenderSelectedChoices: 'auto',
searchRenderSelectedChoices: true,
loadingText: 'Loading...',
noResultsText: 'No results found',
noChoicesText: 'No choices to choose from',
@ -665,11 +665,11 @@ For backward compatibility, `<option value="">This is a placeholder</option>` an
### searchRenderSelectedChoices
**Type:** `'auto' | 'always' | Boolean` **Default:** `'auto'`
**Type:** `Boolean` **Default:** `true'`
**Input types affected:** `select-multiple`
**Usage:** Whether selected choices should be removed from the list during search. By default (`'auto'`), selected choices appear in search results if they match the search query. Set to `false` to hide selected choices from search results, or `'always'` to always show them in search results.
**Usage:** Whether selected choices should be removed from the list during search.
**Example:**

View file

@ -219,10 +219,6 @@ class Choices {
config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne;
}
if (typeof config.searchRenderSelectedChoices !== 'boolean') {
config.searchRenderSelectedChoices = true;
}
if (config.closeDropdownOnSelect === 'auto') {
config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect;
} else {

View file

@ -73,7 +73,7 @@ export const DEFAULT_CONFIG: Options = {
prependValue: null,
appendValue: null,
renderSelectedChoices: 'auto',
searchRenderSelectedChoices: 'auto',
searchRenderSelectedChoices: true,
loadingText: 'Loading...',
noResultsText: 'No results found',
noChoicesText: 'No choices to choose from',

View file

@ -472,13 +472,13 @@ export interface Options {
renderSelectedChoices: 'auto' | 'always' | boolean;
/**
* Whether selected choices should be removed from the list during search. By default selected choices appear in search results if they match the search query. Set to `false` to hide selected choices from search results.
* Whether selected choices should be removed from the list during search.
*
* **Input types affected:** select-multiple
*
* @default 'auto';
* @default false;
*/
searchRenderSelectedChoices: 'auto' | 'always' | boolean;
searchRenderSelectedChoices: boolean;
/**
* The text that is shown whilst choices are being populated via AJAX.

View file

@ -118,62 +118,6 @@ describe('choices', () => {
});
});
describe('passing the searchRenderSelectedChoices config option with an unexpected value', () => {
it('sets searchRenderSelectedChoices to true for select-multiple', () => {
document.body.innerHTML = `
<select data-choice multiple></select>
`;
instance = new Choices('[data-choice]', {
allowHTML: true,
searchRenderSelectedChoices: 'test' as any,
});
expect(instance.config.searchRenderSelectedChoices).to.equal(true);
});
it('sets searchRenderSelectedChoices to true for select-one', () => {
document.body.innerHTML = `
<select data-choice></select>
`;
instance = new Choices('[data-choice]', {
allowHTML: true,
searchRenderSelectedChoices: 'test' as any,
});
expect(instance.config.searchRenderSelectedChoices).to.equal(true);
});
it('sets searchRenderSelectedChoices to true for select-multiple', () => {
document.body.innerHTML = `
<select data-choice multiple></select>
`;
instance = new Choices('[data-choice]', {
allowHTML: true,
searchRenderSelectedChoices: 'test' as any,
});
expect(instance.config.searchRenderSelectedChoices).to.equal(true);
});
});
describe('passing the searchRenderSelectedChoices config option with "always"', () => {
it('sets searchRenderSelectedChoices to true', () => {
document.body.innerHTML = `
<select data-choice multiple></select>
`;
instance = new Choices('[data-choice]', {
allowHTML: true,
searchRenderSelectedChoices: 'always',
});
expect(instance.config.searchRenderSelectedChoices).to.equal(true);
});
});
describe('passing the searchRenderSelectedChoices config option with false', () => {
it('keeps searchRenderSelectedChoices as false', () => {
document.body.innerHTML = `