How to allow only one node in editor (and it has to be a Heading Node) #3819
Unanswered
nickschinestzki
asked this question in
Q&A
Replies: 2 comments 6 replies
-
|
What if you just save what an empty Header node would look like e.g. const initialHeading = {
root: {
"children": [
{
"children": [],
"direction": null,
"format": "",
"indent": 0,
"type": "heading",
"version": 1,
"tag": "h1"
}
],
"direction": null,
"format": "",
"indent": 0,
"type": "root",
"version": 1
}
}and use this for the initial value <LexicalComposer
initialConfig={{
...,
editorState: initialHeading
}}
/>And then restrict adding more nodes? |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
Firstly, the node transform solution you posted should in theory work. Can you maybe create a repro on codesandbox? Also, you could also make a custom ParagraphNode that essentially is a HeadNode, use the node replacement API to replace ParagraphNode with it? You will still need the node transform to not permit line breaks. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Similarly to this issue: #3675
I want to have a single line editor that has only one Heading Node and nothing more (not even line breaks). I don't know how can I achieve this. I have tried replacing the Paragraph Node with a Heading Node in the initial config of the editor, but an error accused me that that was wrong.
I've also tried using Node Transforms, but I got some errors. This is what I tried:
And this is giving me this error:

So what I'm doing wrong about these Node Transforms?
Beta Was this translation helpful? Give feedback.
All reactions