使用 ReactQuill 库禁用任何用户输入

Ota*_*sto 1 javascript reactjs quill react-ace

我试图使用 ReactQuill 只是为了显示我拥有的一些富文本,因此我不希望它可以接收用户的任何输入或键入。原因,我有另一个库(ReactAce),ReactQuill 导致了一个错误,当我键入“删除”键时,它使 ReactAce 停止工作......

您可以在下面看到我正在尝试禁用 Quill 实例的示例。

quillRef = React.createRef();    

componentDidMount = () => {
  console.log(this.quillRef.current.editor);

  this.quillRef.current.editor.enable(false);   // undefined
};

render () { 
    <ReactQuill
      readOnly
      value={info}
      ref={this.quillRef}
      modules={quillConfig}
    >
}
Run Code Online (Sandbox Code Playgroud)

如果您知道某种方法可以阻止 ReactQuill 接收来自键盘的任何输入,我会很高兴,因为我认为这是导致该错误的原因。

谢谢你!

小智 11

在 React Quill 1.3.5 中,您可以将 readOnly 属性添加为 true。禁用时,它将像输入标签一样禁用您的编辑器。


小智 5

readOnly您可以按如下方式使用该属性:

<ReactQuilltheme="snow" readOnly={true} />
Run Code Online (Sandbox Code Playgroud)

当然,您需要使用使其动态化useState()

const [disabled, setDisabled] = useState(true);
    
return (
    <ReactQuilltheme="snow" readOnly={disabled} />
)
Run Code Online (Sandbox Code Playgroud)