Skip to content

Commit

Permalink
Merge pull request #1871 from googlefonts/issue-1865-refactor-findPar…
Browse files Browse the repository at this point in the history
…entWithClass

Add method showHideAccordionItem to Accordion class instead of findParentWithClass
  • Loading branch information
justvanrossum authored Dec 18, 2024
2 parents f08c640 + 3780c1f commit 8fabc91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/fontra/client/web-components/ui-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ export class Accordion extends UnlitElement {
_toggleItem(itemElement) {
itemElement.classList.toggle("ui-accordion-item-closed");
}

showHideAccordionItem(item, onOff) {
let parent = item.content;
do {
parent = parent.parentElement;
} while (parent && !parent.classList.contains("ui-accordion-item"));

if (!parent) {
return;
}
parent.hidden = !onOff;
}
}

customElements.define("ui-accordion", Accordion);
11 changes: 1 addition & 10 deletions src/fontra/views/editor/panel-related-glyphs.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export default class RelatedGlyphPanel extends Panel {

for (const item of this.accordion.items) {
this._updateAccordionItem(item, glyphName, codePoint).then((hasResult) => {
this.accordion.showHideAccordionItem(item, hasResult);
results.push(hasResult);
if (results.length === this.accordion.items.length) {
if (!results.some((hasResult) => hasResult)) {
Expand All @@ -170,7 +171,6 @@ export default class RelatedGlyphPanel extends Panel {

async _updateAccordionItem(item, glyphName, codePoint) {
const element = item.content;
const parent = findParentWithClass(element, "ui-accordion-item");

element.innerHTML = "";
let hideAccordionItem = true;
Expand Down Expand Up @@ -217,7 +217,6 @@ export default class RelatedGlyphPanel extends Panel {
element.innerHTML = "";
}
}
parent.hidden = hideAccordionItem;
return !hideAccordionItem;
}

Expand Down Expand Up @@ -356,12 +355,4 @@ function addCharInfo(fontController, glyphNames) {
});
}

function findParentWithClass(element, parentClass) {
let parent = element;
do {
parent = parent.parentElement;
} while (parent && !parent.classList.contains(parentClass));
return parent;
}

customElements.define("panel-related-glyph", RelatedGlyphPanel);

0 comments on commit 8fabc91

Please sign in to comment.