Shopify themes, liquid, logos, and UX
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
Search appears ⬆️
Supposingly If I click in the area circled area the search disappears, I want it to stay as it is and also
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!
Solved! Go to the solution
This is an accepted solution.
Hi @birinoc ,
Here’s how you can fix both issues with your live search functionality:
The issue occurs because the dropdown likely closes when a click event is detected outside the search area. To resolve this:
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');
}
});
The issue arises because only specific elements (like product name or image) are linked to the product page. To make the entire row clickable:
<div class="search-result-item">
<a href="{{ product.url }}" class="search-result-link">
<div class="search-result-content">
<img src="{{ product.image | img_url: 'small' }}" alt="{{ product.title }}">
<span>{{ product.title }}</span>
</div>
</a>
</div>
Ensure the clickable area spans the entire row:
.search-result-link {
display: flex;
align-items: center;
padding: 10px;
text-decoration: none;
width: 100%;
}
.search-result-link:hover {
background-color: #f8f8f8; /* Optional hover effect */
}
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.
Thanks & Regards
Akshay Bhatt
This is an accepted solution.
Hi @birinoc ,
Here’s how you can fix both issues with your live search functionality:
The issue occurs because the dropdown likely closes when a click event is detected outside the search area. To resolve this:
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');
}
});
The issue arises because only specific elements (like product name or image) are linked to the product page. To make the entire row clickable:
<div class="search-result-item">
<a href="{{ product.url }}" class="search-result-link">
<div class="search-result-content">
<img src="{{ product.image | img_url: 'small' }}" alt="{{ product.title }}">
<span>{{ product.title }}</span>
</div>
</a>
</div>
Ensure the clickable area spans the entire row:
.search-result-link {
display: flex;
align-items: center;
padding: 10px;
text-decoration: none;
width: 100%;
}
.search-result-link:hover {
background-color: #f8f8f8; /* Optional hover effect */
}
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.
Thanks & Regards
Akshay Bhatt
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!
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024