keep the focus at end on initial load

This commit is contained in:
Ajay Bura 2026-08-16 12:22:29 +05:30
commit c3e508a8f9

View file

@ -5,10 +5,11 @@ import React, {
ReactNode,
forwardRef,
useCallback,
useEffect,
useState,
} from 'react';
import { Box, Scroll, Text } from 'folds';
import { Descendant, Editor, createEditor } from 'slate';
import { Descendant, Editor, Transforms, createEditor } from 'slate';
import {
Slate,
Editable,
@ -89,6 +90,12 @@ export const CustomEditor = forwardRef<HTMLDivElement, CustomEditorProps>(
},
]);
useEffect(() => {
if (!initialValue?.length) return;
Transforms.select(editor, Editor.end(editor, []));
}, [editor, initialValue]);
const renderElement = useCallback(
(props: RenderElementProps) => <RenderElement {...props} />,
[]