Skip to content

Product selector click is not working fully #196

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

Merged
merged 1 commit into from
Mar 28, 2025
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
12 changes: 11 additions & 1 deletion assets/css/v2/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ atomic-search-layout atomic-layout-section[section="search"] {
border: none;
font-size: 1.25rem;
width: 100%;
padding: 0.5rem;
padding: 0.5rem 0.5rem 0.5rem 1rem; /* 1rem to vertically align with searchbar text */
cursor: pointer;
}

Expand All @@ -508,6 +508,16 @@ atomic-search-layout atomic-layout-section[section="search"] {
box-shadow: 3px 3px 0px var(--color-shadow);
}

button:has(~ .product-selector[style*="block"])
> .product-selector-button-icon {
transition: transform 0.25s ease-in-out;
transform: rotate(180deg);
}

button:has(~ .product-selector[style*="none"]) > .product-selector-button-icon {
transition: transform 0.25s ease-in-out;
transform: rotate(0deg);
}
.product-selector p {
font-size: 0.75rem;
color: var(--color-product-title);
Expand Down
11 changes: 5 additions & 6 deletions assets/js/product-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ document.addEventListener('DOMContentLoaded', () => {
'product-selector-button'
);

if (productSelectorButton === null || productSelectorButton == null) {
if (productSelectorButton === null || productSelectorContent == null) {
return;
}

productSelectorButton.addEventListener('click', () => {
/* Logic for hiding/showing ONLY when the button is clicked */
if (productSelectorContent.style.display === 'block') {
productSelectorContent.style.display = 'none';
productSelectorButton.classList.remove('remove-bottom-radius');
Expand All @@ -19,12 +20,10 @@ document.addEventListener('DOMContentLoaded', () => {
});

window.addEventListener('click', (event) => {
if (
!event.target.matches('#product-selector-button') &&
!event.target.matches('#product-selector-button-icon')
) {
/* Greedy Logic to hide the product selector when something other than the button is clicked. Assumes everything has an id containing "product-selector" */
if (!event.target.id.includes('product-selector')) {
productSelectorContent.style.display = 'none';
productSelectorButton.classList.remove('remove-bottom-radius');
}
productSelectorButton.classList.remove('remove-bottom-radius');
});
});
16 changes: 8 additions & 8 deletions layouts/partials/sidebar-v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

<button class="product-selector-button" id="product-selector-button">
{{/* product name and selector */}}
<div class="product-name">{{ $productName }}</div>
<div class="product-selector-button-icon">
<svg width="8" height="14" viewBox="0 0 8 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1 13L7 7L0.999999 1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<div class="product-selector-name" id="product-selector-name">{{ $productName }}</div>
<div class="product-selector-button-icon" id="product-selector-button-icon">
<svg width="8" height="14" viewBox="0 0 8 14" fill="none" xmlns="http://www.w3.org/2000/svg" id="product-selector-chevron-icon">
<path d="M1 13L7 7L0.999999 1" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" id="product-selector-chevron-icon"/>
</svg>
</div>
</button>
Expand All @@ -41,11 +41,11 @@
{{ $type := . }}
{{ $products := index $groupedProducts $type }}
<div class="product-selector-content" id="product-selector-content">
<p>{{ $type | humanize | title | upper }}</p>
<ul>
<p id="product-selector-content-product-group-name">{{ $type | humanize | title | upper }}</p>
<ul id="product-selector-content-product-container">
{{ range $products }}
<li>
<a href="{{ .url }}">{{ .title }}</a>
<li id="product-selector-content-product-name">
<a id="product-selector-content-product-link" href="{{ .url }}">{{ .title }}</a>
</li>
{{ end }}
</ul>
Expand Down
Loading