最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Disable any user input using ReactQuill library - Stack Overflow

programmeradmin9浏览0评论

I'm trying to use ReactQuill just to show some rich text that I have, and therefore I don't want that it can receive any input or typing from the user. Reason, I have another library (ReactAce), and ReactQuill is causing a bug that when I type the 'delete' key, it made the ReactAce stops working...

Below you can see the example, that I am trying to disable the Quill instance.

quillRef = React.createRef();    

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

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

render () { 
    <ReactQuill
      readOnly
      value={info}
      ref={this.quillRef}
      modules={quillConfig}
    >
}

If you know some way to stop the ReactQuill to receive any input from the keyboard, I would be glad because I think that is causing the bug.

Thank you!

I'm trying to use ReactQuill just to show some rich text that I have, and therefore I don't want that it can receive any input or typing from the user. Reason, I have another library (ReactAce), and ReactQuill is causing a bug that when I type the 'delete' key, it made the ReactAce stops working...

Below you can see the example, that I am trying to disable the Quill instance.

quillRef = React.createRef();    

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

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

render () { 
    <ReactQuill
      readOnly
      value={info}
      ref={this.quillRef}
      modules={quillConfig}
    >
}

If you know some way to stop the ReactQuill to receive any input from the keyboard, I would be glad because I think that is causing the bug.

Thank you!

Share Improve this question edited Feb 22, 2019 at 7:43 Johnny Willemsen 3,0021 gold badge16 silver badges17 bronze badges asked Feb 21, 2019 at 19:30 Otavio AugustoOtavio Augusto 3381 gold badge3 silver badges10 bronze badges 1
  • I don't really know what was problem that was causing the bug, but I took off the inner div and problem was solved. I saw this issue at the repo: github./zenoamaro/react-quill/issues/282 and figured out that I could do the same thing. – Otavio Augusto Commented Feb 21, 2019 at 20:10
Add a ment  | 

3 Answers 3

Reset to default 12

in React Quill 1.3.5, you can add the readOnly prop as true. It will disable your editor like input tag when disabled.

You can just use the readOnly property as the following:

<ReactQuilltheme="snow" readOnly={true} />

Of course you need to make it dynamic by using useState()

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

You can add event listener on "keydown" and ref to ReactQuill

this.quillRef.current.addEventListener('keydown', null);
发布评论

评论列表(0)

  1. 暂无评论