Hey! Having a little issue and would love if someone helps me solve it. Basically my website has live search and upon search the product appears but if anywhere on the white space I click the search disappears and upon reclicking on the search bar nothing comes up until you write enter a letter or delete a letter as search begins again. Can someone help me you solve it? I want that upon clicking on the rest area of the search the suggested search options are still there and also the product page of the clicked item is only opened when either the name or the image of the product is clicked, I want that the whole horizontal rectangular area of the specific product when clicked opens the specific product page. Thanks! Attaching items below, Website link: https://w0v9jv-y1.myshopify.com Pass: door
If I click on the green area the product page of the item opens but If I click anywhere horizontal to the product page in the red area nothing happens, I want that even if the red area is clicked the search works and product page is opened!
Here’s how you can fix both issues with your live search functionality:
1. Prevent the Search Dropdown from Disappearing on Background Click:
The issue occurs because the dropdown likely closes when a click event is detected outside the search area. To resolve this:
Steps:- Locate the JavaScript file responsible for the search dropdown functionality in your theme files. It might be named something like search.js or embedded within theme.js .
Find the code handling the “click outside” behavior. Look for a listener like document.addEventListner(‘click’, …).
Modify the code to ignore clicks inside the search area.
Example Fix:
document.addEventListener('click', function (e) {
const searchBox = document.querySelector('.search-dropdown'); // Adjust selector as needed
const searchInput = document.querySelector('.search-input'); // Adjust selector as needed
if (!searchBox.contains(e.target) && !searchInput.contains(e.target)) {
// Hide dropdown only if click is outside
searchBox.classList.remove('visible');
} else {
// Keep dropdown visible if clicked inside
searchBox.classList.add('visible');
}
});
2. Make the Entire Product Row Clickable:
The issue arises because only specific elements (like product name or image) are linked to the product page. To make the entire row clickable:
Steps:- Go to the search dropdown’s HTML template, likely in search.liquid or search-results.liquid .
3. Testing:- Save your changes and refresh your site.
Verify:
The search dropdown remains visible when clicking inside.
Clicking anywhere within a product’s row opens its page.
Got it! If you found my suggestions helpful, please consider liking or marking it as a solution.
Your feedback is appreciated! If you have any more questions or need further assistance, just let me know.
Thank you Akshay! The Entire Row clickable solution worked!, but I still am not able to implement the product dropdown disappering on click. Could you help me fix it if I could add you as a staff? Thanks!