【问题标题】:react-quill onBlur not workingreact-quill onBlur 不起作用
【发布时间】:2017-10-30 15:17:37
【问题描述】:

我在 react 应用程序中使用 react-quill 作为富文本编辑器。

我必须将文本编辑器的内容存储在本地 React 状态,并且只将值发送到 Redux 'onBlur'。我的问题是,当您在获得焦点后单击文本编辑器之外的按钮时,onBlur 将不起作用。 (即 onBlur 在点击屏幕上的非交互元素时有效,但在点击“保存”按钮时无效)。

当前代码:

    class TextEditor extends React.Component {
        constructor(props) {
            super(props)
            this.state={
                content: this.props.content;
            }
            this.handleQuillEditor_change = this.handleQuillEditor_change.bind(this)
            this.handleQuillEditor_update = this.handleQuillEditor_update.bind(this)
        }

        handleQuillEditor_change (value) {
            // handleChange...
        }

        handleQuillEditor_update () {
           console.log('blur activated!')
        }


        render() {
            const cmsProps = this.props.cmsProps
            return (
                <div style={containerStyle}>

                      <ReactQuill value={this.state.content}
                                  onChange={this.handleQuillEditor_change} 
                                  onBlur={this.handleQuillEditor_update}/>

               </div>
            )           
        }
    }

【问题讨论】:

    标签: javascript reactjs onblur


    【解决方案1】:

    我的快速修复:将模糊处理程序移动到 QuillComponent 的容器 div,如下所示:

                <div style={containerStyle} onBlur={this.handleQuillEditor_update}>
    
                      <ReactQuill value={this.state.content}
                                  onChange={this.handleQuillEditor_change} />
    
               </div>
    

    【讨论】:

    • 我比第二个更喜欢这个答案。更清晰
    【解决方案2】:

    我遇到了同样的错误,我用这堆代码修复了它。

    <ReactQuill
        onChange={(newValue, delta, source) => {
                    if (source === 'user') {
                      input.onChange(newValue);
                     }}}
        onBlur={(range, source, quill) => {
                input.onBlur(quill.getHTML());
               }}
     />
    

    【讨论】:

    • 哇,这看起来是一个真正的解决方案。用“onBlur”将 RTE 包装在 div 中对你有用吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 2011-12-02
    • 1970-01-01
    • 2021-06-23
    相关资源
    最近更新 更多