Skip to content

为 tabs 新增 slot nav-left & nav-right#1358

Open
GreatAuk wants to merge 3 commits intoMoonofweisheng:masterfrom
GreatAuk:tabs-slots
Open

为 tabs 新增 slot nav-left & nav-right#1358
GreatAuk wants to merge 3 commits intoMoonofweisheng:masterfrom
GreatAuk:tabs-slots

Conversation

@GreatAuk
Copy link
Contributor

@GreatAuk GreatAuk commented Nov 6, 2025

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

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

发布说明

  • New Features

    • Tabs 组件新增 nav-leftnav-right 插槽,支持在导航区域左右两侧自定义内容。
    • 优化标签页激活指示线的定位逻辑,提升视觉准确性。
  • Documentation

    • 新增 Tabs 组件插槽使用示例和文档说明。
    • 补充中英文本地化翻译。
  • Tests

    • 新增导航插槽渲染功能的测试用例。

@netlify
Copy link

netlify bot commented Nov 6, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 60f0298
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/690c4ea5fb698e000801bd06
😎 Deploy Preview https://deploy-preview-1358--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 project configuration.

@vercel
Copy link

vercel bot commented Nov 6, 2025

@GreatAuk is attempting to deploy a commit to the weisheng's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

概览

此改动向 Tabs 组件添加了 nav-leftnav-right 插槽以支持自定义导航区域,并更新了下划线定位逻辑。同时补充了中英文本地化翻译、文档示例、组件测试和演示页面。

改动

