From e68d8f5f18d0463273229e611d845470658d2772 Mon Sep 17 00:00:00 2001
From: ubermanu <e.vodor@gmail.com>
Date: Thu, 18 Mar 2021 13:37:10 +0100
Subject: [PATCH] bugfix: fix position in shadowRoot

---
 src/plugins/sib-reactions.js | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/plugins/sib-reactions.js b/src/plugins/sib-reactions.js
index e20ae3b..a2c2092 100644
--- a/src/plugins/sib-reactions.js
+++ b/src/plugins/sib-reactions.js
@@ -266,6 +266,17 @@ converse.plugins.add('sib-reactions', {
         let rectTop = tr.top + window.pageYOffset - docEl.clientTop;
         let rectLeft = tr.left + window.pageXOffset - docEl.clientLeft;
 
+        // Fix the position if contained in a shadowRoot
+        // TODO: Should iterate through all the parent instances
+        const root = _converse.root;
+        if (root.nodeType === 11) {
+          const rcr = root.getRootNode().host?.getBoundingClientRect();
+          if (rcr) {
+            rectLeft -= rcr.left;
+            rectTop -= rcr.top;
+          }
+        }
+
         picker.style.position = 'fixed';
         picker.style.zIndex = '999';
         picker.style.margin = '10px';
@@ -313,6 +324,8 @@ converse.plugins.add('sib-reactions', {
       },
     };
 
+    window._converse = _converse;
+
     // Apply message mixin
     const Message = _converse.api.elements.registry['converse-chat-message'];
     const _renderMessageText = Message.prototype.renderMessageText;
-- 
GitLab