Skip to content
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

Fix popover invisible in horizontal scroll #702

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

saint3347
Copy link
Collaborator

@saint3347 saint3347 commented Oct 9, 2024

Types of changes

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Others

Changelog

  • 修复Popover在滚动容器中的极限边界场景下不可见的问题
  • 修复弹出层类组件偶现的闪烁问题

Summary by CodeRabbit

  • 新功能
    • 引入了 getClosestScrollContainer 函数,以改进弹出窗口的定位逻辑。
  • bug 修复
    • 修复了在滚动容器的极端边界情况下,Popover 组件不可见的问题。
  • 文档
    • 更新了 Popover 组件的变更日志,记录了版本 3.4.3-beta.4 的更新。

Copy link

coderabbitai bot commented Oct 9, 2024

Walkthrough

该拉取请求包含对多个文件的更改,主要涉及版本更新和功能增强。在package.json中,版本号从"3.4.3-beta.3"更新为"3.4.3-beta.4"。在usePositionStyle钩子中,添加了获取最近滚动容器的功能,并改进了弹出元素的定位逻辑。同时,usePopup钩子的updatePosition函数进行了重构,移除了延迟,允许立即更新位置。最后,新增了getClosestScrollContainer函数以支持滚动容器的查找。

Changes

文件路径 更改摘要
package.json 版本更新:"version": "3.4.3-beta.3""version": "3.4.3-beta.4"
packages/hooks/src/common/use-position-style/index.ts 添加了getClosestScrollContainer的导入,改进了getAbsolutePositionStyle的逻辑,增加了调试日志。
packages/hooks/src/components/use-popup/use-popup.ts 重构了updatePosition函数,移除了10毫秒的延迟,简化了位置更新逻辑。
packages/hooks/src/utils/dom/element.tsx 新增getClosestScrollContainer函数,用于查找最近的可滚动祖先元素。
packages/shineout/src/popover/__doc__/changelog.cn.md 更新了Popover组件的变更日志,新增版本3.4.3-beta.4,记录了相关的bug修复。

Possibly related PRs

兔子欢快跳跃,
版本更新真是妙,
新功能来助力,
定位精准无烦恼。
小日志记录忙,
让调试更轻松。
哦,变化真美好! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Outside diff range and nitpick comments (3)
packages/shineout/src/popover/__doc__/changelog.cn.md (1)

1-5: 更新看起来不错!

新的更新日志条目格式正确,内容清晰。它准确地描述了修复的问题,并提供了相关的 PR 链接。这与之前提供的 PR 目标一致。

为了保持一致性,建议在版本号和日期之间添加一个空行。例如:

 ## 3.4.3-beta.4
+
 2024-10-09
packages/hooks/src/utils/dom/element.tsx (1)

106-137: 代码实现良好,建议小幅优化性能

这个新增的 getClosestScrollContainer 函数实现得很好,逻辑清晰,考虑了各种边界情况。以下是一些观察和建议:

  1. 函数正确处理了输入元素为 null 的情况。
  2. 内部的 isScrollable 函数全面检查了元素的可滚动性,包括样式和实际尺寸。
  3. DOM 树的遍历逻辑正确。
  4. 当找不到可滚动祖先时,使用 document.scrollingElementdocument.documentElement 作为后备方案是恰当的。

为了稍微优化性能,可以考虑缓存 window.getComputedStyle 的结果:

  const isScrollable = (el: HTMLElement) => {
-   const style = window.getComputedStyle(el);
+   const style = el.style || window.getComputedStyle(el);
    const overflowX = style.overflowX;
    const overflowY = style.overflowY;
    return (overflowX === 'auto' || overflowX === 'scroll' ||
            overflowY === 'auto' || overflowY === 'scroll') &&
           (el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth);
  };

这样可以避免对已经有内联样式的元素重复调用 getComputedStyle,从而略微提高性能。

packages/hooks/src/common/use-position-style/index.ts (1)

344-344: 建议移除或条件化控制台日志

updateStyle 函数中添加的 console.log 语句可能对调试很有帮助,但不适合保留在生产代码中。建议采取以下措施之一:

  1. 如果这个日志仅用于临时调试,请在提交前删除它。
  2. 如果这个日志对于长期调试或监控很重要,考虑使用条件语句来控制它的输出,例如:
if (process.env.NODE_ENV === 'development') {
  console.log('show, position, absolute, updateKey, fixedWidth: >>', show, position, absolute, updateKey, fixedWidth);
}

这样可以确保日志只在开发环境中输出,不会影响生产环境的性能。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 859ea14 and fa5ae4a.

📒 Files selected for processing (5)
  • package.json (2 hunks)
  • packages/hooks/src/common/use-position-style/index.ts (4 hunks)
  • packages/hooks/src/components/use-popup/use-popup.ts (2 hunks)
  • packages/hooks/src/utils/dom/element.tsx (1 hunks)
  • packages/shineout/src/popover/doc/changelog.cn.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🧰 Additional context used
🔇 Additional comments (4)
packages/hooks/src/components/use-popup/use-popup.ts (1)

62-68: 代码改进:提高了弹出框定位的响应性和稳定性

这个改动很好地解决了PR中提到的问题:

  1. 移除了setTimeout,有助于解决间歇性闪烁的问题。
  2. 立即计算和更新位置,提高了弹出框在滚动容器中的响应性。
  3. 只在位置发生变化时更新状态,减少了不必要的重渲染。

这些变更应该能有效改善弹出框在水平滚动场景中的可见性和稳定性。

packages/hooks/src/common/use-position-style/index.ts (3)

6-6: 新导入函数有助于改进定位逻辑

引入 getClosestScrollContainer 函数是一个好的改进。这个函数可以帮助我们找到最近的可滚动容器,从而更准确地计算弹出元素的位置,特别是在复杂的嵌套滚动容器中。


158-159: 改进了水平滚动情况下的定位逻辑

这个修改很好地解决了在水平滚动容器中弹出元素可能变得不可见的问题。通过考虑最近滚动容器的滚动偏移量,弹出元素的位置现在可以更准确地计算,确保它始终保持在正确的位置上。这对于提高用户体验和组件的可用性非常重要。

建议:

  1. 考虑添加注释解释这个计算的目的,以便其他开发者更容易理解。
  2. 可以考虑将这个逻辑抽取为一个单独的函数,以提高代码的可读性和可维护性。

Also applies to: 176-176


Line range hint 1-355: 总体评价:有效解决了报告的问题

这些更改很好地解决了水平滚动场景中弹出元素可见性的问题。主要改进包括:

  1. 引入了 getClosestScrollContainer 函数,用于找到最近的可滚动容器。
  2. 更新了 getAbsolutePositionStyle 函数中的定位逻辑,考虑了最近滚动容器的滚动偏移量。
  3. 添加了调试日志,有助于问题排查(建议在生产环境中移除或条件化)。

这些修改提高了组件在复杂布局中的可用性和可靠性。建议在合并这些更改之前,进行全面的测试,特别是在各种滚动场景下,以确保修复能够在所有情况下正常工作。

@saint3347 saint3347 merged commit b41dcfd into main Oct 9, 2024
1 check passed
@saint3347 saint3347 mentioned this pull request Oct 12, 2024
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant