Skip to content

Commit 5a9de0e

Browse files
committed
chore: added static initialization block for outside click
1 parent 7ce25ed commit 5a9de0e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

elements/pf-search-input/pf-search-input.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ export class PfSelectChangeEvent extends Event {
3333
@customElement('pf-search-input')
3434
export class PfSearchInput extends LitElement {
3535
static readonly styles: CSSStyleSheet[] = [styles];
36-
3736
static readonly formAssociated = true;
38-
3937
static override readonly shadowRootOptions: ShadowRootInit = {
4038
...LitElement.shadowRootOptions,
4139
delegatesFocus: true,
4240
};
4341

42+
static instances: Set<PfSearchInput> = new Set<PfSearchInput>();
43+
4444
optionDetails: {
4545
text: string;
4646
value: string;
@@ -207,15 +207,23 @@ export class PfSearchInput extends LitElement {
207207
setItemSelected: (item, selected) => item.selected = selected,
208208
});
209209

210+
static {
211+
document.addEventListener('click', event => {
212+
for (const instance of PfSearchInput.instances) {
213+
instance._onOutsideClick(event);
214+
}
215+
});
216+
}
217+
210218
connectedCallback(): void {
211219
super.connectedCallback();
212-
document.addEventListener('click', this._onOutsideClick);
220+
PfSearchInput.instances.add(this);
213221
this.addOptions(this.optionDetails);
214222
}
215223

216224
disconnectedCallback(): void {
217225
super.disconnectedCallback();
218-
document.removeEventListener('click', this._onOutsideClick);
226+
PfSearchInput.instances.delete(this);
219227
}
220228

221229
// Function to handle the closing of popover

0 commit comments

Comments
 (0)