client: fix tocs collapsed detector

This commit is contained in:
fantasticit 2022-05-30 15:42:15 +08:00
parent 1233211966
commit 359105f474
1 changed files with 3 additions and 2 deletions

View File

@ -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 }) => { export const Tocs: React.FC<{ editor: Editor; getContainer: () => HTMLElement }> = ({ editor, getContainer }) => {
const [collapsed, toggleCollapsed] = useToggle(true); const [collapsed, toggleCollapsed] = useToggle(true);
@ -51,7 +51,8 @@ export const Tocs: React.FC<{ editor: Editor; getContainer: () => HTMLElement }>
if (!el) return; if (!el) return;
const handler = throttle(() => { const handler = throttle(() => {
toggleCollapsed(el.offsetWidth <= FULL_WIDTH); const diffWidth = el.offsetWidth - (el.firstChild as HTMLDivElement).offsetWidth;
toggleCollapsed(diffWidth <= TOCS_WIDTH);
}, 200); }, 200);
handler(); handler();