Slate: can't programmatically focus the editor anymore...

Created on 19 Dec 2019  路  6Comments  路  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

feature

What's the current behavior?

There's no longer a way to give programmatically focus to the content-editable element.
In slate 0.4x it was possibile to attach a ref to the <Editor> component. This is no longer the case because <Editable> is a stateless component

Slate: 0.57.0
Browser: all
OS: all

What's the expected behavior?

It should be possible to give focus programmatically to the editor

Most helpful comment

Is this documented anywhere?

All 6 comments

Isn't ReactEditor.focus function does what you want to achieve?

@Killavus no idea because it's basically undocumented and I didn't know it existed. I'll try it.

@Killavus yep it works, thanks!

Is this documented anywhere?

@MarkPare I found that you can import ReactEditor from slate-react and it has a focus method. Here is how you can use it.

import { ReactEditor } from 'slate-react';
ReactEditor.focus(editor);

With editor being an instance of your editor. You can get it from createEditor() or useSlate() depending on where do you need it.

This really needs to be documented...

Was this page helpful?
0 / 5 - 0 ratings