内聚类 / 文件 改动摘要
组件核心
src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue
在模板中添加 nav-leftnav-right 插槽;修改下划线定位计算逻辑,从原有的前置宽度叠加改为使用 previousItemsWidth + firstItemLeft + 当前项宽度的一半 的新算法
文档与示例
docs/component/tabs.md, src/subPages/tabs/Index.vue
新增插槽演示文档块(展示 nav-left 和 nav-right 用法);在演示页面添加新的 tab12 标签组示例,包含自定义导航插槽和对应样式 .tab-nav-slot
本地化
src/locale/en-US.json, src/locale/zh-CN.json
新增 cha-cao-yan-shi(插槽演示)的中英文本地化条目
测试
tests/components/wd-tabs.test.ts
新增两个测试用例验证左右导航插槽(#nav-left#nav-right)的渲染和内容

时序图

sequenceDiagram
    participant User as 用户
    participant Tabs as Tabs 组件
    participant Slot as 插槽(nav-left/right)
    
    User->>Tabs: 点击标签项
    Tabs->>Tabs: 计算新的下划线位置<br/>previousItemsWidth + firstItemLeft<br/>+ 当前项宽度/2
    Tabs->>Tabs: 更新下划线平移距离
    Note over Tabs: 新增:导航左/右插槽<br/>支持自定义内容
    Slot-->>Tabs: 渲染自定义导航区域
    Tabs-->>User: 显示新位置的下划线<br/>与自定义导航区
Loading

代码审查工作量估计

🎯 3 (中等复杂度) | ⏱️ ~25 分钟

需要重点关注的区域:

  • 下划线定位逻辑变更 (wd-tabs.vue):新的计算公式 previousItemsWidth + firstItemLeft + 当前项宽度/2 需要验证在各种场景(粘性模式、非粘性模式、不同 tab 宽度)下的正确性
  • 插槽集成 (wd-tabs.vue):确保 nav-leftnav-right 插槽在两种模板模式下都正确渲染且不影响原有布局
  • 演示页面样式 (src/subPages/tabs/Index.vue):验证 .tab-nav-slot 类的样式逻辑与插槽内容的交互是否符合预期
  • 测试覆盖 (wd-tabs.test.ts):新增测试是否充分覆盖插槽内容的渲染情况,建议检查边界场景

可能相关的 PR

  • PR #679:同样修改了 wd-tabs 组件的下划线/线条布局逻辑,涉及 updateLineStyle 和宽度计算
  • PR #718:涉及 wd-tabs 组件的线条定位和 updateLineStyle 的修改及模板绑定更新
  • PR #733:修改了 wd-tabs.vue 中的 tab 指示器/线条定位逻辑,涉及激活时序和线条动画调整

建议审查者

  • Moonofweisheng

诗歌

🐰 插槽绽放在标签间,
左右导航任君裁。
下划线起舞新轨迹,
测试齐备笑靥开。
文档双语话悠长。 ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题清晰准确地总结了主要变更:为tabs组件新增nav-left和nav-right两个slot功能,完全对应changeset中的核心改动。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

🧹 Nitpick comments (1)
tests/components/wd-tabs.test.ts (1)

71-134: 建议增加更全面的测试覆盖

当前测试验证了插槽内容能够正确渲染,这是很好的基础测试。建议补充以下测试用例以提高覆盖率:

  1. 下划线在使用插槽时的位置是否正确
  2. 使用插槽时的滚动行为是否正常
  3. sticky 模式下插槽是否正常工作
  4. 切换标签时插槽内容保持不变

示例测试用例:

test('使用插槽时下划线位置正确', async () => {
  const wrapper = mount(
    {
      template: `
        <wd-tabs v-model="activeTab">
          <template #nav-left>
            <view style="width: 50px;">左侧</view>
          </template>
          <wd-tab title="标签1">内容1</wd-tab>
          <wd-tab title="标签2">内容2</wd-tab>
        </wd-tabs>
      `,
      data() {
        return { activeTab: 0 }
      }
    },
    {
      global: { components: globalComponents }
    }
  )

  await nextTick()
  
  // 验证下划线样式包含 transform 属性
  const line = wrapper.find('.wd-tabs__line')
  expect(line.attributes('style')).toContain('transform')
})
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c315a9 and 60f0298.

📒 Files selected for processing (6)
  • docs/component/tabs.md (2 hunks)
  • src/locale/en-US.json (1 hunks)
  • src/locale/zh-CN.json (1 hunks)
  • src/subPages/tabs/Index.vue (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue (5 hunks)
  • tests/components/wd-tabs.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-11-24T06:12:44.418Z
Learnt from: Moonofweisheng
Repo: Moonofweisheng/wot-design-uni PR: 733
File: src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue:327-327
Timestamp: 2024-11-24T06:12:44.418Z
Learning: 在 `src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue` 中,由于 `title` 可能会发生变化,涉及到 `title` 的优化不太容易实现,需谨慎处理。

Applied to files:

  • tests/components/wd-tabs.test.ts
  • src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue
  • docs/component/tabs.md
  • src/subPages/tabs/Index.vue
🪛 markdownlint-cli2 (0.18.1)
docs/component/tabs.md

338-338: Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Generate Test Summary
🔇 Additional comments (8)
src/locale/en-US.json (1)

212-212: LGTM!

新增的国际化翻译条目格式正确,翻译准确,符合项目规范。

src/locale/zh-CN.json (1)

211-211: LGTM!

中文翻译准确,与英文翻译键一致。

src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue (2)

13-13: 插槽位置需确认

nav-left 插槽被放置在 scroll-view 内部,这意味着当标签数量较多需要滚动时,左侧插槽内容也会随之滚动。请确认这是否为预期行为:

  • 如果左侧内容应该始终可见(如筛选按钮),建议将插槽移到 scroll-view 外部
  • 如果左侧内容应该随标签一起滚动,则当前实现正确

相同的问题也适用于第 28 行(sticky 模式)、第 85 行和第 99 行(非 sticky 模式)的 nav-right 插槽。


333-337: 验证下划线位置计算在插槽场景中的表现

代码逻辑本身正确。新的计算方式通过 rects[0]?.left 自动适配导航插槽:当 nav-left 插槽存在时,第一个标签的 left 值会自动包含插槽宽度;当无插槽时为 0。

但是,当前测试用例缺乏下划线位置相关的验证,建议在以下场景中手动验证下划线位置准确性:

  1. 没有使用插槽时
  2. 只使用 nav-left 插槽时
  3. 只使用 nav-right 插槽时
  4. 同时使用两个插槽时

特别注意:在 title 或插槽内容动态变化时,确保 updateLineStyle 正确更新位置。

docs/component/tabs.md (2)

204-237: LGTM!

插槽演示文档清晰完整,示例代码易于理解,SCSS 样式也包含在内,便于开发者参考使用。


337-342: 需要替换版本占位符并修复格式问题

存在两个需要修复的问题:

  1. 版本占位符:第 340-341 行使用了 $LOWEST_VERSION$ 占位符,需要替换为实际的版本号(如 1.4.1 或其他合适的版本号)

  2. Markdown 格式:根据 markdownlint 提示,表格前后需要空行。建议在第 337 行之前和第 342 行之后各添加一个空行。

应用以下修改:

+
 ## Tabs Slots
 | name   | 说明                 | 参数                    | 最低版本 |
 | ------ | -------------------- | ----------------------- | -------- |
-| nav-left | 标签栏左侧内容         | - | $LOWEST_VERSION$   |
-| nav-right | 标签栏右侧内容         | - | $LOWEST_VERSION$   |
+| nav-left | 标签栏左侧内容         | - | 1.4.1   |
+| nav-right | 标签栏右侧内容         | - | 1.4.1   |
+
⛔ Skipped due to learnings
Learnt from: Moonofweisheng
Repo: Moonofweisheng/wot-design-uni PR: 733
File: src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue:327-327
Timestamp: 2024-11-24T06:12:44.418Z
Learning: 在 `src/uni_modules/wot-design-uni/components/wd-tabs/wd-tabs.vue` 中,由于 `title` 可能会发生变化,涉及到 `title` 的优化不太容易实现,需谨慎处理。
Learnt from: chen-ziwen
Repo: Moonofweisheng/wot-design-uni PR: 910
File: docs/component/input-number.md:155-155
Timestamp: 2025-02-20T13:33:37.038Z
Learning: Documentation files in wot-design-uni use `$LOWEST_VERSION$` as a placeholder that gets automatically replaced with the actual version number during the release process. These placeholders should not be flagged as issues.
Learnt from: chen-ziwen
Repo: Moonofweisheng/wot-design-uni PR: 909
File: docs/component/input-number.md:155-155
Timestamp: 2025-02-20T05:58:07.379Z
Learning: In documentation files, `$LOWEST_VERSION$` placeholder is automatically replaced with the actual version number during the release process, and should not be manually updated.
src/subPages/tabs/Index.vue (2)

126-144: LGTM!

插槽演示实现清晰,使用了有意义的图标(筛选和添加),能够很好地展示导航插槽的实际应用场景。与其他演示的集成也很流畅。


261-268: LGTM!

.tab-nav-slot 样式实现合理:

  • 使用 align-self: stretch 使插槽区域垂直填充
  • flex-shrink: 0 防止插槽内容被压缩
  • inline-flex 和居中对齐确保图标正确显示

样式设计考虑周到。

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