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: 🐛 修复DropMenu第一次通过open()而非用户点击打开时展开菜单定位错误问题 #671

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zybzzc
Copy link
Contributor

@zybzzc zybzzc commented Oct 18, 2024

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • 新功能

    • 增强了下拉菜单组件的响应能力,确保菜单显示方向的偏移量准确计算。
  • 改进

    • 优化了菜单折叠功能的执行流程,确保在切换可见性之前完成偏移量更新。

Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 4:24am

Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

该拉取请求对 wd-drop-menu.vue 组件进行了多项修改,主要增强了其功能和控制流程。最显著的变化是新增了 onMounted 生命周期钩子,该钩子调用了新的 updateOffset 函数,以根据组件在视口中的位置计算和更新偏移量,从而提高菜单的响应性。fold 函数被重构为异步函数,以确保在切换子菜单的可见性之前准确计算偏移量。

Changes

文件路径 更改摘要
src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue 新增 async function updateOffset();重构 fold 函数为异步,确保在切换子菜单前更新偏移量。

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

🐇 在菜单中跳跃,偏移量更新,
异步折叠,清晰又顺畅,
方向明确,错误无踪,
兔子欢呼,功能更强! 🌟


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

netlify bot commented Oct 18, 2024

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f38e51c
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/6711e2afd4a1810008fe693e
😎 Deploy Preview https://deploy-preview-671--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 31353ce and f38e51c.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue (3 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue (1)

109-118: 确认 updateOffset 函数的健壮性

updateOffset 函数中使用了 getRect 获取元素的位置信息,并根据方向计算 offset 的值。请确保在可能的情况下,rect 始终能正确获取,否则可能导致 offset 未被更新,影响菜单的定位。

建议在全局搜索可能影响 dropMenuIdproxy 的代码,确保在任何情况下 getRect 都能返回有效的 rect

Comment on lines +71 to +73
onMounted(() => {
updateOffset()
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

建议在 onMounted 中正确处理异步函数

onMounted 钩子中调用了异步函数 updateOffset(),但未使用 await 等待其完成。这可能导致在组件挂载后,offset 尚未更新就进行后续操作。建议将 onMounted 改为异步函数,并使用 await 确保 updateOffset() 完成。

建议修改如下:

-onMounted(() => {
+onMounted(async () => {
   await updateOffset()
 })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onMounted(() => {
updateOffset()
})
onMounted(async () => {
await updateOffset()
})

Comment on lines +123 to +125
async function fold(child: any) {
await updateOffset()
child.$.exposed!.toggle()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

注意异步函数调用的返回值处理

fold 函数已被修改为异步函数,但在 toggle 函数中调用时未处理返回的 Promise。这可能导致在 updateOffset() 未完成时就执行了后续的 toggle() 操作,可能引发逻辑问题。建议在调用 fold(child) 时适当处理异步。

如果需要等待 fold 完成,建议修改 toggle 函数:

 function toggle(child: any) {
   // 点击当前菜单,关闭其他菜单
   if (child && !child.disabled) {
     if (queue && queue.closeOther) {
       queue.closeOther(child)
     } else {
       closeOther(child)
     }
-    fold(child)
+    fold(child)
+      .then(() => {
+        // 后续操作
+      })
+      .catch((error) => {
+        console.error(error)
+      })
   }
 }

或者将 toggle 函数也修改为异步函数:

- function toggle(child: any) {
+ async function toggle(child: any) {
   // 点击当前菜单,关闭其他菜单
   if (child && !child.disabled) {
     if (queue && queue.closeOther) {
       queue.closeOther(child)
     } else {
       closeOther(child)
     }
-    fold(child)
+    await fold(child)
   }
 }

请根据具体需求选择合适的修改方式。

Committable suggestion was skipped due to low confidence.

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