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: 🐛 修复Collapse折叠面板组件内容溢出问题 #710

Merged
merged 3 commits into from
Nov 21, 2024
Merged

Conversation

Gahotx
Copy link
Contributor

@Gahotx Gahotx commented Nov 13, 2024

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

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

🔗 相关 Issue

#503

💡 需求背景和解决方案

问题:

  1. 点击子项,会改变其他子项的wd-collapse-item__wrapper的高度,导致如果折叠面板内容是文字省略号到展开的状态就不会触发transitionend事件置空wd-collapse-item__wrapper的高度,从而造成了内容溢出的问题
  2. 即使折叠面板里的内容变化触发了transitionend事件,也会有一个先溢出再展开的效果,而不是直接展开的效果
    3b4210ce29180dea7a22e4880c6f3b77

解决办法:

  1. 取消每一项wd-collapse-itemselected的监听,不会造成点击子项影响其他子项的wd-collapse-item__wrapper高度
  2. 在点击子项的handleClick事件调用updateExpend(),只更新点击的那一个子项,不影响其他子项

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

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

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

Summary by CodeRabbit

  • 新功能
    • 增加了 updateExpand 方法,允许外部更新折叠项的展开状态。
    • 改进了 toggleAll 方法,确保在切换所有面板时正确更新子组件的展开状态。
  • 变更
    • 移除了对选中属性的观察,简化了展开状态的控制逻辑。
    • 重命名了 updateExpendupdateExpand,并更新了相关调用。

Copy link

vercel bot commented Nov 13, 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 Nov 20, 2024 3:34am

Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

该拉取请求对 wd-collapse-item.vue 组件进行了修改,主要集中在脚本部分。移除了监视 selected 计算属性变化的 watch 函数,简化了控制流,使得展开状态的更新不再依赖于 selected 属性,而是通过新的 handleChangeExpand(name) 函数来管理。同时,updateExpend() 函数被重命名为 updateExpand(),并在 onMounted 生命周期钩子中调用。wd-collapse.vue 组件的 toggleAll 方法也进行了增强,以确保在切换所有面板时更新子组件的展开状态。

Changes

文件路径 更改摘要
src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue 移除对 selected 的监视,重命名 updateExpend()updateExpand(),并添加 handleChangeExpand(name) 函数。
src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts CollapseItemExpose 类型中添加 updateExpand 方法,返回 Promise<void>
src/uni_modules/wot-design-uni/components/wd-collapse/wd-collapse.vue toggleAll 方法中添加 item.$.exposed!.updateExpand() 调用,以更新子组件的展开状态。

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

Poem

在兔子窝里跳跃欢,
点击展开乐无边。
更新状态快如风,
简化流程真轻松。
兔子欢呼声声响,
变化来临乐无疆。 🐇✨


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 Nov 13, 2024

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 553b022
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/673d5878804b4b000830a9ae
😎 Deploy Preview https://deploy-preview-710--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: 0

🧹 Outside diff range and nitpick comments (1)
src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue (1)

115-115: 代码更改解决了内容溢出问题

新增的 updateExpend() 调用确保了在状态切换之前更新高度,这样可以防止内容溢出。建议考虑以下优化点:

  1. 可以添加注释说明这行代码的重要性,以防止将来误删除
  2. 考虑将 updateExpend() 的调用移动到 beforeExpend 处理之后,以确保在实际展开之前获取最新的内容高度

建议添加如下注释:

function handleClick() {
  if (props.disabled) return
+  // 在状态切换前更新高度,防止内容溢出
  updateExpend()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2e124b2 and b21971d.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue (1 hunks)
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue (1)

Line range hint 114-137: 验证解决方案的完整性

需要确认以下几点以确保完全解决问题:

  1. 是否已移除 selected 的 watch 监听器
  2. 当前实现是否确实避免了对其他折叠面板项的影响

运行以下脚本验证完整实现:

@Gahotx
Copy link
Contributor Author

Gahotx commented Nov 20, 2024

这是Deploy Preview的效果,可以和上面的对比,包括我项目中出现的内容溢出问题也解决了,请问是有什么问题阻碍了合并吗?@Moonofweisheng
PixPin_2024-11-20_10-09-33

@Moonofweisheng
Copy link
Owner

这是Deploy Preview的效果,可以和上面的对比,包括我项目中出现的内容溢出问题也解决了,请问是有什么问题阻碍了合并吗?@Moonofweisheng PixPin_2024-11-20_10-09-33 PixPin_2024-11-20_10-09-33

这两天在搞别的,PR晚点会review,点了下看着有点问题,代码还没看,这周会看。

QQ20241120-102633.mp4

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

🧹 Outside diff range and nitpick comments (2)
src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts (1)

34-38: 建议补充方法文档说明

建议在方法文档中补充更详细的信息:

  • 方法的具体用途
  • 何时会被调用
  • 返回的 Promise 在什么情况下 resolve/reject

建议修改为:

  /**
   * 更新展开状态
+  * @description 更新折叠面板的展开状态,处理内容高度变化和过渡动画
+  * @remarks 在面板展开/收起时自动调用,也可以在内容变化时手动调用
+  * @throws 当面板处于禁用状态时可能会抛出错误
   * @returns Promise<void>
   */
  updateExpand: () => Promise<void>
src/uni_modules/wot-design-uni/components/wd-collapse/wd-collapse.vue (1)

Line range hint 128-133: 建议增加错误处理和注释说明

为了提高代码的可维护性和稳定性,建议:

  1. 添加注释说明此更改如何解决内容溢出问题
  2. 增加错误处理机制

建议修改为:

+      // 确保在切换展开状态前更新高度,防止内容溢出
+      try {
         await item.$.exposed!.updateExpand()
         if (isDef(expanded) ? expanded : !item.$.exposed!.getExpanded()) {
           names.push(item.name || index)
         }
+      } catch (error) {
+        console.error('更新展开状态失败:', error)
+      }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b21971d and d7d34cb.

📒 Files selected for processing (3)
  • src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-collapse/wd-collapse.vue (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts (1)

34-38: 方法签名和类型定义正确!

新增的 updateExpand 方法定义合理,返回类型 Promise<void> 符合异步操作的需求。这个改动很好地支持了折叠面板内容溢出问题的修复。

@Gahotx
Copy link
Contributor Author

Gahotx commented Nov 20, 2024

这两天在搞别的,PR晚点会review,点了下看着有点问题,代码还没看,这周会看。

有一个小问题,wd-collapse-item组件内部的updateExpendbeforeExpend应该是拼错单词了(expand),内部使用的updateExpend我更正为了updateExpandbeforeExpend是一个props属性,修改的话对旧版本就不兼容了,所以我没有修改,您可以看一下是否需要修改

@Moonofweisheng
Copy link
Owner

Moonofweisheng commented Nov 20, 2024 via email

@Gahotx
Copy link
Contributor Author

Gahotx commented Nov 20, 2024

好的,上面发现的两个问题已经修复好了,其他地方我点了暂时没发现问题,您有空的时候可以看看

Copy link
Owner

@Moonofweisheng Moonofweisheng left a comment

Choose a reason for hiding this comment

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

感谢你的PR!

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.

2 participants