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: tabs 代码简化,调整部分样式 #2949

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

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Jan 16, 2025

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

发布说明

  • 新功能

    • 更新了选项卡组件的标签标题和内容
    • 为选项卡组件添加了新的样式和布局选项
  • 样式调整

    • 优化了选项卡的水平和垂直布局
    • 改进了选项卡的活动状态和禁用状态样式
    • 调整了选项卡滚动和溢出行为
  • 性能优化

    • 简化了选项卡组件的状态管理
    • 优化了组件的渲染逻辑和事件处理
  • 兼容性改进

    • 为右到左(RTL)布局添加了样式支持
    • 增强了跨平台组件的一致性

Copy link

coderabbitai bot commented Jan 16, 2025

概述

演练

这个拉取请求(PR)主要涉及对 Tabs 和 TabPane 组件的多个文件进行修改。更改包括在多个演示文件中将第一个标签页的标题从 "Tab 1" 更改为 "Tab longitem",在 Taro 和 H5 环境下的演示文件都有此修改。同时,对 tabpane.taro.tsx 文件进行了组件渲染方式的调整,使用 Taro 的 View 组件替代了原生 div 元素。

变更

文件 变更摘要
src/packages/tabpane/tabpane.taro.tsx 新增 View 组件导入,替换 divView
src/packages/tabpane/tabpane.tsx 简化条件渲染逻辑
src/packages/tabs/tabs.scss 调整标签页样式,增加水平和垂直布局支持
src/packages/tabs/tabs.taro.tsx 简化状态管理和事件处理逻辑
src/packages/tabs/tabs.tsx 优化类型安全和代码结构
多个 demos 文件 更新标签页标题和内容

可能相关的 PR

建议标签

size/M, 3.x

建议审阅者

irisSong

诗歌

🐰 标签跳跃,长项变幻
视图轻舞,代码飞翔
一行改变,千重意象
Tabs 起舞,兔子欢唱!
🎉 代码之美,在于蜕变


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 2

🔭 Outside diff range comments (1)
src/packages/tabs/__test__/tabs.spec.tsx (1)

Line range hint 19-29: 需要修复测试失败!

测试期望元素具有 'nut-tabs-titles-scrollable' 类,但实际上只有 'nut-tabs-titles nut-tabs-titles-smile'。这可能是由于最近的样式调整导致的回归问题。

建议修复方案:

- <Tabs value="0" direction="horizontal" activeType="smile">
+ <Tabs value="0" direction="horizontal" activeType="smile" scrollable>
🧹 Nitpick comments (3)
src/packages/tabs/demos/h5/demo16.tsx (1)

14-14: 建议改进标签页内容和无障碍性

建议:

  1. 标签页的内容应该是有意义的,而不是简单地重复标题
  2. 为了提高无障碍性,考虑添加 aria-label 属性来描述标签页的用途
- <Tabs.TabPane title="第一名top1">第一名top1</Tabs.TabPane>
+ <Tabs.TabPane 
+   title="第一名top1" 
+   aria-label="展示排名第一的商品信息"
+ >
+   {/* 这里添加实际的商品内容 */}
+   <div>商品详情内容...</div>
+ </Tabs.TabPane>
src/packages/tabs/tabs.tsx (1)

189-191: 建议优化性能!

可以考虑使用 useCallback 优化 tabChange 回调函数,避免不必要的重渲染。

+ const memoizedTabChange = useCallback((item: TabsTitle) => {
+   onClick?.(item.value)
+   if (!item.disabled) {
+     setValue(item.value)
+   }
+ }, [onClick, setValue])

  return (
    ...
-   onClick={() => tabChange(item)}
+   onClick={() => memoizedTabChange(item)}
    ...
  )

Also applies to: 201-205

src/packages/tabs/tabs.taro.tsx (1)

227-230: 建议使用可选链操作符

可以使用可选链操作符来简化代码:

-  onClick && onClick(item.value)
+  onClick?.(item.value)
🧰 Tools
🪛 Biome (1.9.4)

[error] 229-230: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 16fb6e5 and 8b76ec0.

