我正在使用 Facebook 的词法编辑器,但很难将编辑器设置为只读模式。
为了尝试它,我设置了 readyOnly
属性,但没有成功:
<ContentEditable readOnly={false} className="editor-input" />
这是完整的代码
<LexicalComposer initialConfig={editorConfig}>
<div className="editor-container">
<ToolbarPlugin />
<div className="editor-inner">
<RichTextPlugin
contentEditable={
<ContentEditable readOnly={true} className="editor-input" />
}
placeholder={<Placeholder />}
/>
<HistoryPlugin />
{/* <TreeViewPlugin /> */}
<AutoFocusPlugin />
<CodeHighlightPlugin />
<ListPlugin />
<LinkPlugin />
<AutoLinkPlugin />
<ListMaxIndentLevelPlugin maxDepth={7} />
<MarkdownShortcutPlugin transformers={TRANSFORMERS} />
</div>
</div>
<OnChangePlugin
onChange={onChange}
ignoreSelectionChange
ignoreHistoryMergeTagChange
/>
<TextLoader note={note} />
</LexicalComposer>
最佳答案
你可以通过这样的initialConfig来完成
const editorConfig = {
namespace: 'blahblah',
editable: false,
....
}
<LexicalComposer initialConfig={editorConfig}
关于lexicaljs - 如何将词法编辑器设置为只读模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74494777/