Skip to content

Commit

Permalink
Added check for ascendent links to close menu when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
raulberari committed May 29, 2023
1 parent 49c46ee commit cb4290c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teleporthq/teleport-custom-scripts",
"version": "0.0.21",
"version": "0.0.22",
"main": "src/index.js",
"private": false,
"description": "Custom scripts ready to be injected in to the playground",
Expand Down
15 changes: 12 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,27 @@
if (!event) {
return;
}
if (!event.target.href) {

// check for links in ascendent elements
let currentElement = event.target;

while (currentElement !== document.body && !currentElement.href) {
currentElement = currentElement.parentNode;
}

if (!currentElement.href) {
return;
}

if (!mobileMenu) {
return;
}

if (event.target.href) {
if (currentElement.href) {
document.body.style.overflow = bodyOverflow;
}

if (event.target.pathname === window.location.pathname) {
if (currentElement.pathname === window.location.pathname) {
mobileMenu.classList.remove("teleport-show");
mobileMenu.classList.remove("thq-show");
mobileMenu.classList.remove("thq-translate-to-default");
Expand Down

0 comments on commit cb4290c

Please sign in to comment.