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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
move focus logic to use-content-editable
Roman Pominov94a827b9f460
diff --git a/apps/designer/app/canvas/features/wrapper-component/text-editor/hooks/use-content-editable.tsx b/apps/designer/app/canvas/features/wrapper-component/text-editor/hooks/use-content-editable.tsxindex 1c5a59704c..7c8e1f9c7d 100644--- a/apps/designer/app/canvas/features/wrapper-component/text-editor/hooks/use-content-editable.tsx+++ b/apps/designer/app/canvas/features/wrapper-component/text-editor/hooks/use-content-editable.tsx@@ -1,5 +1,5 @@import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";-import { useCallback, useEffect } from "react";+import { useCallback, useEffect, useRef } from "react";type RefCallback = (rootElement: null | HTMLElement) => void;@@ -21,7 +21,14 @@ export const useContentEditable = ([editor]);+ const prevIsEditing = useRef(isEditing);useEffect(() => {+ const startedEditing = isEditing && prevIsEditing.current === false;+ prevIsEditing.current = isEditing;+ if (startedEditing) {+ editor.getRootElement()?.focus();+ }+if (isEditing === true) return;// Lets unset the root element when we are not editingeditor.setRootElement(null);diff --git a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsxindex e96d9546e1..5e39324f6d 100644--- a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx+++ b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx@@ -36,14 +36,7 @@ export const WrapperComponentDev = ({const refCallback = useCallback((element) => {- if (isEditing) {- editableRefCallback(element);-- // focus the element when starting to edit- if (element != null) {- element.focus();- }- }+ if (isEditing) editableRefCallback(element);// When entering text editing we unmount the instance element, so we need to update the reference, otherwise we have a detached element referenced and bounding box will be wrong.if (element !== null) setSelectedElement(element);