Skip to content

Commit b00c9ad

Browse files
committed
chore: display listbox only when input is entered in the textbox
1 parent 83faa65 commit b00c9ad

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@
190190
#outer.expanded #listbox-container {
191191
opacity: 1;
192192
z-index: 9999 !important;
193-
max-height: 220px;
194-
overflow: hidden;
195193
}
196194

197195
#listbox {

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class PfSearchInput extends LitElement {
9898
getToggleButton: () => this._toggleButton ?? null,
9999
getComboboxInput: () => this._toggleInput ?? null,
100100
isExpanded: () => this.expanded,
101-
requestShowListbox: () => void (this.expanded ||= true),
101+
requestShowListbox: () => this.#showListbox(),
102102
requestHideListbox: () => void (this.expanded &&= false),
103103
setItemHidden: (item, hidden) => (item.id !== 'placeholder') && void (item.hidden = hidden),
104104
isItem: item => item instanceof PfOption,
@@ -181,7 +181,7 @@ export class PfSearchInput extends LitElement {
181181
<input
182182
id="toggle-input"
183183
?disabled="${disabled}"
184-
@change=${this.#onChange}
184+
@input=${this.#onChange}
185185
@keyup=${this.#onSubmit}
186186
placeholder="${placeholder}"
187187
>
@@ -244,6 +244,13 @@ export class PfSearchInput extends LitElement {
244244
this.dispatchEvent(new PfSearchChangeEvent());
245245
}
246246

247+
@observes('value')
248+
private collapseOnEmpty() {
249+
if (this.value === '') {
250+
this.expanded = false;
251+
}
252+
}
253+
247254
async #doExpand() {
248255
try {
249256
await this.#float.show({ placement: this.position || 'bottom', flip: !!this.enableFlip });
@@ -316,6 +323,17 @@ export class PfSearchInput extends LitElement {
316323
this.dispatchEvent(new PfSearchChangeEvent());
317324
}
318325
}
326+
327+
#delay(ms: number): Promise<void> {
328+
return new Promise(resolve => setTimeout(resolve, ms));
329+
}
330+
331+
async #showListbox() {
332+
await this.#delay(10);
333+
if (this.value !== '') {
334+
this.expanded ||= true;
335+
}
336+
}
319337
}
320338

321339
declare global {

0 commit comments

Comments
 (0)