Skip to content

Commit

Permalink
Trigger a search event when search stops
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Aug 22, 2024
1 parent 7ec0738 commit 698e79a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -937,19 +937,19 @@ example.passedElement.element.addEventListener(
### change
**Payload:** `value`
**Payload:** `value: string`
**Input types affected:** `text`, `select-one`, `select-multiple`
**Usage:** Triggered each time an item is added/removed **by a user**.
### 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
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,11 @@ class Choices {
this._isSearching = false;
if (wasSearching) {
this._store.dispatch(activateChoices(true));

this.passedElement.triggerEvent(EventType.search, {
value: '',
resultCount: 0,
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/interfaces/passed-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 698e79a

Please sign in to comment.