From 698e79ad7489985f356007d90962cb24636b5651 Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:29:00 +0800 Subject: [PATCH] Trigger a search event when search stops --- README.md | 6 +++--- src/scripts/choices.ts | 5 +++++ src/scripts/interfaces/passed-element.ts | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0618bdb1..98fdf9a9 100644 --- a/README.md +++ b/README.md @@ -937,7 +937,7 @@ example.passedElement.element.addEventListener( ### change -**Payload:** `value` +**Payload:** `value: string` **Input types affected:** `text`, `select-one`, `select-multiple` @@ -945,11 +945,11 @@ example.passedElement.element.addEventListener( ### search -**Payload:** `value`, `resultCount` +**Payload:** `value: string`, `resultCount: number` **Input types affected:** `select-one`, `select-multiple` -**Usage:** Triggered when a user types into an input to search choices. +**Usage:** Triggered when a user types into an input to search choices. When a search is ended, a search event with an empty value with no resultCount is triggered. ### showDropdown diff --git a/src/scripts/choices.ts b/src/scripts/choices.ts index 7acf452d..56cd6c21 100644 --- a/src/scripts/choices.ts +++ b/src/scripts/choices.ts @@ -1492,6 +1492,11 @@ class Choices { this._isSearching = false; if (wasSearching) { this._store.dispatch(activateChoices(true)); + + this.passedElement.triggerEvent(EventType.search, { + value: '', + resultCount: 0, + }); } } diff --git a/src/scripts/interfaces/passed-element.ts b/src/scripts/interfaces/passed-element.ts index 1a2fbbda..5e113224 100644 --- a/src/scripts/interfaces/passed-element.ts +++ b/src/scripts/interfaces/passed-element.ts @@ -60,7 +60,7 @@ export interface EventMap { change: CustomEvent<{ value: string }>; /** - * Triggered when a user types into an input to search choices. + * Triggered when a user types into an input to search choices. When a search is ended, a search event with an empty value with no resultCount is triggered. * * **Input types affected:** select-one, select-multiple *