fix(tooltip): support reconnecting tooltip arrow inside other overlays

This commit is contained in:
Joren Broekema 2020-04-02 09:33:31 +02:00 committed by Thomas Allmer
parent afd5ac96cc
commit 78a8554019

View file

@ -12,12 +12,9 @@ export class LionTooltip extends OverlayMixin(LitElement) {
connectedCallback() { connectedCallback() {
super.connectedCallback(); super.connectedCallback();
this._overlayContentNode.setAttribute('role', 'tooltip'); this._overlayContentNode.setAttribute('role', 'tooltip');
} // Schedule setting up the arrow element so that it works both on firstUpdated
// and when the tooltip is moved in the DOM (disconnected + reconnected)
firstUpdated(...args) { this.updateComplete.then(() => this.__setupArrowElement());
super.firstUpdated(...args);
this.__setupArrowElement();
} }
render() { render() {
@ -30,7 +27,7 @@ export class LionTooltip extends OverlayMixin(LitElement) {
} }
__setupArrowElement() { __setupArrowElement() {
this.__arrowElement = this.querySelector('[slot=arrow]'); this.__arrowElement = Array.from(this.children).find(child => child.slot === 'arrow');
if (!this.__arrowElement) { if (!this.__arrowElement) {
return; return;
} }