📒 Files selected for processing (42)
  • src/packages/tabpane/tabpane.taro.tsx (2 hunks)
  • src/packages/tabpane/tabpane.tsx (1 hunks)
  • src/packages/tabs/__test__/tabs.spec.tsx (8 hunks)
  • src/packages/tabs/demos/h5/demo1.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo10.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo11.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo12.tsx (2 hunks)
  • src/packages/tabs/demos/h5/demo13.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo14.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo16.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo2.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo20.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo21.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo22.tsx (2 hunks)
  • src/packages/tabs/demos/h5/demo3.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo4.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo5.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo6.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo7.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo8.tsx (1 hunks)
  • src/packages/tabs/demos/h5/demo9.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo1.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo10.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo11.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo12.tsx (2 hunks)
  • src/packages/tabs/demos/taro/demo13.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo14.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo16.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo2.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo20.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo21.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo22.tsx (2 hunks)
  • src/packages/tabs/demos/taro/demo3.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo4.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo5.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo6.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo7.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo8.tsx (1 hunks)
  • src/packages/tabs/demos/taro/demo9.tsx (1 hunks)
  • src/packages/tabs/tabs.scss (10 hunks)
  • src/packages/tabs/tabs.taro.tsx (8 hunks)
  • src/packages/tabs/tabs.tsx (5 hunks)
✅ Files skipped from review due to trivial changes (31)
  • src/packages/tabs/demos/h5/demo5.tsx
  • src/packages/tabs/demos/h5/demo10.tsx
  • src/packages/tabs/demos/h5/demo14.tsx
  • src/packages/tabs/demos/h5/demo3.tsx
  • src/packages/tabs/demos/h5/demo7.tsx
  • src/packages/tabs/demos/h5/demo1.tsx
  • src/packages/tabs/demos/h5/demo6.tsx
  • src/packages/tabs/demos/taro/demo5.tsx
  • src/packages/tabs/demos/taro/demo10.tsx
  • src/packages/tabs/demos/taro/demo6.tsx
  • src/packages/tabs/demos/taro/demo4.tsx
  • src/packages/tabs/demos/h5/demo8.tsx
  • src/packages/tabs/demos/h5/demo2.tsx
  • src/packages/tabs/demos/taro/demo2.tsx
  • src/packages/tabs/demos/h5/demo9.tsx
  • src/packages/tabs/demos/taro/demo9.tsx
  • src/packages/tabs/demos/h5/demo21.tsx
  • src/packages/tabs/demos/taro/demo13.tsx
  • src/packages/tabs/demos/taro/demo8.tsx
  • src/packages/tabs/demos/taro/demo1.tsx
  • src/packages/tabs/demos/taro/demo14.tsx
  • src/packages/tabs/demos/h5/demo22.tsx
  • src/packages/tabs/demos/taro/demo21.tsx
  • src/packages/tabs/demos/taro/demo20.tsx
  • src/packages/tabs/demos/h5/demo4.tsx
  • src/packages/tabs/demos/taro/demo7.tsx
  • src/packages/tabs/demos/taro/demo3.tsx
  • src/packages/tabs/demos/h5/demo12.tsx
  • src/packages/tabs/demos/taro/demo11.tsx
  • src/packages/tabs/demos/taro/demo22.tsx
  • src/packages/tabs/demos/h5/demo20.tsx
🧰 Additional context used
🪛 GitHub Actions: CI
src/packages/tabs/__test__/tabs.spec.tsx

[error] 29-29: Test failed: Expected element to have class 'nut-tabs-titles-scrollable' but received 'nut-tabs-titles nut-tabs-titles-smile'

🪛 Biome (1.9.4)
src/packages/tabs/tabs.taro.tsx

[error] 229-230: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (17)
src/packages/tabs/demos/taro/demo16.tsx (1)

14-14: 参考 H5 版本的改进建议

此处存在与 H5 版本相同的问题,请参考上述建议进行相应修改。

src/packages/tabs/demos/taro/demo12.tsx (1)

