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

feat: ✨ DropMenuItem 新增通过 v-mode:open 外部控制打开或关闭状态 #662

Closed
wants to merge 0 commits into from

Conversation

zybzzc
Copy link
Contributor

@zybzzc zybzzc commented Oct 15, 2024

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

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了DropMenu组件的文档,增加了外部控制菜单状态、预切换功能、方向属性等新特性。
    • 增加了外部控制打开/关闭的示例,提升了交互性。
    • 新增了v-model:open属性,允许外部控制DropMenuItem的可见性。
  • 文档

    • 扩展了DropMenuItem的属性表,包含新属性和功能的代码示例。

Copy link

vercel bot commented Oct 15, 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 15, 2024 9:59am

Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

本次更改主要集中在DropMenu组件的文档和实现上。文档中增加了外部控制菜单状态、before-toggle功能、方向属性以及样式自定义的说明。同时,代码示例也进行了更新,以展示新功能的使用。实现方面,DropMenuItem新增了v-model:open属性和before-toggle函数,wd-drop-menu-item组件则更新了事件处理和状态管理,增强了与外部状态的交互。

Changes

文件路径 更改摘要
docs/component/drop-menu.md 更新文档,增加外部控制菜单状态、before-toggle功能、方向属性及样式自定义说明,更新代码示例。
src/pages/dropMenu/Index.vue 移除@click="closeOutside"事件处理,新增演示块以展示外部控制功能,添加openvalue11的响应式变量。
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts dorpMenuItemProps中新增open属性,表示菜单的打开/关闭状态。
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue 更新emit函数签名以包含update:open事件,添加多个观察者以改进状态管理和类型验证。

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

Poem

🐰 在菜单中跳跃,状态随心控,
before-toggle来临,验证不再愁。
方向随意选择,样式更灵动,
代码示例闪亮,开发乐无穷!
兔子欢呼雀跃,祝贺新功能! 🌟


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 15, 2024

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 60b07e5
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/6711cf08db8113000872898c
😎 Deploy Preview https://deploy-preview-662--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: 1

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

Line range hint 1-91: 整体改动评估

此次改动仅在 dorpMenuItemProps 对象中添加了 open 属性,没有对文件的其他部分进行修改。这个改动与现有代码结构保持一致,不会对现有的类型或接口造成破坏性变更。总的来说,这个改动很好地实现了 PR 的目标,即允许通过 v-model:open 外部控制 DropMenuItem 的打开或关闭状态。

建议:

  1. 考虑在 DropMenuItemProps 类型中也反映这个新属性,以确保类型定义的完整性。
  2. 可以在 DropMenuItemExpose 接口中添加与 open 状态相关的方法,如 isOpen()setOpen(value: boolean),以提供更完整的组件 API。
docs/component/drop-menu.md (1)

169-190: 新功能文档清晰明了,建议稍作优化

这个新增的部分很好地解释了如何使用 v-model:open 来外部控制 DropMenuItem 的打开和关闭状态。代码示例清晰地展示了如何使用这个新特性。

为了进一步提高文档的可读性,建议在代码示例中添加一行注释,说明 open 变量的作用。例如:

// 控制 DropMenuItem 的打开/关闭状态
const open = ref<boolean>(false)

这样可以帮助读者更快地理解代码的意图。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 60b07e5 and 4b44509.

📒 Files selected for processing (4)
  • docs/component/drop-menu.md (2 hunks)
  • src/pages/dropMenu/Index.vue (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue (2 hunks)
🧰 Additional context used
🔇 Additional comments (8)
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (1)

15-18: 新属性 open 添加正确

新增的 open 属性符合 PR 的目标,允许外部控制菜单项的打开/关闭状态。属性名称和类型选择恰当,注释清晰简洁。这个改动增强了组件的灵活性和可控性。

docs/component/drop-menu.md (2)

226-226: 属性表格更新正确

v-model:open 属性已正确添加到 DropMenuItem 的属性表格中。描述清晰,与之前的解释保持一致,有助于用户理解和使用这个新特性。


Line range hint 1-290: 文档更新全面且集成良好

本次更新很好地介绍了 DropMenuItem 组件的新功能 —— 通过 v-model:open 实现外部控制打开/关闭状态。新增的内容包括:

  1. 详细的功能说明和使用示例
  2. 在 DropMenuItem 属性表格中添加了新属性

这些变更与现有文档内容保持一致,没有引入任何错误或不一致之处。整体而言,这次更新提高了组件的灵活性,并为用户提供了清晰的使用指导。

src/pages/dropMenu/Index.vue (2)

41-46: 外部控制打开关闭功能实现正确

你添加了一个新的示例,用于展示如何通过v-model:open外部控制wd-drop-menu-item的打开和关闭状态。实现方式正确,功能符合预期。


44-44: 同时使用v-modelv-model:open需要注意

wd-drop-menu-item组件上同时使用了v-model="value11"v-model:open="open",请确保组件能够正确处理这两个绑定,避免可能的状态冲突或意外行为。

src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue (3)

65-65: 新增了 'update:open' 事件以支持外部控制

通过在 emit 中添加 'update:open' 事件,使组件能够与外部的 open 属性进行同步,符合 Vue 3 中 v-model 事件命名规范。


69-69: 同步内部 showPop 状态与外部 open 属性

showPop 的初始值设置为 props.open,确保组件的初始显示状态与传入的 open 属性一致,增强了组件的可控性和同步性。


118-126: 同步 showPop.valueprops.open,确保状态一致

showPop.value 发生变化且与 props.open 不同时,触发 'update:open' 事件。这有助于将组件内部状态的变化通知给父组件,使外部的 open 属性与组件内部状态保持同步。

Comment on lines 106 to 116
watch(
() => props.open,
(newValue) => {
if (isDef(newValue) && typeof newValue !== 'boolean') {
console.error('[wot-design] warning(wd-drop-menu-item): the type of open should be a boolean.')
}
if (newValue !== showPop.value) {
dropMenu?.fold(proxy)
}
}
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

props.open 的监听器中可能存在逻辑问题

当前,当 props.open 发生变化且与 showPop.value 不同时,调用了 dropMenu?.fold(proxy) 方法。然而,这可能无法正确同步 showPop.value,导致内部状态与外部 open 属性不一致。建议直接更新 showPop.value = newValue,以确保状态同步。

建议修改代码如下:

watch(
  () => props.open,
  (newValue) => {
    if (isDef(newValue) && typeof newValue !== 'boolean') {
      console.error('[wot-design] warning(wd-drop-menu-item): the type of open should be a boolean.')
    }
    if (newValue !== showPop.value) {
-     dropMenu?.fold(proxy)
+     showPop.value = newValue
    }
  }
)

此修改确保当 props.open 变化时,showPop.value 能正确更新,保持组件内部状态与外部属性同步。

📝 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
watch(
() => props.open,
(newValue) => {
if (isDef(newValue) && typeof newValue !== 'boolean') {
console.error('[wot-design] warning(wd-drop-menu-item): the type of open should be a boolean.')
}
if (newValue !== showPop.value) {
dropMenu?.fold(proxy)
}
}
)
watch(
() => props.open,
(newValue) => {
if (isDef(newValue) && typeof newValue !== 'boolean') {
console.error('[wot-design] warning(wd-drop-menu-item): the type of open should be a boolean.')
}
if (newValue !== showPop.value) {
showPop.value = newValue
}
}
)

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