fix: remove blur event listener from tippy element (#3365) (#3366)

This commit is contained in:
Mihir Shah 2022-11-04 22:21:01 +05:30 committed by GitHub
parent 4dbdd735b6
commit aca6c88f2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -135,6 +135,10 @@ export class BubbleMenuView {
this.hide()
}
tippyBlurHandler = (event : FocusEvent) => {
this.blurHandler({ event })
}
createTooltip() {
const { element: editorElement } = this.editor.options
const editorIsAttached = !!editorElement.parentElement
@ -156,9 +160,7 @@ export class BubbleMenuView {
// maybe we have to hide tippy on its own blur event as well
if (this.tippy.popper.firstChild) {
(this.tippy.popper.firstChild as HTMLElement).addEventListener('blur', event => {
this.blurHandler({ event })
})
(this.tippy.popper.firstChild as HTMLElement).addEventListener('blur', this.tippyBlurHandler)
}
}
@ -234,6 +236,9 @@ export class BubbleMenuView {
}
destroy() {
if (this.tippy?.popper.firstChild) {
(this.tippy.popper.firstChild as HTMLElement).removeEventListener('blur', this.tippyBlurHandler)
}
this.tippy?.destroy()
this.element.removeEventListener('mousedown', this.mousedownHandler, { capture: true })
this.view.dom.removeEventListener('dragstart', this.dragstartHandler)

View File

@ -104,6 +104,10 @@ export class FloatingMenuView {
this.hide()
}
tippyBlurHandler = (event : FocusEvent) => {
this.blurHandler({ event })
}
createTooltip() {
const { element: editorElement } = this.editor.options
const editorIsAttached = !!editorElement.parentElement
@ -125,9 +129,7 @@ export class FloatingMenuView {
// maybe we have to hide tippy on its own blur event as well
if (this.tippy.popper.firstChild) {
(this.tippy.popper.firstChild as HTMLElement).addEventListener('blur', event => {
this.blurHandler({ event })
})
(this.tippy.popper.firstChild as HTMLElement).addEventListener('blur', this.tippyBlurHandler)
}
}
@ -172,6 +174,9 @@ export class FloatingMenuView {
}
destroy() {
if (this.tippy?.popper.firstChild) {
(this.tippy.popper.firstChild as HTMLElement).removeEventListener('blur', this.tippyBlurHandler)
}
this.tippy?.destroy()
this.element.removeEventListener('mousedown', this.mousedownHandler, { capture: true })
this.editor.off('focus', this.focusHandler)