From 865d3bb4adea4f90380653adbab220dd29fbf3d4 Mon Sep 17 00:00:00 2001 From: Chris233 Date: Fri, 10 Jul 2026 21:52:51 +0800 Subject: [PATCH] Disable background scrolling when settings open Fixes #580: prevent background thin-scroll areas from scrolling/bleeding through when the Settings modal is open. Adds data-ol-settings-open={settingsOpen ? 'true' : undefined} to the main FloatingShell div and corresponding CSS in tokens.css to set overflow:hidden and hide WebKit scrollbars when the attribute is present. Also adds settings-modal-scroll-isolation.test.mjs to assert the attribute placement and CSS selectors. --- .../settings-modal-scroll-isolation.test.mjs | 62 +++++++++++++++++++ .../app/src/components/FloatingShell.tsx | 1 + openless-all/app/src/styles/tokens.css | 7 +++ 3 files changed, 70 insertions(+) create mode 100644 openless-all/app/scripts/settings-modal-scroll-isolation.test.mjs diff --git a/openless-all/app/scripts/settings-modal-scroll-isolation.test.mjs b/openless-all/app/scripts/settings-modal-scroll-isolation.test.mjs new file mode 100644 index 00000000..b7db5568 --- /dev/null +++ b/openless-all/app/scripts/settings-modal-scroll-isolation.test.mjs @@ -0,0 +1,62 @@ +import { readFile } from 'node:fs/promises'; + +function assertEqual(actual, expected, name) { + if (actual !== expected) { + throw new Error(`${name}:期望 ${expected},实际 ${actual}`); + } +} + +function assertMatch(source, pattern, name) { + if (!pattern.test(source)) { + throw new Error(`${name}:未找到 ${pattern}`); + } +} + +const floatingShellTsx = await readFile( + new URL('../src/components/FloatingShell.tsx', import.meta.url), + 'utf-8', +); +const tokensCss = await readFile( + new URL('../src/styles/tokens.css', import.meta.url), + 'utf-8', +); + +const lockAttributeMatches = [ + ...floatingShellTsx.matchAll(/data-ol-settings-open=\{([^}]*)\}/g), +]; + +assertEqual( + lockAttributeMatches.length, + 1, + '背景滚动锁标记应只出现一次', +); + +const [lockAttributeMatch] = lockAttributeMatches; +const lockAttributeExpression = lockAttributeMatch[1]; +const lockAttributeIndex = lockAttributeMatch.index; +const backgroundScrollerIndex = floatingShellTsx.indexOf('className="ol-thinscroll', lockAttributeIndex); +const settingsModalIndex = floatingShellTsx.indexOf('