@@ -190,15 +190,13 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
190190 } else if ( isExpanded ) {
191191 searchInputInputRef ?. current ?. focus ( ) ;
192192 } else {
193- if ( hasAnimations ) {
194- setTimeout ( ( ) => {
195- searchInputExpandableToggleRef ?. current ?. focus ( ) ;
196- } , 150 ) ;
197- } else {
193+ if ( ! hasAnimations ) {
198194 searchInputExpandableToggleRef ?. current ?. focus ( ) ;
199195 }
200196 }
201- setFocusAfterExpandChange ( false ) ;
197+ if ( ! hasAnimations ) {
198+ setFocusAfterExpandChange ( false ) ;
199+ }
202200 } , [ focusAfterExpandChange , isExpanded , searchInputInputRef , searchInputExpandableToggleRef ] ) ;
203201
204202 useEffect ( ( ) => {
@@ -487,6 +485,15 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
487485 innerRef : searchInputRef
488486 } ;
489487
488+ const onTransitionEnd = ( ) => {
489+ ! isExpanded && focusAfterExpandChange && searchInputExpandableToggleRef ?. current ?. focus ( ) ;
490+ setFocusAfterExpandChange ( false ) ;
491+ } ;
492+
493+ if ( hasAnimations ) {
494+ searchInputProps . onTransitionEnd = onTransitionEnd ;
495+ }
496+
490497 if ( ! ! expandableInput && ! isExpanded && ! hasAnimations ) {
491498 return (
492499 < InputGroup { ...searchInputProps } >
@@ -519,15 +526,19 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
519526 </ div >
520527 ) ;
521528
529+ const advancedSearchInputProps = hasAnimations
530+ ? {
531+ className : css (
532+ expandableInput && inputGroupStyles . modifiers . searchExpandable ,
533+ expandableInput && isExpanded && inputGroupStyles . modifiers . expanded
534+ ) ,
535+ onTransitionEnd
536+ }
537+ : null ;
522538 const AdvancedSearchWithPopper = (
523539 < div className = { css ( className ) } ref = { searchInputRef } { ...props } >
524540 < Popper
525- trigger = { buildSearchTextInputGroupWithExtraButtons ( {
526- className : css (
527- expandableInput && hasAnimations && inputGroupStyles . modifiers . searchExpandable ,
528- expandableInput && hasAnimations && isExpanded && inputGroupStyles . modifiers . expanded
529- )
530- } ) }
541+ trigger = { buildSearchTextInputGroupWithExtraButtons ( advancedSearchInputProps ) }
531542 triggerRef = { triggerRef }
532543 popper = { AdvancedSearch }
533544 popperRef = { popperRef }
@@ -541,12 +552,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({
541552
542553 const AdvancedSearchInline = (
543554 < div className = { css ( className ) } ref = { searchInputRef } { ...props } >
544- { buildSearchTextInputGroupWithExtraButtons ( {
545- className : css (
546- expandableInput && hasAnimations && inputGroupStyles . modifiers . searchExpandable ,
547- expandableInput && hasAnimations && isExpanded && inputGroupStyles . modifiers . expanded
548- )
549- } ) }
555+ { buildSearchTextInputGroupWithExtraButtons ( advancedSearchInputProps ) }
550556 { AdvancedSearch }
551557 </ div >
552558 ) ;
0 commit comments