Hey @brekila
You’re using Dawn theme (by default, clicking the search icon takes you to /search page).
If you want it to open a drawer instead (like the cart drawer), and also show live suggestions/recommendations, you’ll need to
Enable predictive search in Shopify
- Go to Online Store → Preferences.
- Make sure “Enable search suggestions” is checked (that enables Shopify’s predictive search API).
Create a search-drawer.liquid snippet
<div id="SearchDrawer" class="fixed inset-0 z-50 hidden">
<div class="absolute inset-0 bg-black bg-opacity-50"></div>
<div class="absolute top-0 right-0 w-full max-w-lg bg-white h-full shadow-xl overflow-y-auto">
<div class="p-4 flex justify-between items-center border-b">
<h2 class="text-lg font-semibold">Search</h2>
<button type="button" class="close-search text-gray-500 hover:text-black">âś•</button>
</div>
<div class="p-4">
<form action="{{ routes.search_url }}" method="get" role="search">
<input
type="search"
name="q"
id="SearchInput"
placeholder="Search products..."
class="w-full border px-3 py-2 rounded"
autocomplete="off"
>
</form>
</div>
<!-- Suggestions will load here -->
<div id="SearchResults" class="p-4 space-y-4"></div>
</div>
</div>
Add JavaScript to open/close drawer & fetch results
In theme.liquid (before ), add:
<script>
document.addEventListener('DOMContentLoaded', () => {
const searchToggle = document.querySelectorAll('[data-action="toggle-search"]');
const searchDrawer = document.getElementById('SearchDrawer');
const closeSearch = document.querySelector('.close-search');
const searchInput = document.getElementById('SearchInput');
const searchResults = document.getElementById('SearchResults');
// Open drawer
searchToggle.forEach(btn => {
btn.addEventListener('click', e => {
e.preventDefault();
searchDrawer.classList.remove('hidden');
searchInput.focus();
});
});
// Close drawer
closeSearch.addEventListener('click', () => {
searchDrawer.classList.add('hidden');
});
// Predictive search API
let timer;
searchInput.addEventListener('input', () => {
clearTimeout(timer);
const query = searchInput.value.trim();
if (query.length < 2) {
searchResults.innerHTML = '';
return;
}
timer = setTimeout(() => {
fetch(`/search/suggest.json?q=${query}&resources[type]=product,collection&page=1&limit=5`)
.then(res => res.json())
.then(data => {
let html = '';
if (data.resources.results.products.length > 0) {
html += `<h3 class="font-semibold mb-2">Products</h3>`;
data.resources.results.products.forEach(p => {
html += `
<div class="flex items-center space-x-3">
<img src="${p.image}" alt="${p.title}" class="w-12 h-12 object-cover rounded">
<a href="${p.url}" class="hover:underline">${p.title}</a>
</div>`;
});
}
if (data.resources.results.collections.length > 0) {
html += `<h3 class="font-semibold mt-4 mb-2">Collections</h3>`;
data.resources.results.collections.forEach(c => {
html += `<a href="${c.url}" class="block hover:underline">${c.title}</a>`;
});
}
searchResults.innerHTML = html || '<p>No results found.</p>';
});
}, 300);
});
});
</script>
Replace search icon link with toggle
In header.liquid, replace the search icon link with:
<a href="#" data-action="toggle-search" class="header__icon">
{% render 'icon-search' %}
</a>
Now when you click the search icon, the drawer opens on the homepage.
As you type, live suggestions & recommendations show up instantly.
If you want me to implement this for you, please feel free to reach out and check my past work here: https://rajatweb.dev/ – you’ll find my contact details in my portfolio.
Rajat | Shopify Expert