-
Notifications
You must be signed in to change notification settings - Fork 21
fix: consider overflow-y: scroll as overflowing in isBodyOverflowing #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Walkthrough本次更改对 Changes
Sequence Diagram(s)sequenceDiagram
participant 调用者
participant util.ts
调用者->>util.ts: 调用 isBodyOverflowing()
util.ts->>util.ts: 获取 body 的 computed style
alt overflowY 为 'scroll'
util.ts-->>调用者: 返回 true
else
util.ts->>util.ts: 执行原有溢出判断逻辑
util.ts-->>调用者: 返回判断结果
end
Estimated code review effort1 (~2 minutes) Possibly related issues
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/util.tsOops! Something went wrong! :( ESLint: 7.32.0 ESLint couldn't find the plugin "eslint-plugin-react". (The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-react" was referenced from the config file in ".eslintrc.js » /node_modules/.pnpm/@umijs[email protected]/node_modules/@umijs/fabric/dist/eslint.js". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/util.ts (2)
5-6
: 逻辑修改正确,建议改进代码风格。新增的早期返回条件正确解决了
overflow-y: scroll
时滚动条始终可见的问题。不过建议为 if 语句添加花括号以提高代码可读性。- if (window.getComputedStyle(document.body).overflowY === 'scroll') - return true; + if (window.getComputedStyle(document.body).overflowY === 'scroll') { + return true; + }
4-13
: 功能实现正确,考虑处理其他溢出场景。当前修改正确解决了
overflow-y: scroll
的问题。为了更全面地处理滚动条场景,可以考虑以下增强:
- 当
overflowY
为'auto'
且内容确实溢出时,滚动条也会显示- 可能需要考虑
overflowX
的类似情况不过考虑到这是针对特定问题的修复,当前实现已经足够解决 PR 目标中描述的布局偏移问题。
If you want to see the issue in action, I created this CodeSandbox: https://codesandbox.io/p/sandbox/wonderful-darwin-72j6h9 |
When the body has
overflow-y: scroll
set, the scrollbar is always visible,even if the content doesn’t overflow. Previously,
isBodyOverflowing
returned false in this case, causing layout shifts (e.g., modal jumps)
because no padding was applied.
This change makes
isBodyOverflowing
return true ifoverflow-y: scroll
is detected, ensuring consistent scrollbar handling and preventing UI jumps.
Summary by CodeRabbit