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(bubble-menu): add focusout handler for floating element #5882

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions .changeset/twelve-turtles-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@tiptap/extension-bubble-menu": patch
"@tiptap/react": patch
"@tiptap/vue-2": patch
"@tiptap/vue-3": patch
---

Fix the bug where the bubble menu does not hide
cairon666 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions packages/extension-bubble-menu/src/bubble-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class BubbleMenuView {
}

this.element.addEventListener('mousedown', this.mousedownHandler, { capture: true })
this.element.addEventListener('focusout', this.floatingFocusoutHandler)
this.view.dom.addEventListener('dragstart', this.dragstartHandler)
this.editor.on('focus', this.focusHandler)
this.editor.on('blur', this.blurHandler)
Expand All @@ -132,6 +133,10 @@ export class BubbleMenuView {
this.element.style.visibility = 'visible'
}

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

mousedownHandler = () => {
this.preventHide = true
}
Expand Down Expand Up @@ -303,6 +308,7 @@ export class BubbleMenuView {
}
this.tippy?.destroy()
this.element.removeEventListener('mousedown', this.mousedownHandler, { capture: true })
this.element.removeEventListener('focusout', this.floatingFocusoutHandler)
this.view.dom.removeEventListener('dragstart', this.dragstartHandler)
this.editor.off('focus', this.focusHandler)
this.editor.off('blur', this.blurHandler)
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/BubbleMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const BubbleMenu = (props: BubbleMenuProps) => {
}, [props.editor, currentEditor, element])

return (
<div ref={setElement} className={props.className} style={{ visibility: 'hidden' }}>
<div ref={setElement} tabIndex={-1} className={props.className} style={{ visibility: 'hidden' }}>
cairon666 marked this conversation as resolved.
Show resolved Hide resolved
{props.children}
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-2/src/BubbleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const BubbleMenu: Component = {
},

render(this: BubbleMenuInterface, createElement: CreateElement) {
return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)
return createElement('div', { style: { visibility: 'hidden' }, attrs: { tabIndex: -1 } }, this.$slots.default)
},

beforeDestroy(this: BubbleMenuInterface) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-3/src/BubbleMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ export const BubbleMenu = defineComponent({
editor.unregisterPlugin(pluginKey)
})

return () => h('div', { ref: root }, slots.default?.())
return () => h('div', { ref: root, tabindex: -1 }, slots.default?.())
},
})