@@ -14,6 +14,7 @@ import { TextInputGroup, TextInputGroupMain, TextInputGroupUtilities } from '../
1414import { InputGroup , InputGroupItem } from '../InputGroup' ;
1515import { Popper } from '../../helpers' ;
1616import textInputGroupStyles from '@patternfly/react-styles/css/components/TextInputGroup/text-input-group' ;
17+ import inputGroupStyles from '@patternfly/react-styles/css/components/InputGroup/input-group' ;
1718
1819/** Properties for adding search attributes to an advanced search input. These properties must
1920 * be passed in as an object within an array to the search input component's attribute property.
@@ -41,6 +42,8 @@ export interface SearchInputExpandable {
4142 onToggleExpand : ( event : React . SyntheticEvent < HTMLButtonElement > , isExpanded : boolean ) => void ;
4243 /** An accessible label for the expandable search input toggle. */
4344 toggleAriaLabel : string ;
45+ /** Flag indicating animations should be enabled when the search input expands and collapses. */
46+ hasAnimations ?: boolean ;
4447}
4548
4649/** The main search input component. */
@@ -177,7 +180,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
177180 const popperRef = useRef ( null ) ;
178181 const [ focusAfterExpandChange , setFocusAfterExpandChange ] = useState ( false ) ;
179182
180- const { isExpanded, onToggleExpand, toggleAriaLabel } = expandableInput || { } ;
183+ const { isExpanded, onToggleExpand, toggleAriaLabel, hasAnimations } = expandableInput || { } ;
181184
182185 useEffect ( ( ) => {
183186 // this effect and the focusAfterExpandChange variable are needed to focus the input/toggle as needed when the
@@ -349,7 +352,31 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
349352 </ TextInputGroup >
350353 ) ;
351354
352- const expandableToggle = (
355+ const expandToggleButton = (
356+ < Button
357+ variant = { ButtonVariant . plain }
358+ aria-label = { toggleAriaLabel }
359+ aria-expanded = { isExpanded }
360+ icon = { < SearchIcon /> }
361+ onClick = { onExpandHandler }
362+ ref = { searchInputExpandableToggleRef }
363+ { ...( isExpanded && { inert : '' } ) }
364+ />
365+ ) ;
366+
367+ const collapseToggleButton = (
368+ < Button
369+ variant = { ButtonVariant . plain }
370+ aria-label = { toggleAriaLabel }
371+ aria-expanded = { isExpanded }
372+ icon = { < TimesIcon /> }
373+ onClick = { onExpandHandler }
374+ ref = { searchInputExpandableToggleRef }
375+ { ...( ! isExpanded && { inert : '' } ) }
376+ />
377+ ) ;
378+
379+ const singleButtonToggle = (
353380 < Button
354381 variant = { ButtonVariant . plain }
355382 aria-label = { toggleAriaLabel }
@@ -360,10 +387,34 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
360387 />
361388 ) ;
362389
363- const buildExpandableSearchInput = ( { ...searchInputProps } = { } ) => (
390+ const expandableToggle = (
391+ < >
392+ { ! hasAnimations && < InputGroupItem isPlain > { singleButtonToggle } </ InputGroupItem > }
393+ { hasAnimations && (
394+ < >
395+ < InputGroupItem className = { inputGroupStyles . modifiers . searchExpand } isPlain >
396+ { expandToggleButton }
397+ </ InputGroupItem >
398+ < InputGroupItem className = { inputGroupStyles . modifiers . searchAction } isPlain >
399+ { collapseToggleButton }
400+ </ InputGroupItem >
401+ </ >
402+ ) }
403+ </ >
404+ ) ;
405+
406+ const buildExpandableSearchInput = ( { ...searchInputProps } : any = { } ) => (
364407 < InputGroup { ...searchInputProps } >
365- < InputGroupItem isFill > { buildTextInputGroup ( ) } </ InputGroupItem >
366- < InputGroupItem isPlain > { expandableToggle } </ InputGroupItem >
408+ < InputGroupItem
409+ isFill
410+ { ...( hasAnimations && { className : inputGroupStyles . modifiers . searchInput } ) }
411+ { ...( ! isExpanded && {
412+ inert : ''
413+ } ) }
414+ >
415+ { buildTextInputGroup ( ) }
416+ </ InputGroupItem >
417+ { expandableToggle }
367418 </ InputGroup >
368419 ) ;
369420
@@ -377,9 +428,19 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
377428
378429 const buildSearchTextInputGroupWithExtraButtons = ( { ...searchInputProps } = { } ) => (
379430 < InputGroup ref = { triggerRef } { ...searchInputProps } >
380- < InputGroupItem isFill > { buildTextInputGroup ( ) } </ InputGroupItem >
431+ < InputGroupItem
432+ isFill
433+ { ...( expandableInput && hasAnimations && { className : inputGroupStyles . modifiers . searchInput } ) }
434+ { ...( expandableInput &&
435+ hasAnimations &&
436+ ! isExpanded && {
437+ inert : ''
438+ } ) }
439+ >
440+ { buildTextInputGroup ( ) }
441+ </ InputGroupItem >
381442 { ( attributes . length > 0 || onToggleAdvancedSearch ) && (
382- < InputGroupItem isPlain >
443+ < InputGroupItem isPlain { ... ( hasAnimations && { className : inputGroupStyles . modifiers . searchAction } ) } >
383444 < Button
384445 className = { isSearchMenuOpen && 'pf-m-expanded' }
385446 variant = { ButtonVariant . control }
@@ -392,7 +453,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
392453 </ InputGroupItem >
393454 ) }
394455 { ! ! onSearch && (
395- < InputGroupItem >
456+ < InputGroupItem { ... ( hasAnimations && { className : inputGroupStyles . modifiers . searchAction } ) } >
396457 < Button
397458 type = "submit"
398459 variant = { ButtonVariant . control }
@@ -413,11 +474,15 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
413474
414475 const searchInputProps = {
415476 ...props ,
416- className : className && css ( className ) ,
477+ className : css (
478+ expandableInput && hasAnimations && inputGroupStyles . modifiers . searchExpandable ,
479+ expandableInput && hasAnimations && isExpanded && inputGroupStyles . modifiers . expanded ,
480+ className && css ( className )
481+ ) ,
417482 innerRef : searchInputRef
418483 } ;
419484
420- if ( ! ! expandableInput && ! isExpanded ) {
485+ if ( ! ! expandableInput && ! isExpanded && ! hasAnimations ) {
421486 return (
422487 < InputGroup { ...searchInputProps } >
423488 < InputGroupItem > { expandableToggle } </ InputGroupItem >
@@ -452,7 +517,12 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
452517 const AdvancedSearchWithPopper = (
453518 < div className = { css ( className ) } ref = { searchInputRef } { ...props } >
454519 < Popper
455- trigger = { buildSearchTextInputGroupWithExtraButtons ( ) }
520+ trigger = { buildSearchTextInputGroupWithExtraButtons ( {
521+ className : css (
522+ expandableInput && hasAnimations && inputGroupStyles . modifiers . searchExpandable ,
523+ expandableInput && hasAnimations && isExpanded && inputGroupStyles . modifiers . expanded
524+ )
525+ } ) }
456526 triggerRef = { triggerRef }
457527 popper = { AdvancedSearch }
458528 popperRef = { popperRef }
@@ -466,7 +536,12 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
466536
467537 const AdvancedSearchInline = (
468538 < div className = { css ( className ) } ref = { searchInputRef } { ...props } >
469- { buildSearchTextInputGroupWithExtraButtons ( ) }
539+ { buildSearchTextInputGroupWithExtraButtons ( {
540+ className : css (
541+ expandableInput && hasAnimations && inputGroupStyles . modifiers . searchExpandable ,
542+ expandableInput && hasAnimations && isExpanded && inputGroupStyles . modifiers . expanded
543+ )
544+ } ) }
470545 { AdvancedSearch }
471546 </ div >
472547 ) ;
0 commit comments