Drawer Menu Won't Close After Clicking Anchor Link - Dawn Theme

Solved

Drawer Menu Won't Close After Clicking Anchor Link - Dawn Theme

Rolling
Visitor
2 0 1

Hey guys,

 

The Drawer Menu Won't Close After Clicking Anchor Links. It makes them kind of useless. Any idea how to solve this problem? I'm using the Dawn Theme.

 

BentleyRolling.com

 

Thank you in advance!

Accepted Solution (1)

tim
Shopify Partner
3997 416 1475

This is an accepted solution.

In your "Footer", add a "Custom liquid" section and paste this code:

 

<script>
  document.querySelector('header-drawer').addEventListener('click', e => {
    if (e.target.tagName !== 'A') return;
    let url = new URL (e.target.href);
    if (url.pathname != location.pathname) return;
    if (!document.querySelector(url.hash)) return;
    let closeButton = e.currentTarget.querySelector('summary');
    if (closeButton) closeButton.dispatchEvent( new Event('click'));
  });
</script>

 

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com

View solution in original post

Replies 3 (3)

thirtycoders
Shopify Partner
135 21 28

Hello @Rolling,

 

Could you grant me access to your store? I'd be glad to assist you.

Thanks!

Thirtycoders || Shopify Partner
Found my response useful? Show your appreciation with a Like!
Did your query get resolved? Mark it as an Accepted Solution.
For additional discussions, reach out via: Email ID: thirtycoders@gmail.com

tim
Shopify Partner
3997 416 1475

This is an accepted solution.

In your "Footer", add a "Custom liquid" section and paste this code:

 

<script>
  document.querySelector('header-drawer').addEventListener('click', e => {
    if (e.target.tagName !== 'A') return;
    let url = new URL (e.target.href);
    if (url.pathname != location.pathname) return;
    if (!document.querySelector(url.hash)) return;
    let closeButton = e.currentTarget.querySelector('summary');
    if (closeButton) closeButton.dispatchEvent( new Event('click'));
  });
</script>

 

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
Rolling
Visitor
2 0 1

This is the best solution. Thank you for your help. Super easy without editing code. Anyone looking for the real solution to this problem, this is it!