Skip to content

Commit 7f53f1e

Browse files
committed
removing search event listener and firing option-cleared event on clear button click
1 parent 2bbb568 commit 7f53f1e

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

elements/pfe-autocomplete/demo/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<link href="../../pfelement/dist/pfelement.min.css" rel="stylesheet">
2626

2727
<!-- uncomment the es5-adapter if you're using the umd version -->
28-
<script src="https://unpkg.com/@webcomponents/[email protected]/custom-elements-es5-adapter.js"></script>
28+
<!-- <script src="https://unpkg.com/@webcomponents/[email protected]/custom-elements-es5-adapter.js"></script>
2929
<script src="https://unpkg.com/@webcomponents/[email protected]/webcomponents-bundle.js"></script>
3030
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
3131
<script>
@@ -34,6 +34,10 @@
3434
'../../pfe-band/dist/pfe-band.umd.js'
3535
])
3636
37+
</script> -->
38+
<script type="module">
39+
import "../dist/pfe-autocomplete.js";
40+
import "../../pfe-band/dist/pfe-band.js";
3741
</script>
3842
</head>
3943

elements/pfe-autocomplete/docs/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ detail: {
145145
optionValue: String
146146
}
147147
```
148+
149+
### pfe-autocomplete:option-cleared
150+
Fires when a user clears the input field using the clear button.
151+
152+
```javascript
153+
detail: {
154+
searchValue: ""
155+
}
156+
```
148157
:::
149158

150159
::: section

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class PfeAutocomplete extends PFElement {
130130

131131
this._input.addEventListener("input", this._inputChanged.bind(this));
132132
this._input.addEventListener("blur", this._closeDroplist.bind(this));
133-
this._input.addEventListener("search", this._searchCleared.bind(this));
134133

135134
this._input.setAttribute("role", "combobox");
136135

@@ -171,7 +170,6 @@ class PfeAutocomplete extends PFElement {
171170
this._clearBtn.removeEventListener("click", this._clear);
172171
this._searchBtn.removeEventListener("click", this._search);
173172
this._searchBtnTextual.removeEventListener("click", this._search);
174-
this._input.removeEventListener("search", this._searchCleared.bind(this));
175173
}
176174

177175
_initValueChanged(oldVal, newVal) {
@@ -262,7 +260,11 @@ class PfeAutocomplete extends PFElement {
262260
this._searchBtn.setAttribute("disabled", "");
263261
this._searchBtnTextual.setAttribute("disabled", "");
264262
this._input.focus();
265-
this._searchCleared(this._input.value);
263+
this.emitEvent(PfeAutocomplete.events.optionCleared, {
264+
bubbles: true,
265+
composed: true,
266+
detail: { searchValue: "" },
267+
});
266268
}
267269

268270
_search() {
@@ -275,16 +277,6 @@ class PfeAutocomplete extends PFElement {
275277
this._input.setAttribute("aria-expanded", "false");
276278
}
277279

278-
_searchCleared(searchQuery = '') {
279-
if (this._input.value === "") {
280-
this.emitEvent(PfeAutocomplete.events.optionCleared, {
281-
bubbles: true,
282-
composed: true,
283-
detail: { searchValue: searchQuery},
284-
});
285-
}
286-
}
287-
288280
_openDroplist() {
289281
this.activeIndex = null;
290282
this._dropdown.open = true;

0 commit comments

Comments
 (0)