Skip to content

Prevent <details> from closing on cart update #103

Discussion options

You must be logged in to vote

Add this code somewhere after import liquid-ajax-cart:

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.getAt…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by thagxt
Comment options

You must be logged in to vote
1 reply
@EvgeniyMukhamedjanov
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #102 on July 06, 2024 18:08.