From 695f6a3391cd161fbe2b68b226be5262799d5934 Mon Sep 17 00:00:00 2001 From: Lightling Date: Thu, 30 May 2024 19:17:11 -0400 Subject: [PATCH] hide subtitles if they're not set --- libs/embeds/src/link.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libs/embeds/src/link.ts b/libs/embeds/src/link.ts index 60bf404..df50b02 100644 --- a/libs/embeds/src/link.ts +++ b/libs/embeds/src/link.ts @@ -91,22 +91,25 @@ export class LinkEmbed extends HTMLElement { } const _subtitle = ownerDocument.createElement('p') + if (!this.getAttribute('subtitle')) { + _subtitle.style.display = 'hidden' + } this._observers.subtitle = { element: _subtitle, observer: (oldVal, newVal) => { const { element } = this._observers.subtitle if (!!newVal) { element!.innerHTML = newVal - } else { - element!.style.display = 'hidden' + if (_subtitle.parentElement !== _textWrapper) { + _textWrapper.append(_subtitle) + } + } else if (_subtitle.parentElement === _textWrapper) { + _textWrapper.removeChild(_subtitle) } }, } - _textWrapper.append( - _title, - _subtitle, - ) + _textWrapper.append(_title) } attributeChangedCallback(name: LinkEmbedAttributes, oldVal: any, newVal: any) {