From b47ae9214e9a28ff642019746456b426fc266d27 Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Thu, 1 Jan 2026 02:34:43 +0800 Subject: [PATCH] Cleanup searchRenderSelectedChoices option to just be a boolean with backwards compatible defaults --- CHANGELOG.md | 2 +- README.md | 6 ++-- src/scripts/choices.ts | 4 --- src/scripts/defaults.ts | 2 +- src/scripts/interfaces/options.ts | 6 ++-- test/scripts/choices.test.ts | 56 ------------------------------- 6 files changed, 8 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 805492e8..7523fb06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/README.md b/README.md index cbda5cb5..6675e296 100644 --- a/README.md +++ b/README.md @@ -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, `` 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:** diff --git a/src/scripts/choices.ts b/src/scripts/choices.ts index d2d2479d..ed370c40 100644 --- a/src/scripts/choices.ts +++ b/src/scripts/choices.ts @@ -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 { diff --git a/src/scripts/defaults.ts b/src/scripts/defaults.ts index 9a39a793..7a5cbaa6 100644 --- a/src/scripts/defaults.ts +++ b/src/scripts/defaults.ts @@ -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', diff --git a/src/scripts/interfaces/options.ts b/src/scripts/interfaces/options.ts index 70a2cafd..7ad7c5f7 100644 --- a/src/scripts/interfaces/options.ts +++ b/src/scripts/interfaces/options.ts @@ -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. diff --git a/test/scripts/choices.test.ts b/test/scripts/choices.test.ts index aac95d8a..e8680f27 100644 --- a/test/scripts/choices.test.ts +++ b/test/scripts/choices.test.ts @@ -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 = ` - - `; - - 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 = ` - - `; - - 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 = ` - - `; - - 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 = ` - - `; - - 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 = `