Skip to content

Commit

Permalink
fix content toggle not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-shafi committed Jun 15, 2024
1 parent 8bf9b9d commit 3f0462a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion dist/blocks.build.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blocks.style.build.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ That's it. You're done!
= 3.2.0 =

* FIX: Aspect Ratio not working on uploaded video in advanced video block.
* FIX: Content Toggle not working properly.

= 3.1.9 =

Expand Down
21 changes: 10 additions & 11 deletions src/blocks/content-toggle/front.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ var togglePanel = function togglePanel(target) {
panelContent.style.height = "";
}
}, 20);
panelContent.addEventListener("transitionend", function () {
panelContent.classList.remove("ub-toggle-transition");
panelContent.setAttribute("aria-expanded", panelContent.offsetHeight !== 0);
if (panelContent.offsetHeight === 0) {
panelContent.classList.add("ub-hide");
} else {
panelContent.removeAttribute("style");
}
panelContent.classList.remove("ub-hiding");
});
panelContent.querySelectorAll(".wp-block-embed iframe").forEach(function (embeddedContent) {
embeddedContent.style.removeProperty("width");
embeddedContent.style.removeProperty("height");
Expand Down Expand Up @@ -113,17 +123,6 @@ var attachTogglePanelEvents = function attachTogglePanelEvents() {
e.stopImmediatePropagation();
togglePanel(instance);
});
panelContent.addEventListener("transitionend", function () {
panelContent.classList.remove("ub-toggle-transition");
panelContent.setAttribute("aria-expanded", panelContent.offsetHeight !== 0);
if (panelContent.offsetHeight === 0) {
panelContent.classList.add("ub-hide");
} else {
panelContent.removeAttribute("style");
}
panelContent.classList.remove("ub-hiding");
});
panelContent.removeAttribute("style");
});
if (parentIsHidden) {
toggleContainer.parentElement.style.display = "none";
Expand Down
31 changes: 13 additions & 18 deletions src/blocks/content-toggle/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ const togglePanel = (target) => {
}
}, 20);

panelContent.addEventListener("transitionend", () => {
panelContent.classList.remove("ub-toggle-transition");
panelContent.setAttribute("aria-expanded", panelContent.offsetHeight !== 0);

if (panelContent.offsetHeight === 0) {
panelContent.classList.add("ub-hide");
} else {
panelContent.removeAttribute("style");
}

panelContent.classList.remove("ub-hiding");
});

panelContent
.querySelectorAll(".wp-block-embed iframe")
.forEach((embeddedContent) => {
Expand Down Expand Up @@ -168,24 +181,6 @@ const attachTogglePanelEvents = () => {
e.stopImmediatePropagation();
togglePanel(instance);
});

panelContent.addEventListener("transitionend", () => {
panelContent.classList.remove("ub-toggle-transition");
panelContent.setAttribute(
"aria-expanded",
panelContent.offsetHeight !== 0,
);

if (panelContent.offsetHeight === 0) {
panelContent.classList.add("ub-hide");
} else {
panelContent.removeAttribute("style");
}

panelContent.classList.remove("ub-hiding");
});

panelContent.removeAttribute("style");
});

if (parentIsHidden) {
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/content-toggle/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/blocks/content-toggle/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
}

.wp-block-ub-content-toggle-accordion {
.ub-content-initialized {
opacity: 0;
position: absolute;
}
position: relative;
border: 1px solid lightsalmon;
margin-bottom: 10px;
Expand Down

0 comments on commit 3f0462a

Please sign in to comment.