-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Issue clearing input on key press #3492
Comments
This is because the cursor is still looking for a block after the action. You won't have this problem when you click on a button. Because the editor loses focus. Import ReactEditor value from slate-react. import { Editable, withReact, Slate, ReactEditor } from "slate-react"; Use the <Editable
placeholder="Write text and press enter to see error."
onKeyDown={e => {
if (e.key === "Enter") {
e.preventDefault();
ReactEditor.blur(editor);
setValue([
{
type: "paragraph",
children: [{ text: "" }]
}
]);
}
}}
/> |
Or it can import import { createEditor, Transforms, Editor } from "slate"; With the <Editable
placeholder="Write text and press enter to see error."
onKeyDown={e => {
if (e.key === "Enter") {
e.preventDefault();
Transforms.select(editor, Editor.start(editor, []));
setValue([
{
type: "paragraph",
children: [{ text: "" }]
}
]);
}
}}
/> |
Ah right that makes sense, thanks for the quick help and detailed explanation. |
Do you want to request a feature or report a bug?
Bug
What's the current behavior?
When clearing input on key press enter I get a slate error. Example in this sandbox
Slate: 0.57.1
Browser: Chrome
OS: Windows
I have tried the suggestions in #713 and #300
What's the expected behavior?
Should remove the input content, the same as the behavior of the button in the sandbox.
The text was updated successfully, but these errors were encountered: