@@ -52,55 +52,56 @@ export function SearchBarButton({
5252
5353 return (
5454 < >
55- { /* We don't want to show the input when overlay is open */ }
56- { ! isSearchOpen ? (
57- < >
58- { /* On mobile only the IconButton is shown */ }
59- < IconButton
60- data-testid = "mobile-search-button"
61- data-instance = { instanceId }
62- ref = { searchButtonRef }
63- className = { styles . searchIconButton }
64- onClick = { handleClick }
65- tabIndex = { 0 }
66- aria-label = { t ( 'search.input.placeholder_no_icon' ) }
67- icon = { SearchIcon }
68- />
69- { /* On large and up the SearchBarButton is shown */ }
70- < button
71- data-testid = "search"
72- data-instance = { instanceId }
73- tabIndex = { 0 }
74- aria-label = { t ( 'search.input.placeholder_no_icon' ) }
75- className = { styles . searchInputButton }
76- onKeyDown = { handleKeyDown }
77- onClick = { handleClick }
78- ref = { searchButtonRef }
55+ { /* Keep buttons in DOM even when overlay is open so returnFocusRef
56+ can restore focus to the trigger element on overlay close. */ }
57+ < div style = { isSearchOpen ? { visibility : 'hidden' , position : 'absolute' } : undefined } >
58+ { /* On mobile only the IconButton is shown. The "small" instance is
59+ the mobile one, so it gets the ref on the icon button. */ }
60+ < IconButton
61+ data-testid = "mobile-search-button"
62+ data-instance = { instanceId }
63+ ref = { instanceId === 'small' ? searchButtonRef : undefined }
64+ className = { styles . searchIconButton }
65+ onClick = { handleClick }
66+ tabIndex = { isSearchOpen ? - 1 : 0 }
67+ aria-label = { t ( 'search.input.placeholder_no_icon' ) }
68+ icon = { SearchIcon }
69+ />
70+ { /* On large and up the SearchBarButton is shown. The "large" instance
71+ is the desktop one, so it gets the ref on the desktop button. */ }
72+ < button
73+ data-testid = "search"
74+ data-instance = { instanceId }
75+ tabIndex = { isSearchOpen ? - 1 : 0 }
76+ aria-label = { t ( 'search.input.placeholder_no_icon' ) }
77+ className = { styles . searchInputButton }
78+ onKeyDown = { handleKeyDown }
79+ onClick = { handleClick }
80+ ref = { instanceId === 'large' ? searchButtonRef : undefined }
81+ >
82+ { /* Styled to look like an input */ }
83+ < div
84+ className = { cx ( 'd-flex align-items-center flex-grow-1' , styles . searchInputContainer ) }
85+ aria-hidden
86+ tabIndex = { - 1 }
7987 >
80- { /* Styled to look like an input */ }
81- < div
82- className = { cx ( 'd-flex align-items-center flex-grow-1' , styles . searchInputContainer ) }
83- aria-hidden
84- tabIndex = { - 1 }
88+ < span
89+ className = { cx ( styles . queryText , ! urlSearchInputQuery ? styles . placeholder : null ) }
8590 >
86- < span
87- className = { cx ( styles . queryText , ! urlSearchInputQuery ? styles . placeholder : null ) }
88- >
89- { urlSearchInputQuery ? (
90- urlSearchInputQuery
91- ) : (
92- < >
93- < span className = { styles . placeholderText } > { placeHolderElements } </ span >
94- </ >
95- ) }
96- </ span >
97- </ div >
98- < span className = { styles . searchIconContainer } aria-hidden tabIndex = { - 1 } >
99- < SearchIcon />
91+ { urlSearchInputQuery ? (
92+ urlSearchInputQuery
93+ ) : (
94+ < >
95+ < span className = { styles . placeholderText } > { placeHolderElements } </ span >
96+ </ >
97+ ) }
10098 </ span >
101- </ button >
102- </ >
103- ) : null }
99+ </ div >
100+ < span className = { styles . searchIconContainer } aria-hidden tabIndex = { - 1 } >
101+ < SearchIcon />
102+ </ span >
103+ </ button >
104+ </ div >
104105 </ >
105106 )
106107}
0 commit comments