Ability to disable Enter
#2948
-
How I can prevent line wrap on |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
If you just want to disable Enter, you can write a custom plugin and override the default behaviour of the Enter key: import { Extension } from "@tiptap/core";
const DisableEnter = Extension.create({
addKeyboardShortcuts() {
return {
Enter: () => true,
};
},
});
const editor = useEditor({
extensions: [
//...
DisableEnter
]
}) I think line-wrap will still happen. With a little bit of CSS magic you can disable that: .ProseMirror {
white-space: nowrap !important;
} This disables line-wrap for all of the editors in your app. You should set an id to the editor and use that here. <EditorContent editor={editor} id="my-editor" /> #my-editor {
white-space: nowrap !important;
} Worth mentioning that if you want to build a single-line editor, you can write a custom document that limits the editor to have only text content (no block nodes such as paragraphs, so enter effectively will do nothing): const TitleDocument = Document.extend({
content: "text*",
});
// single-line editor
const titleEditor = useEditor({
extensions: [ TitleDocument ],
}); You still need the CSS if you really want to visually keep it in one line. |
Beta Was this translation helpful? Give feedback.
-
I tried to use the extension with hotkey behavior reassign you describe, but it doesn't work. |
Beta Was this translation helpful? Give feedback.
-
I found the answer here: const PreventEnter = Extension.create({
addKeyboardShortcuts(this) {
return {
'Enter': () => true
}
},
}) Works as expected. Returned |
Beta Was this translation helpful? Give feedback.
If you just want to disable Enter, you can write a custom plugin and override the default behaviour of the Enter key:
I think line-wrap will still happen. With a little bit of CSS magic you can disable that:
This disables line-wrap for all of the editors in your app. You should set an id to the editor and use that here.