@@ -196,6 +196,7 @@ function initSearch() {
196196 var $searchInput = document . getElementById ( "search" ) ;
197197 var $searchResults = document . querySelector ( ".search-results" ) ;
198198 var $searchResultsItems = document . querySelector ( ".search-results__items" ) ;
199+ var $slashIcon = document . getElementById ( "slash-icon" ) ;
199200 var MAX_ITEMS = 10 ;
200201
201202 var options = {
@@ -250,6 +251,27 @@ function initSearch() {
250251 return index ;
251252 } ;
252253
254+ // Function to toggle slash icon visibility
255+ function updateSlashIconVisibility ( ) {
256+ if ( $slashIcon ) {
257+ // Hide if field is focused OR has text, show only when unfocused AND empty
258+ if ( document . activeElement === $searchInput || $searchInput . value . trim ( ) !== "" ) {
259+ $slashIcon . classList . add ( "hidden" ) ;
260+ } else {
261+ $slashIcon . classList . remove ( "hidden" ) ;
262+ }
263+ }
264+ }
265+
266+ // Update slash icon visibility on input
267+ $searchInput . addEventListener ( "input" , updateSlashIconVisibility ) ;
268+
269+ // Hide slash icon when search field is focused
270+ $searchInput . addEventListener ( "focus" , updateSlashIconVisibility ) ;
271+
272+ // Show slash icon when search field loses focus (if empty)
273+ $searchInput . addEventListener ( "blur" , updateSlashIconVisibility ) ;
274+
253275 $searchInput . addEventListener (
254276 "keyup" ,
255277 debounce ( async function ( ) {
@@ -293,6 +315,8 @@ function initSearch() {
293315 // clear search query to go back to placeholder
294316 $searchInput . value = "" ;
295317 $searchInput . blur ( ) ;
318+ // Show slash icon again since input is now empty
319+ updateSlashIconVisibility ( ) ;
296320 }
297321 } ) ;
298322
0 commit comments