17-17: 代码变更看起来没有问题!

标签文本从 "Tab 1" 更改为 "Tab longitem" 的修改保持了一致性。

Also applies to: 31-31

src/packages/tabs/demos/h5/demo13.tsx (1)

16-25: 文本更新保持一致性,没有问题!

所有 "Tab 1" 文本都已统一更新为 "Tab longitem",保持了整体一致性。

src/packages/tabs/__test__/tabs.spec.tsx (1)

10-10: 文本更新保持一致性,没有问题!

测试用例中的标签文本已统一更新。

Also applies to: 19-20, 35-36, 47-47, 74-75, 90-90, 96-97, 123-124, 148-149, 157-158

src/packages/tabs/tabs.tsx (4)

45-45: 类型安全性改进很好!

  • 使用 Partial<TabsProps> 提高了类型灵活性
  • 参数类型从 any 改为 HTMLDivElement 增强了类型安全性

Also applies to: 66-66, 73-73, 76-76, 78-80


86-89: 代码简化得更清晰了!

使用箭头函数重构 animate 函数使代码更简洁。


177-179: 逻辑优化更合理!

通过先检查 disabled 状态再设置值,避免了不必要的状态更新。


231-239: 代码结构优化很好!

优化了子组件的条件渲染逻辑,提高了代码可读性。

src/packages/tabs/tabs.taro.tsx (4)

70-71: 代码简化获得认可!

Props 解构的简化提高了代码的可读性。


84-86: 代码健壮性改进!

通过使用 React.isValidElement 进行适当的子元素检查,提高了代码的可靠性。


249-251: 样式处理优化!

直接传递 tabStyle 属性使代码更加清晰和易于维护。


303-311: 类型安全性提升!

改进了子组件的处理方式,增强了类型检查并优化了属性传递。

src/packages/tabs/demos/h5/demo11.tsx (1)

14-15: 示例更新合理!

标签文本从 "Tab 1" 更改为 "Tab longitem" 使示例更加清晰,并与其他示例保持一致。

src/packages/tabs/tabs.scss (4)

8-18: 布局样式优化!

  • 新增水平布局类提升了组件的灵活性
  • 改进了溢出处理,优化了滚动体验

Line range hint 103-138: 状态样式改进!

  • 优化了激活状态的视觉反馈
  • 统一了禁用状态的样式处理

329-339: RTL 支持完善!

添加了全面的从右到左布局支持,确保了组件在不同书写方向下的正确显示。


320-327: 内容区域样式优化!

新增的内容包装器类改善了布局结构和溢出处理。

return children ? (
<div className={classes}>{!disabled && children}</div>
) : null
return children && <div className={classes}>{!disabled && children}</div>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议优化条件渲染逻辑

当前实现存在以下问题:

  1. 条件渲染逻辑可能不够直观
  2. disabled 状态的处理方式可能导致不一致的渲染结果

建议重构为更清晰的实现:

- return children && <div className={classes}>{!disabled && children}</div>
+ if (!children) return null
+ return (
+   <div className={classes}>
+     {disabled ? (
+       <div className={`${classPrefix}__disabled`}>
+         {children}
+       </div>
+     ) : children}
+   </div>
+ )

Committable suggestion skipped: line range outside the PR's diff.

@@ -1,5 +1,6 @@
import React, { FunctionComponent } from 'react'
import classNames from 'classnames'
import { View } from '@tarojs/components'
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议统一组件引入方式并优化渲染逻辑

  1. 建议将组件引入语句与其他引入保持一致的顺序
  2. 渲染逻辑存在与 React 版本相同的问题
- import { View } from '@tarojs/components'
+ import type { View } from '@tarojs/components'
+ import { View } from '@tarojs/components'

  // ... 其他代码 ...

- return children && <View className={classes}>{!disabled && children}</View>
+ if (!children) return null
+ return (
+   <View className={classes}>
+     {disabled ? (
+       <View className={`${classPrefix}__disabled`}>
+         {children}
+       </View>
+     ) : children}
+   </View>
+ )

Also applies to: 41-41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant