mdx-editor / editor

A rich text editor React component for markdown
https://mdxeditor.dev
MIT License
1.63k stars 131 forks source link

[BUG] Cannot focus() if editor is initialized empty #446

Closed braincore closed 2 months ago

braincore commented 2 months ago

If you want to ask for support or request features, sponsor the project and contact me over email.

Describe the bug If an editor is initialized with prop markdown="", then a call editor method focus() will fail to focus the editor.

Reproduction Sandbox: Simply click "Test focus"

Expected behavior Editor should be brought to focus with blinking cursor at start index.

Additional context This issue came up in the context of calling "focus()" from a mobile-web interface to bring up the virtual keyboard.

braincore commented 2 months ago

As a workaround, setMarkdown() can be called prior to calling focus(). However, setMarkdown() must have contents (at least temporarily)! To avoid any visual artifacts, one can do the following:

mdxEditorRef.current.setMarkdown("  ");
mdxEditorRef.current.setMarkdown("");