diff --git a/.changeset/silver-pugs-share.md b/.changeset/silver-pugs-share.md new file mode 100644 index 000000000..397d9a8c0 --- /dev/null +++ b/.changeset/silver-pugs-share.md @@ -0,0 +1,5 @@ +--- +'@ithaka/pharos': patch +--- + +Fix positioning of coach mark react component diff --git a/packages/pharos/src/components/coach-mark/pharos-coach-mark.ts b/packages/pharos/src/components/coach-mark/pharos-coach-mark.ts index 7912a38fc..47d98afe2 100644 --- a/packages/pharos/src/components/coach-mark/pharos-coach-mark.ts +++ b/packages/pharos/src/components/coach-mark/pharos-coach-mark.ts @@ -88,7 +88,8 @@ export class PharosCoachMark extends ScopedRegistryMixin(PharosElement) { override connectedCallback() { super.connectedCallback(); - this.setOffset(); + + autoUpdate(document.documentElement, this, () => this.requestUpdate()); } private setOffset() { @@ -96,22 +97,21 @@ export class PharosCoachMark extends ScopedRegistryMixin(PharosElement) { const targetElement: Element | null = document.querySelector(`[data-coach-mark="${id}"]`); if (!targetElement) return; - this._cleanup = autoUpdate(targetElement, this, () => - computePosition(targetElement, this, { - placement: this.alignment === 'center' ? this.side : `${this.side}-${this.alignment}`, - middleware: [flip(), offset(20)], - }).then(({ x, y, placement }) => { - Object.assign(this.style, { - left: `${x}px`, - top: `${y}px`, - }); - this._computedSide = placement.toString().split('-')[0]; // Removes -start or -end from final placement - this.requestUpdate(); - }) - ); + computePosition(targetElement, this, { + placement: this.alignment === 'center' ? this.side : `${this.side}-${this.alignment}`, + middleware: [flip(), offset(20)], + }).then(({ x, y, placement }) => { + Object.assign(this.style, { + left: `${x}px`, + top: `${y}px`, + }); + this._computedSide = placement.toString().split('-')[0]; // Removes -start or -end from final placement + }); } protected override render(): TemplateResult { + this.setOffset(); + return html`