fix: 失去焦点tooltip不消失

This commit is contained in:
yanbiao 2020-12-30 00:20:44 +08:00 committed by 86driver
parent 277d09720f
commit 3c48acfe41
5 changed files with 9 additions and 7 deletions

View File

@ -179,7 +179,6 @@ class Editor {
public destroy(): void {
// 调用钩子函数
this.beforeDestroyHooks.forEach(fn => fn.call(this))
// 销毁 DOM 节点
this.$toolbarElem.remove()
this.$textContainerElem.remove()

View File

@ -56,10 +56,7 @@ function _bindFocusAndBlur(editor: Editor): void {
if (isToolbar && !isMenu) {
return
}
if (editor.isFocus) {
_blurHandler(editor)
}
_blurHandler(editor)
editor.isFocus = false
} else {
if (!editor.isFocus) {
@ -103,6 +100,7 @@ function _blurHandler(editor: Editor) {
const config = editor.config
const onblur = config.onblur
const currentHtml = editor.txt.html() || ''
editor.txt.eventHooks.onBlurEvents.forEach(fn => fn())
onblur(currentHtml)
}

View File

@ -31,7 +31,6 @@ class Tooltip {
this.conf = conf
this._show = false
this._isInsertTextContainer = false
// 定义 container
const $container = $('<div></div>')
$container.addClass('w-e-tooltip')
@ -167,6 +166,9 @@ class Tooltip {
}
this._show = true
editor.beforeDestroy(this.remove.bind(this))
editor.txt.eventHooks.onBlurEvents.push(this.remove.bind(this))
}
/**

View File

@ -13,9 +13,10 @@ import getHtmlByNodeList from './getHtmlByNodeList'
/** 按键函数 */
type KeyBoardHandler = (event: KeyboardEvent) => unknown
/** 普通事件回调 */
type EventHandler = (event: Event) => unknown
type EventHandler = (event?: Event) => unknown
// 各个事件钩子函数
type TextEventHooks = {
onBlurEvents: EventHandler[]
changeEvents: (() => void)[] // 内容修改时
dropEvents: ((event: DragEvent) => unknown)[]
clickEvents: EventHandler[]
@ -64,6 +65,7 @@ class Text {
this.editor = editor
this.eventHooks = {
onBlurEvents: [],
changeEvents: [],
dropEvents: [],
clickEvents: [],

View File

@ -43,6 +43,7 @@ test('点击 tooltip', () => {
})
test('tooltip 显示和隐藏', () => {
tooltip.create()
expect(tooltip.isShow).toBe(true)
tooltip.remove()