From a983d3a4a2350be7e98800a7a5ee4fa7f706b1b1 Mon Sep 17 00:00:00 2001 From: anish-work Date: Tue, 13 Aug 2024 17:45:07 +0530 Subject: [PATCH] fix: use target id to get the div --- src/components/shared/Buttons/buttons.scss | 2 +- src/lib.tsx | 1 - src/widgets/copilot/components/widget/index.tsx | 5 +++-- src/widgets/index.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/shared/Buttons/buttons.scss b/src/components/shared/Buttons/buttons.scss index e694839..7447045 100644 --- a/src/components/shared/Buttons/buttons.scss +++ b/src/components/shared/Buttons/buttons.scss @@ -45,7 +45,7 @@ button:disabled { border: 1px solid #eee; } -.button-text:active { +.button-text:active:not(:disabled) { background-color: #eee; color: #0d0d0d !important; } diff --git a/src/lib.tsx b/src/lib.tsx index 09cf9d8..3d09b11 100644 --- a/src/lib.tsx +++ b/src/lib.tsx @@ -24,7 +24,6 @@ class GooeyEmbedFactory { } const innerDiv = document.createElement("div"); innerDiv.style.display = "contents"; - innerDiv.className = "inner-div"; if(targetElem.children.length > 0) targetElem.removeChild(targetElem.children[0]); targetElem.appendChild(innerDiv); const root = renderCopilotChatWidget(innerDiv, config); diff --git a/src/widgets/copilot/components/widget/index.tsx b/src/widgets/copilot/components/widget/index.tsx index eeb3221..5050065 100644 --- a/src/widgets/copilot/components/widget/index.tsx +++ b/src/widgets/copilot/components/widget/index.tsx @@ -17,12 +17,13 @@ type CopilotWidgetType = { }; const CopilotWidget: FC = ({ isInline }) => { - const { isExpanded }: SystemContextType = useSystemContext(); + const { isExpanded, config }: SystemContextType = useSystemContext(); const { flushData, cancelApiCall }: any = useMessagesContext(); const handleEditClick = () => { cancelApiCall(); flushData(); - const shadowRoot = document.getElementById(isInline ? "inline" : "popup")?.getElementsByClassName("inner-div")[0]?.shadowRoot; + const shadowRoot = document.querySelector((config?.target || "") as string) + ?.firstElementChild?.shadowRoot; const ele = shadowRoot?.getElementById(CHAT_INPUT_ID); ele?.focus(); }; diff --git a/src/widgets/index.tsx b/src/widgets/index.tsx index 7938b95..f2a0df3 100644 --- a/src/widgets/index.tsx +++ b/src/widgets/index.tsx @@ -37,7 +37,7 @@ export function CopilotChatWidget({ config }: { config?: any }) { } export function renderCopilotChatWidget(elem: Element, config?: any) { - const shadow = elem.attachShadow({ mode: "open", delegatesFocus: true}); + const shadow = elem.attachShadow({ mode: "open", delegatesFocus: true }); const root = ReactDOM.createRoot(shadow); root.render(