javascript - react 羽毛笔 onBlur 不工作

标签 javascript reactjs onblur

我在 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>
            )           
        }
    }

最佳答案

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

            <div style={containerStyle} onBlur={this.handleQuillEditor_update}>

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

           </div>

关于javascript - react 羽毛笔 onBlur 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47018722/

相关文章:

javascript - 轮播上的 jQuery 循环不起作用

javascript - 使用 onBlur 事件上的值更新 React 输入文本字段

javascript - 模糊事件不会在 IE7 和 IE6 中触发

javascript - GWT - 未触发 onClick

javascript - jQuery - 告诉页面何时滚动到并正在查看特定的 DIV

javascript - Meteor 从模式定义的表单中获取数据

javascript - 我开发了一个 api,我希望它重定向到其他 php 页面,并在我单击 api 文件中的按钮时弹出模式

javascript - ReactJS - 未捕获错误 : Syntax error, 无法识别的表达式

javascript - Firebase - 等待来自异步数据库调用的数据

javascript - 状态值停止在 UseEffect Hook 内更新 - Gatsby/React