diff --git a/src/fontra/client/web-components/ui-accordion.js b/src/fontra/client/web-components/ui-accordion.js index 256cb4e1d..ddebc83e0 100644 --- a/src/fontra/client/web-components/ui-accordion.js +++ b/src/fontra/client/web-components/ui-accordion.js @@ -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); diff --git a/src/fontra/views/editor/panel-related-glyphs.js b/src/fontra/views/editor/panel-related-glyphs.js index 3f3871085..899befb6a 100644 --- a/src/fontra/views/editor/panel-related-glyphs.js +++ b/src/fontra/views/editor/panel-related-glyphs.js @@ -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)) { @@ -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; @@ -217,7 +217,6 @@ export default class RelatedGlyphPanel extends Panel { element.innerHTML = ""; } } - parent.hidden = hideAccordionItem; return !hideAccordionItem; } @@ -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);