Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Autofocus doesn't seem to work on the Yoota Editor #445

Open
aidan-code opened this issue Feb 3, 2025 · 2 comments
Open

The Autofocus doesn't seem to work on the Yoota Editor #445

aidan-code opened this issue Feb 3, 2025 · 2 comments

Comments

@aidan-code
Copy link

When ever my page mounts the Editor is not focused on. It'd only focus if i click on it.
I'm not sure if this is a bug. but all I've tried to get the editor to auto focus didn't work even after adding the autofocus prop.

<YooptaEditor
placeholder="Start creating"
plugins={plugins}
editor={editor}
value={value}
onChange={onChange}
tools={TOOLS}
style={{ width: "100%" }}
className="text-small-xl border w-full rounded p-2 cursor-text"
marks={MARKS}
autoFocus
/>

btw great editor
guys😌

@aidan-code aidan-code changed the title The Autofocus doesn't seem to work The Autofocus doesn't seem to work on the Yoota Editor Feb 4, 2025
@acidio
Copy link

acidio commented Feb 7, 2025

From what I noticed it only works when there is already a block in the editor, if you have an empty editor than it doesn't focus.
I believe it's also important to have the initial focus when the editor is empty so the user can start typing right away.

You can workaround that setting an empty paragraph as default data to start the editor.
Maybe this is even something that could become the fix for the issue, having an empty paragraph as default when default data is empty. (🤔?)

I'm new to the lib so it would be nice to have some input from others on it.

@Keneficka
Copy link

@acidio you can also use insertBlock to add a paragraph in a useEffect and focus on it. Or maybe that's what you meant.

useEffect(() => { editor.insertBlock('Paragraph',{ at: 1, focus: true }); }, [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants