Prevent <details>
from closing on cart update
#103
-
How do you prevent a I am using a How do you keep the details open? I've tried |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hi @thagxt , If you still want to use the details tag, I'll send a short js-script for Liquid Ajax Cart a bit later that will keep the open/close state of the details element. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the suggestion! Yes, please, that would help. I'd like to stick to using the |
Beta Was this translation helpful? Give feedback.
-
Add this code somewhere after const cartDetailsOpen = {};
function cartDetailsInit() {
document.querySelectorAll('[data-ajax-cart-section] [data-ajax-cart-details]').forEach($details => {
const key = $details.getAttribute('data-ajax-cart-details');
if (!key) return;
cartDetailsOpen[key] = $details.hasAttribute('open');
$details.addEventListener('toggle', event => {
cartDetailsOpen[key] = event.target.open;
});
});
}
cartDetailsInit();
document.addEventListener('liquid-ajax-cart:request-end', event => {
document.querySelectorAll('[data-ajax-cart-section] [data-ajax-cart-details]').forEach($details => {
const key = $details.getAttribute('data-ajax-cart-details');
if (!key) return;
$details.open = cartDetailsOpen[key];
});
cartDetailsInit();
}); Then add <details data-ajax-cart-details="unique-identifier-1">
<summary>Title</summary>
Content
</details> Let me know if that works. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much @EvgeniyMukhamedjanov, that works perfectly! :) This would be great to have as a function within the core of 'liquid-ajax-cart', not just for details but also for other HTML elements in general. |
Beta Was this translation helpful? Give feedback.
Add this code somewhere after
import liquid-ajax-cart
: