@@ -172,47 +172,52 @@ export class PfSearchInput extends LitElement {
172172 const hideLightDomItems = ! ComboboxController . supportsCrossRootActiveDescendant ;
173173
174174 return html `
175- < div
176- id ="outer "
177- style ="${ styleMap ( styles ) } "
178- class ="${ classMap ( { disabled, expanded, [ anchor ] : ! ! anchor , [ alignment ] : ! ! alignment } ) } "
179- >
180- < div id ="toggle ">
181- < div class ="search-icon ">
182- < pf-icon size ="md " icon ="search " set ="fas "> search</ pf-icon >
183- </ div >
184- < input
185- id ="toggle-input "
186- ?disabled ="${ disabled } "
187- @keydown =${ this . #onSearchInput}
188- placeholder ="${ placeholder } ">
189- < div class ="close-button-container ">
190- < pf-button
191- @click ="${ this . #OnClose} "
192- ?hidden ="${ this . #hideCloseButton( ) } "
193- id ="close-button "
194- plain
195- label ="Close "
196- >
197- < pf-icon size ="md " icon ="close " set ="patternfly "> close</ pf-icon >
198- </ pf-button >
199- </ div >
200- < button aria-label ="toggle button " inert class ="visually-hidden " id ="toggle-button "> </ button >
201- </ div >
175+ < div class ="search-input-container " @click =${ this . #onSubmit}
176+ @keydown =${ this . #handleKeyDown} >
202177 < div
203-
204- id ="listbox-container "
205- ?hidden ="${ ! expanded } "
206- style ="${ styleMap ( {
207- marginTop : `${ height || 0 } px` ,
208- width : width ? `${ width } px` : 'auto' ,
209- } ) } "
178+ id ="outer "
179+ style ="${ styleMap ( styles ) } "
180+ class ="${ classMap ( { disabled, expanded, [ anchor ] : ! ! anchor , [ alignment ] : ! ! alignment } ) } "
210181 >
211- < div id ="listbox ">
212- ${ this . #combobox. renderItemsToShadowRoot ( ) }
213- < slot ?hidden ="${ hideLightDomItems } "> </ slot >
182+ < div id ="toggle ">
183+ < div class ="search-icon ">
184+ < pf-icon size ="md " icon ="search " set ="fas "> search</ pf-icon >
185+ </ div >
186+ < input
187+ id ="toggle-input "
188+ ?disabled ="${ disabled } "
189+ @keydown =${ this . #onSearchInput}
190+ placeholder ="${ placeholder } ">
191+ < div class ="close-button-container ">
192+ < pf-button
193+ @click ="${ this . #OnClose} "
194+ ?hidden ="${ this . #hideCloseButton( ) } "
195+ id ="close-button "
196+ plain
197+ label ="Close "
198+ >
199+ < pf-icon size ="md " icon ="close " set ="patternfly "> close</ pf-icon >
200+ </ pf-button >
201+ </ div >
202+ < button aria-label ="toggle button " inert class ="visually-hidden " id ="toggle-button "> </ button >
203+ </ div >
204+ < div
205+ id ="listbox-container "
206+ ?hidden ="${ ! expanded } "
207+ style ="${ styleMap ( {
208+ marginTop : `${ height || 0 } px` ,
209+ width : width ? `${ width } px` : 'auto' ,
210+ } ) } "
211+ >
212+ < div id ="listbox ">
213+ ${ this . #combobox. renderItemsToShadowRoot ( ) }
214+ < slot ?hidden ="${ hideLightDomItems } "> </ slot >
215+ </ div >
214216 </ div >
215217 </ div >
218+ < div class ="submit-button-container ">
219+ < slot name ="submit "> </ slot >
220+ </ div >
216221 </ div >
217222 ` ;
218223 }
@@ -316,6 +321,27 @@ export class PfSearchInput extends LitElement {
316321 this . dispatchEvent ( new PfSearchChangeEvent ( ) ) ;
317322 }
318323 }
324+
325+ #onSubmit( event : MouseEvent | KeyboardEvent ) {
326+ const path = event . composedPath ( ) ;
327+ const slottedSearchButton = path . find ( el =>
328+ el instanceof HTMLElement
329+ && el . tagName === 'PF-BUTTON'
330+ && el . getAttribute ( 'data-action' ) === 'search'
331+ ) ;
332+
333+ if ( slottedSearchButton && this . _toggleInput ?. value ) {
334+ this . value = this . _toggleInput ?. value ;
335+ this . #internals. setFormValue ( this . value ?? '' ) ;
336+ this . dispatchEvent ( new PfSearchChangeEvent ( ) ) ;
337+ }
338+ }
339+
340+ #handleKeyDown( e : KeyboardEvent ) {
341+ if ( e . key === 'Enter' || e . key === ' ' ) {
342+ this . #onSubmit( e ) ;
343+ }
344+ }
319345}
320346
321347declare global {
0 commit comments