Skip to content

Commit 3ee117e

Browse files
authored
feat: pfe-autocomplete - fire custom event when dropdown is shown (#1046)
Fixes #1045
1 parent 96efb0a commit 3ee117e

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG-prerelease.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Prerelease 55 ( TBD )
22

3+
- [](https://github.com/patternfly/patternfly-elements/commit/) feat: pfe-autocomplete - fire custom event when dropdown is shown
34
- [](https://github.com/patternfly/patternfly-elements/commit/) fix: pfelement - restore pfelement tests (#1018)
45
- [fbe4423](https://github.com/patternfly/patternfly-elements/commit/fbe442396f06b0a097366512b698dc0b6d5e1f9f) fix: improve CLS rating in lighthouse (#1020)
56

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PfeAutocomplete extends PFElement {
3131
return {
3232
search: `${this.tag}:search-event`,
3333
select: `${this.tag}:option-selected`,
34+
optionsShown: `${this.tag}:options-shown`,
3435
slotchange: `slotchange`
3536
};
3637
}
@@ -293,6 +294,9 @@ class PfeAutocomplete extends PFElement {
293294
this.activeIndex = null;
294295
this._dropdown.setAttribute("open", true);
295296
this._dropdown.setAttribute("active-index", null);
297+
this.emitEvent(PfeAutocomplete.events.optionsShown, {
298+
composed: true
299+
});
296300
}
297301

298302
_optionSelected(e) {

elements/pfe-autocomplete/test/pfe-autocomplete_test.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@
133133
});
134134
});
135135

136+
it('should fire a pfe-autocomplete:options-shown event when the droplist is shown to the user', done => {
137+
flush(() => {
138+
const items = ['option 1', 'option 2'];
139+
140+
autocompleteElem.autocompleteRequest = function(params, callback) {
141+
const regx = new RegExp("\^" + params.query, "i");
142+
callback(items.filter(function (item) {
143+
return regx.test(item);
144+
}));
145+
};
146+
147+
autocompleteElem.addEventListener("pfe-autocomplete:options-shown", function(event) {
148+
assert.equal(droplistElem.getAttribute("open"), "true");
149+
done();
150+
});
151+
152+
autocompleteElem._sendAutocompleteRequest("o");
153+
});
154+
});
155+
136156
it('should fire pfe-autocomplete:search-event after user click on an option', done => {
137157
flush(() => {
138158
droplistElem.data = ['option 1', 'option 2'];

0 commit comments

Comments
 (0)