@@ -83,14 +83,15 @@ export class PfSearchInput extends LitElement {
8383
8484 @query ( '#placeholder' ) private _placeholder ?: PfOption ;
8585
86- @query ( '#outer' ) private _searchInputContainer ! : HTMLElement ;
87-
8886 #internals = InternalsController . of ( this ) ;
8987
9088 #float = new FloatingDOMController ( this , { content : ( ) => this . _listboxContainer } ) ;
9189
9290 #slots = new SlotController ( this , null , 'placeholder' ) ;
9391
92+ /** True when the user just clicked the close button */
93+ #clickedCloseButton = false ;
94+
9495 #combobox = ComboboxController . of ( this , {
9596 getItems : ( ) => this . options ,
9697 getFallbackLabel : ( ) => this . accessibleLabel
@@ -100,7 +101,7 @@ export class PfSearchInput extends LitElement {
100101 getListboxElement : ( ) => this . _listbox ?? null ,
101102 getToggleButton : ( ) => this . _toggleButton ?? null ,
102103 getComboboxInput : ( ) => this . _toggleInput ?? null ,
103- isExpanded : ( ) => this . expanded ,
104+ isExpanded : ( ) => this . #setIsExpanded ( ) ,
104105 requestShowListbox : ( ) => this . #showListbox( ) ,
105106 requestHideListbox : ( ) => void ( this . expanded &&= false ) ,
106107 setItemHidden : ( item , hidden ) => ( item . id !== 'placeholder' ) && void ( item . hidden = hidden ) ,
@@ -149,17 +150,17 @@ export class PfSearchInput extends LitElement {
149150 @keyup ="${ this . #onSubmit} "
150151 @keydown ="${ this . #onKeyDown} ">
151152 < div class ="close-button-container ">
152- < pf-button id ="close-button "
153+ < pf-button id ="toggle-button "
154+ class ="close-button "
153155 plain
154156 label ="Close "
155157 ?hidden ="${ this . #hideCloseButton( ) } "
156- @click ="${ this . #onClose } ">
158+ @click ="${ this . #onClickCloseButton } ">
157159 < pf-icon size ="md "
158160 icon ="close "
159161 set ="patternfly "> close</ pf-icon >
160162 </ pf-button >
161163 </ div >
162- < button type ="button " aria-label ="toggle button " inert class ="visually-hidden " id ="toggle-button "> </ button >
163164 </ div >
164165 < div id ="listbox-container "
165166 ?hidden ="${ ! expanded } "
@@ -245,13 +246,9 @@ export class PfSearchInput extends LitElement {
245246 }
246247 }
247248
248- async #onClose( ) {
249- if ( this . expanded ) {
250- await this . hide ( ) ;
251- }
252- this . value = '' ;
253- this . _toggleInput ! . value = this . value ;
254- this . #combobox. selected = [ ] ;
249+ async #onClickCloseButton( ) {
250+ this . _toggleInput ! . value = '' ;
251+ this . #clickedCloseButton = true ;
255252 this . _toggleInput ?. focus ( ) ;
256253 }
257254
@@ -310,6 +307,15 @@ export class PfSearchInput extends LitElement {
310307 item ?. scrollIntoView ( { behavior : 'auto' , block : 'nearest' , inline : 'nearest' } ) ;
311308 }
312309 }
310+
311+ #setIsExpanded( ) {
312+ if ( this . #clickedCloseButton) {
313+ this . #clickedCloseButton = false ;
314+ // prevent the listbox from showing when we only intend to clear the input
315+ return true ;
316+ }
317+ return this . expanded ;
318+ }
313319}
314320
315321declare global {
0 commit comments