All things Shopify and commerce
Theme Details- Theme: Dawn (OS 2.0)- Using Alpine.js for interactions- Predictive Search feature
// assets/predictive-search.js
Alpine.data('PredictiveSearch', (resources) => ({
resultsHTML: null,
trimmedQuery: '',
loading: false,
selectedElement: null,
onKeydown() {
if (this.$event.code === 'Enter') {
const form = this.$el.closest('form');
if (form && this.trimmedQuery.length > 0) {
// Prevent default behaviors
this.$event.preventDefault();
this.$event.stopPropagation();
// Get the form action and query
const action = form.action;
const query = this.trimmedQuery;
// Just do a normal form submission
form.submit();
}
}
},
init() {
this.$watch('trimmedQuery', (value) => {
if (!value.length) {
this.closeResults();
this.resultsHTML = null;
} else {
this.openResults();
this.getSearchResults();
}
});
}
}));
Visual Flow
<!-- snippets/header-search.liquid --> <div x-data="{ searchOpen: false }" x-init="initTeleport($root); $store.modals.register('search', 'rightDrawer');" class="hidden lg:block" > <template data-should-teleport="#right-drawer"> <div x-show="$store.modals.rightDrawer.contents === 'search'"> <!-- Search form here --> </div> </template> </div> <!-- sections/predictive-search.liquid --> {%- if predictive_search.performed -%} <div id="predictive-search-results"
data-search-results class="predictive-search-results"> <!-- Results markup --> </div> {%- endif -%}
Expected Behavior
When pressing Enter:
1. Form should submit
2. Navigate to search results page
3. Drawer should close only after navigation starts
Current Behavior
When pressing Enter:
1. Drawer immediately closes
2. No form submission occurs
3. No navigation happens
4. User stays on current page
This happens on the desktop version
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025