Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search customer is not being moved to product details page #665

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions packages/theme/components/Header/SearchBar/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<script>
import { SfButton, SfSearchBar } from '@storefront-ui/vue';
import { defineComponent, ref } from '@nuxtjs/composition-api';
import { clickOutside } from '@storefront-ui/vue/src/utilities/directives/click-outside/click-outside-directive.js';
import { clickOutside } from '~/utilities/directives/click-outside/click-outside-directive.js';
import SvgImage from '~/components/General/SvgImage.vue';

import debounce from 'lodash.debounce';
Expand All @@ -60,6 +60,7 @@ import {
useCategorySearch,
useFacet,
} from '@vue-storefront/magento';
import { watch, useRoute } from '@nuxtjs/composition-api';

export default defineComponent({
name: 'SearchBar',
Expand All @@ -84,6 +85,8 @@ export default defineComponent({
const isSearchOpen = ref(false);
const result = ref(null);

const route = useRoute()

const {
result: searchResult,
search: productsSearch,
Expand Down Expand Up @@ -123,9 +126,17 @@ export default defineComponent({
}
};

const closeSearch = () => {
hideSearch();
term.value = '';
const closeSearch = (event) => {
if (document) {
const searchResultsEl = document.getElementsByClassName('search');
if (!searchResultsEl[0].contains(event.target)) {
hideSearch();
term.value = '';
}
} else {
hideSearch();
term.value = '';
}
};

const handleSearch = debounce(async (paramValue) => {
Expand All @@ -149,6 +160,11 @@ export default defineComponent({
emit('SearchBar:result', result.value);
}, 1000);

watch(route, () => {
hideSearch();
term.value = '';
});

return {
closeSearch,
showSearch,
Expand All @@ -162,3 +178,11 @@ export default defineComponent({
});

</script>

<style lang="scss" scoped>
.sf-search-bar__button {
position: relative;
right: 20px;
bottom: 0;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const clickOutside = {
bind(el, binding) {
binding.name = "click-outside";
const closeHandler = binding.value;
el._outsideClickHandler = function (event) {
if (!el.contains(event.target)) {
event.stopPropagation();
closeHandler(event, el);
}
};
document.addEventListener("mousedown", el._outsideClickHandler);
document.addEventListener("touchstart", el._outsideClickHandler);
},
unbind(el) {
document.removeEventListener("mousedown", el._outsideClickHandler);
document.removeEventListener("touchstart", el._outsideClickHandler);
el._outsideClickHandler = null;
},
};