Skip to content

Commit 45e2e62

Browse files
committed
feat: added custom event for clear search
1 parent dda9bd0 commit 45e2e62

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

elements/pfe-autocomplete/src/pfe-autocomplete.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class PfeAutocomplete extends PFElement {
6969
search: `${this.tag}:search-event`,
7070
select: `${this.tag}:option-selected`,
7171
optionsShown: `${this.tag}:options-shown`,
72+
optionCleared: `${this.tag}:option-cleared`,
7273
slotchange: `slotchange`,
7374
};
7475
}
@@ -129,6 +130,7 @@ class PfeAutocomplete extends PFElement {
129130

130131
this._input.addEventListener("input", this._inputChanged.bind(this));
131132
this._input.addEventListener("blur", this._closeDroplist.bind(this));
133+
this._input.addEventListener("search", this._searchCleared.bind(this));
132134

133135
this._input.setAttribute("role", "combobox");
134136

@@ -254,6 +256,7 @@ class PfeAutocomplete extends PFElement {
254256
this._searchBtn.setAttribute("disabled", "");
255257
this._searchBtnTextual.setAttribute("disabled", "");
256258
this._input.focus();
259+
this._searchCleared();
257260
}
258261

259262
_search() {
@@ -266,6 +269,14 @@ class PfeAutocomplete extends PFElement {
266269
this._input.setAttribute("aria-expanded", "false");
267270
}
268271

272+
_searchCleared() {
273+
this.emitEvent(PfeAutocomplete.events.optionsShown, {
274+
bubbles: true,
275+
composed: true,
276+
detail: { searchValue: searchQuery }
277+
});
278+
}
279+
269280
_openDroplist() {
270281
this.activeIndex = null;
271282
this._dropdown.open = true;
@@ -412,6 +423,7 @@ class PfeAutocomplete extends PFElement {
412423
* pfe-autocomplete:option-selected | Fires when an option is selected.
413424
event.details.optionValue contains the selected value.
414425
*/
426+
415427
class PfeSearchDroplist extends PFElement {
416428
static get tag() {
417429
return "pfe-search-droplist";

0 commit comments

Comments
 (0)