Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/extension-bubble-menu/src/bubble-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export class BubbleMenuView {
this.hide()
}

tippyBlurHandler = (event : FocusEvent) => {
this.blurHandler({ event })
}

createTooltip() {
const { element: editorElement } = this.editor.options
const editorIsAttached = !!editorElement.parentElement
Expand All @@ -150,9 +154,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)
}
}

Expand Down Expand Up @@ -213,6 +215,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)
Expand Down
11 changes: 8 additions & 3 deletions packages/extension-floating-menu/src/floating-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand Down