From 2517a8b577fc70e8f277c8b6b11830ae7727ccee Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 10 May 2022 15:57:21 +0800 Subject: [PATCH] tiptap: fix render table row, col bubble menu --- .../client/src/components/tooltip/index.tsx | 2 +- .../tiptap/editor/menus/table/col-bubble.tsx | 12 ++++++++++-- .../tiptap/editor/menus/table/row-bubble.tsx | 17 ++++++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/client/src/components/tooltip/index.tsx b/packages/client/src/components/tooltip/index.tsx index a7640d98..a1cb24fb 100644 --- a/packages/client/src/components/tooltip/index.tsx +++ b/packages/client/src/components/tooltip/index.tsx @@ -21,7 +21,7 @@ export const Tooltip: React.FC = ({ content, hideOnClick = false, positi onMouseLeave={() => { toggleVisible(false); }} - onMouseMove={() => { + onMouseDown={() => { hideOnClick && toggleVisible(false); }} > diff --git a/packages/client/src/tiptap/editor/menus/table/col-bubble.tsx b/packages/client/src/tiptap/editor/menus/table/col-bubble.tsx index d7000b9e..9fbe7b92 100644 --- a/packages/client/src/tiptap/editor/menus/table/col-bubble.tsx +++ b/packages/client/src/tiptap/editor/menus/table/col-bubble.tsx @@ -10,7 +10,14 @@ export const TableColBubbleMenu = ({ editor }) => { const shouldShow = useCallback( ({ node, state }) => { if (!editor.isActive(Table.name) || !node || isTableSelected(state.selection)) return false; - const gripColumn = node.querySelector('a.grip-column.selected'); + + let container = node; + + while (container && !['TD', 'TH'].includes(container.tagName)) { + container = container.parentElement; + } + + const gripColumn = container && container.querySelector && container.querySelector('a.grip-column.selected'); return !!gripColumn; }, [editor] @@ -28,7 +35,7 @@ export const TableColBubbleMenu = ({ editor }) => { editor={editor} pluginKey="table-col-bubble-menu" tippyOptions={{ - offset: [0, 20], + offset: [0, 35], }} shouldShow={shouldShow} getRenderContainer={getRenderContainer} @@ -53,6 +60,7 @@ export const TableColBubbleMenu = ({ editor }) => { size="small" /> +