Skip to content

Commit a8a4b35

Browse files
committed
chore: outside click implementation
1 parent 6573703 commit a8a4b35

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

elements/pf-search-input/pf-search-input-option.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414

1515
:host(:focus) #outer,
16-
:host(:hover) #outer{
16+
:host(:hover) #outer {
1717
background-color: #e0e0e0;
1818
}
1919

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { observes } from '@patternfly/pfe-core/decorators/observes.js';
1919
import { PfSearchInputOption } from './pf-search-input-option.js';
2020
import styles from './pf-search-input.css';
2121
import type { PfButton } from '../pf-button/pf-button.js';
22+
import { bound } from '@patternfly/pfe-core/decorators.js';
2223

2324
export class PfSelectChangeEvent extends Event {
2425
constructor() {
@@ -84,6 +85,8 @@ export class PfSearchInput extends LitElement {
8485

8586
@query('#placeholder') private _placeholder?: PfSearchInputOption;
8687

88+
@query('#outer') private _searchInputContainer!: HTMLElement;
89+
8790
#isNotPlaceholderOption = (option: PfSearchInputOption) => option !== this._placeholder;
8891

8992
#internals = InternalsController.of(this);
@@ -110,6 +113,29 @@ export class PfSearchInput extends LitElement {
110113
setItemSelected: (item, selected) => item.selected = selected,
111114
});
112115

116+
connectedCallback(): void {
117+
super.connectedCallback();
118+
document.addEventListener('click', this._onOutsideClick);
119+
}
120+
121+
disconnectedCallback(): void {
122+
super.disconnectedCallback();
123+
document.removeEventListener('click', this._onOutsideClick);
124+
}
125+
126+
127+
// Function to handle the closing of popover and month select popup on outside click
128+
@bound private _onOutsideClick(event: MouseEvent) {
129+
const path = event.composedPath();
130+
if (!path.includes(this._searchInputContainer)) {
131+
if (this.expanded) {
132+
this.expanded = false;
133+
} else {
134+
//this._popover.hide();
135+
}
136+
}
137+
}
138+
113139
/**
114140
* Single select option value for single select menus,
115141
* or array of select option values for multi select.

0 commit comments

Comments
 (0)