Skip to content

Commit

Permalink
update accordion.
Browse files Browse the repository at this point in the history
  • Loading branch information
wildone committed Aug 8, 2024
1 parent e078138 commit 6d9d05d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion blocks/accordion-item/accordion-item.css

This file was deleted.

Empty file.
10 changes: 10 additions & 0 deletions blocks/accordion/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
* https://www.hlx.live/developer/block-collection/accordion
*/

function hasWrapper(el) {
return !!el.firstElementChild && window.getComputedStyle(el.firstElementChild).display === 'block';
}

export default function decorate(block) {
[...block.children].forEach((row) => {
// decorate accordion item label
const label = row.children[0];
const summary = document.createElement('summary');
summary.className = 'accordion-item-label';
summary.append(...label.childNodes);
if (!hasWrapper(summary)) {
summary.innerHTML = `<p>${summary.innerHTML}</p>`;
}
// decorate accordion item body
const body = row.children[1];
body.className = 'accordion-item-body';
if (!hasWrapper(body)) {
body.innerHTML = `<p>${body.innerHTML}</p>`;
}
// decorate accordion item
const details = document.createElement('details');
details.className = 'accordion-item';
Expand Down

0 comments on commit 6d9d05d

Please sign in to comment.