I´m trying to create a "one line" message component based on Lexical, but i´m unable to prevent the enter key to create a new paragraph.
Any ideas how to accomplish this?
I´ve added styling with
white-space: nowrap!important;
resize: none;
and i´ve tried to MaxLengthPlugin ( which works but if enter in there it creates two lines)
also tried to add
<EditorWrapper ref={onRef} data-testid="editor"
onKeyDown={event => {
if (event.key === 'Enter') {
event.preventDefault();
}
}}>
I was expecting this to prevent the new paragraph with enter, but still adds a new paragraph in the editor.
LineBreakNode
helped to stop the users from adding</br>
but I also had to register to theRootNode
to prevent new paragraphs.mergeRegister( editor.registerNodeTransform(RootNode, (rootNode: RootNode) => { if (rootNode.getChildrenSize() <= 1) return; rootNode.getLastChild()?.remove(); }), editor.registerNodeTransform(LineBreakNode, (node) => { node.remove(); }), )
– Erbil