Skip to content

Commit

Permalink
fix: 修复设置isFocus为false的情况下,初始化完成后依旧触发blur事件的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
liuqinghua233 committed Mar 22, 2021
1 parent 2e9a311 commit 96e7a1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion examples/auto-focus.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@

editor.config.focus = false

editor.config.onfocus = function () {
console.log('触发focus事件')
}
editor.config.onblur = function () {
console.log('触发blur事件')
}
editor.create()
</script>
</body>

</html>
</html>
4 changes: 3 additions & 1 deletion src/editor/init-fns/bind-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ function _bindFocusAndBlur(editor: Editor): void {
editor.isFocus = true
}
}
if (document.activeElement === editor.$textElem.elems[0]) {
// fix: 增加判断条件,防止当用户设置isFocus=false时,初始化完成后点击其他元素依旧会触发blur事件的问题
if (document.activeElement === editor.$textElem.elems[0] && editor.config.focus) {
_focusHandler(editor)
editor.isFocus = true
}
// 绑定监听事件
$(document).on('click', listener)
// 全局事件在编辑器实例销毁的时候进行解绑
editor.beforeDestroy(function () {
Expand Down

0 comments on commit 96e7a1e

Please sign in to comment.