@@ -19,6 +19,7 @@ import { PfOption } from '../pf-select/pf-option.js';
1919import { bound } from '@patternfly/pfe-core/decorators.js' ;
2020import styles from './pf-search-input.css' ;
2121
22+ /** Fired when a `<pf-search-input>` element's value changes */
2223export class PfSearchChangeEvent extends Event {
2324 constructor ( ) {
2425 super ( 'change' , { bubbles : true } ) ;
@@ -33,86 +34,40 @@ export class PfSearchChangeEvent extends Event {
3334 * Unlike selects or dropdowns, which offer predefined options, a search input lets users enter
3435 * their own keywords to filter or locate results. It includes a clear (×) button to easily
3536 * remove the current input, allowing users to start a new search quickly.
36- * @slot - insert `pf-option` here
37- * @slot placeholder - placeholder text for the search input. Overrides the `placeholder` attribute.
37+ *
38+ * @summary Allows users to search through a list for specific search terms
39+ *
3840 * @fires open - when the menu toggles open
3941 * @fires close - when the menu toggles closed
40- * @cssprop [--pf-c-search-input__toggle--PaddingTop=var(--pf-global--spacer--form-element, 0.375rem)]
41- * @cssprop [--pf-c-search-input__toggle--PaddingRight=var(--pf-global--spacer--sm, 0.5rem)]
42- * @cssprop [--pf-c-search-input__toggle--PaddingBottom=var(--pf-global--spacer--form-element, 0.375rem)]
43- * @cssprop [--pf-c-search-input__toggle--PaddingLeft=var(--pf-global--spacer--sm, 0.5rem)]
44- * @cssprop [--pf-c-search-input__toggle--MinWidth=var(--pf-global--target-size--MinWidth, 44px)]
45- * @cssprop [--pf-c-search-input__toggle--FontSize=var(--pf-global--FontSize--md, 1rem)]
46- * @cssprop [--pf-c-search-input__toggle--FontWeight=var(--pf-global--FontWeight--normal, 400)]
47- * @cssprop [--pf-c-search-input__toggle--LineHeight=var(--pf-global--LineHeight--md, 1.5)]
48- * @cssprop [--pf-c-search-input__toggle--BackgroundColor=var(--pf-global--BackgroundColor--100, #fff)]
49- * @cssprop [--pf-c-search-input__toggle--before--BorderTopWidth=var(--pf-global--BorderWidth--sm, 1px)]
50- * @cssprop [--pf-c-search-input__toggle--before--BorderRightWidth=var(--pf-global--BorderWidth--sm, 1px)]
51- * @cssprop [--pf-c-search-input__toggle--before--BorderBottomWidth=var(--pf-global--BorderWidth--sm, 1px)]
52- * @cssprop [--pf-c-search-input__toggle--before--BorderLeftWidth=var(--pf-global--BorderWidth--sm, 1px)]
53- * @cssprop [--pf-c-search-input__toggle--before--BorderWidth=initial]
54- * @cssprop [--pf-c-search-input__toggle--before--BorderTopColor=var(--pf-global--BorderColor--300, #f0f0f0)]
55- * @cssprop [--pf-c-search-input__toggle--before--BorderRightColor=var(--pf-global--BorderColor--300, #f0f0f0)]
56- * @cssprop [--pf-c-search-input__toggle--before--BorderBottomColor=var(--pf-global--BorderColor--200, #8a8d90)]
57- * @cssprop [--pf-c-search-input__toggle--before--BorderLeftColor=var(--pf-global--BorderColor--300, #f0f0f0)]
58- * @cssprop [--pf-c-search-input__toggle--Color=var(--pf-global--Color--100, #151515)]
59- * @cssprop [--pf-c-search-input__toggle--hover--before--BorderBottomColor=var(--pf-global--active-color--100, #06c)]
60- * @cssprop [--pf-c-search-input__toggle--focus--before--BorderBottomColor=var(--pf-global--active-color--100, #06c)]
61- * @cssprop [--pf-c-search-input__toggle--focus--before--BorderBottomWidth=var(--pf-global--BorderWidth--md, 2px)]
62- * @cssprop [--pf-c-search-input__toggle--active--before--BorderBottomColor=var(--pf-global--active-color--100, #06c)]
63- * @cssprop [--pf-c-search-input__toggle--active--before--BorderBottomWidth=var(--pf-global--BorderWidth--md, 2px)]
64- * @cssprop [--pf-c-search-input__toggle--m-expanded--before--BorderBottomColor=var(--pf-global--active-color--100, #06c)]
65- * @cssprop [--pf-c-search-input__toggle--m-expanded--before--BorderBottomWidth=var(--pf-global--BorderWidth--md, 2px)]
66- * @cssprop [--pf-c-search-input__toggle--disabled--BackgroundColor=var(--pf-global--disabled-color--300, #f0f0f0)]
67- * @cssprop [--pf-c-search-input__toggle--m-plain--before--BorderColor=transparent]
68- * @cssprop [--pf-c-search-input__toggle--m-placeholder--Color=transparent]
69- * @cssprop [--pf-c-search-input--m-invalid__toggle--before--BorderBottomColor=var(--pf-global--danger-color--100, #c9190b)]
70- * @cssprop [--pf-c-search-input--m-invalid__toggle--before--BorderBottomWidth=var(--pf-global--BorderWidth--md, 2px)]
71- * @cssprop [--pf-c-search-input--m-invalid__toggle--hover--before--BorderBottomColor=var(--pf-global--danger-color--100, #c9190b)]
72- * @cssprop [--pf-c-search-input--m-invalid__toggle--focus--before--BorderBottomColor=var(--pf-global--danger-color--100, #c9190b)]
73- * @cssprop [--pf-c-search-input--m-invalid__toggle--active--before--BorderBottomColor=var(--pf-global--danger-color--100, #c9190b)]
74- * @cssprop [--pf-c-search-input--m-invalid__toggle--m-expanded--before--BorderBottomColor=var(--pf-global--danger-color--100, #c9190b)]
75- * @cssprop [--pf-c-search-input--m-invalid__toggle-status-icon--Color=var(--pf-global--danger-color--100, #c9190b)]
76- * @cssprop [--pf-c-search-input--m-success__toggle--before--BorderBottomColor=var(--pf-global--success-color--100, #3e8635)]
77- * @cssprop [--pf-c-search-input--m-success__toggle--before--BorderBottomWidth=var(--pf-global--BorderWidth--md, 2px)]
78- * @cssprop [--pf-c-search-input--m-success__toggle--hover--before--BorderBottomColor=var(--pf-global--success-color--100, #3e8635)]
79- * @cssprop [--pf-c-search-input--m-success__toggle--focus--before--BorderBottomColor=var(--pf-global--success-color--100, #3e8635)]
80- * @cssprop [--pf-c-search-input--m-success__toggle--active--before--BorderBottomColor=var(--pf-global--success-color--100, #3e8635)]
81- * @cssprop [--pf-c-search-input--m-success__toggle--m-expanded--before--BorderBottomColor=var(--pf-global--success-color--100, #3e8635)]
82- * @cssprop [--pf-c-search-input--m-success__toggle-status-icon--Color=var(--pf-global--success-color--100, #3e8635)]
83- * @cssprop [--pf-c-search-input--m-warning__toggle--before--BorderBottomColor=var(--pf-global--warning-color--100, #f0ab00)]
84- * @cssprop [--pf-c-search-input--m-warning__toggle--before--BorderBottomWidth=var(--pf-global--BorderWidth--md, 2px)]
85- * @cssprop [--pf-c-search-input--m-warning__toggle--hover--before--BorderBottomColor=var(--pf-global--warning-color--100, #f0ab00)]
86- * @cssprop [--pf-c-search-input--m-warning__toggle--focus--before--BorderBottomColor=var(--pf-global--warning-color--100, #f0ab00)]
87- * @cssprop [--pf-c-search-input--m-warning__toggle--active--before--BorderBottomColor=var(--pf-global--warning-color--100, #f0ab00)]
88- * @cssprop [--pf-c-search-input--m-warning__toggle--m-expanded--before--BorderBottomColor=var(--pf-global--warning-color--100, #f0ab00)]
89- * @cssprop [--pf-c-search-input--m-warning__toggle-status-icon--Color=var(--pf-global--warning-color--100, #f0ab00)]
90- * @cssprop [--pf-c-search-input__toggle-wrapper--not-last-child--MarginRight=var(--pf-global--spacer--xs, 0.25rem)]
91- * @cssprop [--pf-c-search-input__toggle-wrapper--MaxWidth=calc(100% - var(--pf-global--spacer--lg, 1.5rem))]
92- * @cssprop [--pf-c-search-input__toggle--m-placeholder__toggle-text--Color=var(--pf-global--Color--dark-200, #6a6e73)]
93- * @cssprop [--pf-c-search-input__toggle-icon--toggle-text--MarginLeft=var(--pf-global--spacer--xs, 0.25rem)]
94- * @cssprop [--pf-c-search-input__toggle-status-icon--MarginLeft=var(--pf-global--spacer--xs, 0.25rem)]
95- * @cssprop [--pf-c-search-input__toggle-status-icon--Color=var(--pf-global--Color--100, #151515)]
96- * @cssprop [--pf-c-search-input--m-plain__toggle-arrow--Color=var(--pf-global--Color--200, #6a6e73)]
97- * @cssprop [--pf-c-search-input--m-plain--hover__toggle-arrow--Color=var(--pf-global--Color--100, #151515)]
98- * @cssprop [--pf-c-search-input__toggle-clear--PaddingRight=var(--pf-global--spacer--sm, 0.5rem)]
99- * @cssprop [--pf-c-search-input__toggle-clear--PaddingLeft=var(--pf-global--spacer--md, 1rem)]
100- * @cssprop [--pf-c-search-input__toggle-clear--toggle-button--PaddingLeft=var(--pf-global--spacer--sm, 0.5rem)]
101- * @cssprop [--pf-c-search-input__toggle-button--Color=var(--pf-global--Color--100, #151515)]
102- * @cssprop [--pf-c-search-input__list-item--m-loading--PaddingTop=var(--pf-global--spacer--sm, 0.5rem)]
103- * @cssprop [--pf-c-search-input__menu-content--MaxHeight=20rem;]
104- **/
42+ */
10543@customElement ( 'pf-search-input' )
10644export class PfSearchInput extends LitElement {
10745 static readonly styles : CSSStyleSheet [ ] = [ styles ] ;
46+
10847 static readonly formAssociated = true ;
48+
10949 static override readonly shadowRootOptions : ShadowRootInit = {
11050 ...LitElement . shadowRootOptions ,
11151 delegatesFocus : true ,
11252 } ;
11353
11454 static instances : Set < PfSearchInput > = new Set < PfSearchInput > ( ) ;
11555
56+ static {
57+ if ( ! isServer ) {
58+ document . addEventListener ( 'click' , event => {
59+ for ( const instance of PfSearchInput . instances ) {
60+ instance . _onOutsideClick ( event ) ;
61+ }
62+ } ) ;
63+ document . addEventListener ( 'focusout' , ( ) => {
64+ for ( const instance of PfSearchInput . instances ) {
65+ instance . _onFocusOut ( ) ;
66+ }
67+ } ) ;
68+ }
69+ }
70+
11671 /** Accessible label for the search input */
11772 @property ( { attribute : 'accessible-label' } ) accessibleLabel ?: string ;
11873
@@ -179,21 +134,6 @@ export class PfSearchInput extends LitElement {
179134 setItemSelected : ( item , selected ) => this . #setItemSelected( item , selected ) ,
180135 } ) ;
181136
182- static {
183- if ( ! isServer ) {
184- document . addEventListener ( 'click' , event => {
185- for ( const instance of PfSearchInput . instances ) {
186- instance . _onOutsideClick ( event ) ;
187- }
188- } ) ;
189- document . addEventListener ( 'focusout' , ( ) => {
190- for ( const instance of PfSearchInput . instances ) {
191- instance . _onFocusOut ( ) ;
192- }
193- } ) ;
194- }
195- }
196-
197137 connectedCallback ( ) : void {
198138 super . connectedCallback ( ) ;
199139 PfSearchInput . instances . add ( this ) ;
@@ -249,50 +189,45 @@ export class PfSearchInput extends LitElement {
249189 const { disabled, expanded, placeholder } = this ;
250190 const { anchor = 'bottom' , alignment = 'start' , styles = { } } = this . #float;
251191 const { height, width } = this . getBoundingClientRect ?.( ) || { } ;
252- const hideLightDomItems = ! ComboboxController . supportsCrossRootActiveDescendant ;
253192
254193 return html `
255- < div
256- id ="outer "
257- style ="${ styleMap ( styles ) } "
258- class ="${ classMap ( { disabled, expanded, [ anchor ] : ! ! anchor , [ alignment ] : ! ! alignment } ) } "
259- >
194+ < div id ="outer "
195+ style ="${ styleMap ( styles ) } "
196+ class ="${ classMap ( { disabled, expanded, [ anchor ] : ! ! anchor , [ alignment ] : ! ! alignment } ) } ">
260197 < div id ="toggle ">
261198 < div class ="search-icon ">
262199 < pf-icon size ="md " icon ="search " set ="fas "> search</ pf-icon >
263200 </ div >
264- < input
265- id ="toggle-input "
266- @input =${ this . #onChange}
267- @keyup =${ this . #onSubmit}
268- @keydown=${ this . #onKeyDown}
269- aria-disabled="${ disabled } "
270- placeholder="${ placeholder } "
271- >
201+ < input id ="toggle-input "
202+ aria-disabled ="${ disabled } "
203+ placeholder ="${ placeholder } "
204+ @input ="${ this . #onChange} "
205+ @keyup ="${ this . #onSubmit} "
206+ @keydown ="${ this . #onKeyDown} ">
272207 < div class ="close-button-container ">
273- < pf-button
274- @click =" ${ this . #OnClose } "
275- ?hidden =" ${ this . #hideCloseButton ( ) } "
276- id =" close-button "
277- plain
278- label =" Close "
279- >
280- < pf-icon size =" md " icon =" close " set ="patternfly "> close</ pf-icon >
208+ < pf-button id =" close-button "
209+ plain
210+ label =" Close "
211+ ?hidden =" ${ this . #hideCloseButton ( ) } "
212+ @click =" ${ this . #onClose } " >
213+ < pf-icon size =" md "
214+ icon =" close "
215+ set ="patternfly "> close</ pf-icon >
281216 </ pf-button >
282217 </ div >
283218 < button type ="button " aria-label ="toggle button " inert class ="visually-hidden " id ="toggle-button "> </ button >
284219 </ div >
285- < div
286- id ="listbox-container "
287- ?hidden ="${ ! expanded } "
288- tabindex ="-1 "
289- style ="${ styleMap ( {
290- marginTop : `${ height || 0 } px` ,
291- width : width ? `${ width } px` : 'auto' ,
292- } ) } ">
220+ < div id ="listbox-container "
221+ ?hidden ="${ ! expanded } "
222+ tabindex ="-1 "
223+ style ="${ styleMap ( {
224+ marginTop : `${ height || 0 } px` ,
225+ width : width ? `${ width } px` : 'auto' ,
226+ } ) } ">
293227 < div id ="listbox ">
294228 ${ this . #combobox. renderItemsToShadowRoot ( ) }
295- < slot ?hidden ="${ hideLightDomItems } "> </ slot >
229+ <!-- insert \`<pf-option>\` and/or \`<pf-option-groups>\` here -->
230+ < slot ?hidden ="${ ! ComboboxController . supportsCrossRootActiveDescendant } "> </ slot >
296231 </ div >
297232 </ div >
298233 </ div >
@@ -374,7 +309,7 @@ export class PfSearchInput extends LitElement {
374309 }
375310 }
376311
377- async #OnClose ( ) {
312+ async #onClose ( ) {
378313 if ( this . expanded ) {
379314 await this . hide ( ) ;
380315 }
@@ -391,7 +326,7 @@ export class PfSearchInput extends LitElement {
391326 return false ;
392327 }
393328
394- #onChange( event : Event ) {
329+ #onChange( ) {
395330 this . value = this . _toggleInput ?. value ;
396331 this . #internals. setFormValue ( this . value ?? '' ) ;
397332 this . dispatchEvent ( new PfSearchChangeEvent ( ) ) ;
0 commit comments