From 359105f4747344aa0961fa24364eb5797a44e620 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 30 May 2022 15:42:15 +0800 Subject: [PATCH] client: fix tocs collapsed detector --- packages/client/src/tiptap/editor/tocs/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/client/src/tiptap/editor/tocs/index.tsx b/packages/client/src/tiptap/editor/tocs/index.tsx index 18806e6d..95aa9c3b 100644 --- a/packages/client/src/tiptap/editor/tocs/index.tsx +++ b/packages/client/src/tiptap/editor/tocs/index.tsx @@ -38,7 +38,7 @@ const Toc = ({ toc, collapsed }) => { ); }; -const FULL_WIDTH = 1000; +const TOCS_WIDTH = 198; // 目录展开的宽度 export const Tocs: React.FC<{ editor: Editor; getContainer: () => HTMLElement }> = ({ editor, getContainer }) => { const [collapsed, toggleCollapsed] = useToggle(true); @@ -51,7 +51,8 @@ export const Tocs: React.FC<{ editor: Editor; getContainer: () => HTMLElement }> if (!el) return; const handler = throttle(() => { - toggleCollapsed(el.offsetWidth <= FULL_WIDTH); + const diffWidth = el.offsetWidth - (el.firstChild as HTMLDivElement).offsetWidth; + toggleCollapsed(diffWidth <= TOCS_WIDTH); }, 200); handler();