Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Fix Toolbar dissapears in the tooltip (#2061)

Ivan Starkov7d635c4940fa
diff --git a/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx b/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
index 7fa1445d2f..25d2fc90bf 100644
--- a/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
+++ b/apps/builder/app/canvas/features/text-editor/toolbar-connector.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useRef } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import {
type RangeSelection,
type TextNode,
@@ -91,14 +91,14 @@ const getSelectionClienRect = () => {
return domRange.getBoundingClientRect();
};
-export const ToolbarConnectorPlugin = ({
+const ToolbarConnectorPluginInternal = ({
onSelectNode,
}: {
onSelectNode: (nodeKey: string) => void;
}) => {
const [editor] = useLexicalComposerContext();
- const isMouseDownRef = useRef(false);
+ const isMouseDownRef = useRef(false);
// control toolbar state on data or selection updates
const updateToolbar = useCallback(() => {
const selection = $getSelection();
@@ -275,3 +275,32 @@ export const ToolbarConnectorPlugin = ({
return null;
};
+
+export const ToolbarConnectorPlugin = ({
+ onSelectNode,
+}: {
+ onSelectNode: (nodeKey: string) => void;
+}) => {
+ const [editor] = useLexicalComposerContext();
+ const [hasRootElement, setHasRootElement] = useState(false);
+
+ useEffect(() => {
+ const rootElement = editor.getRootElement();
+
+ /**
+ * We don't set root element for VisuallyHidden nodes
+ * and need to prevent Toolbar events in this case
+ */
+ if (rootElement === null) {
+ return;
+ }
+
+ setHasRootElement(true);
+ }, [editor]);
+
+ if (hasRootElement === false) {
+ return null;
+ }
+
+ return <ToolbarConnectorPluginInternal onSelectNode={onSelectNode} />;
+};