From d010f3aaba2fd443e16e9f63941c8570939a3cfb Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 30 May 2022 17:32:04 +0800 Subject: [PATCH] client: add resize handler in tocs --- packages/client/src/tiptap/editor/tocs/index.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/client/src/tiptap/editor/tocs/index.tsx b/packages/client/src/tiptap/editor/tocs/index.tsx index 7d7ab852..93a5b94c 100644 --- a/packages/client/src/tiptap/editor/tocs/index.tsx +++ b/packages/client/src/tiptap/editor/tocs/index.tsx @@ -51,17 +51,19 @@ export const Tocs: React.FC<{ editor: Editor; getContainer: () => HTMLElement }> if (!el) return; - const handler = throttle(() => { + const handler = () => { const diffWidth = el.offsetWidth - (el.firstChild as HTMLDivElement).offsetWidth; toggleCollapsed(diffWidth <= TOCS_WIDTH); - }, 200); + }; handler(); const observer = new MutationObserver(handler); observer.observe(el, { attributes: true, childList: true, subtree: true }); + window.addEventListener('resize', handler); return () => { observer.disconnect(); + window.removeEventListener('resize', handler); }; }, [getContainer, toggleCollapsed]);