Skip to content

Comments

fix(cascader): 选中后 tab 应展示 text 字段的值#3167

Merged
xiaoyatong merged 1 commit intojdf2e:feat_v3.xfrom
oasis-cloud:fix/cascader_410
Apr 11, 2025
Merged

fix(cascader): 选中后 tab 应展示 text 字段的值#3167
xiaoyatong merged 1 commit intojdf2e:feat_v3.xfrom
oasis-cloud:fix/cascader_410

Conversation

@oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Apr 10, 2025

Summary by CodeRabbit

  • 新功能

    • 优化级联选择组件的标签页标题显示,现在可以展示更具描述性的文本,提升了界面信息的清晰度。
  • 重构

    • 在示例中,将选项的标识值从中文转换为拼音,实现数据标识的一致性和国际化。

@coderabbitai
Copy link

coderabbitai bot commented Apr 10, 2025

Walkthrough

本次变更主要针对 Cascader 组件的数据结构和展示逻辑进行了优化。两个版本(taro 与非 taro)均在计算 levels 数组时新增了 selectedText 属性,该属性基于匹配到的选项的 text 值,用于替换原有的 Tab 标题展示。同时,部分演示文件中的选项数据也由中文值更新为拼音,保证了数据的一致性。

Changes

文件 变更摘要
src/packages/cascader/cascader.taro.tsx
src/packages/cascader/cascader.tsx
在 levels 数组中新增 selectedText 属性,通过选项的 text 值进行赋值,并在 Tabs.TabPane 中用于展示标题。
src/packages/cascader/demos/h5/demo1.tsx
src/packages/cascader/demos/taro/demo1.tsx
将选项中的 value 值从中文改为拼音(如 '浙江' → 'ZheJiang' 等)。
src/packages/cascader/demos/h5/demo2.tsx
src/packages/cascader/demos/taro/demo2.tsx
更新初始状态和 options 结构中 value/value1 字段,将中文转换为拼音,以统一数据格式。

Possibly related PRs

Suggested reviewers

  • Alex-huxiyang
  • irisSong

Poem

我是小兔跳跃轻快,
代码变更一丝不苟在徘徊。
选项文本由中至英转变,
Tab 显示更添精彩。
静待审查共创未来🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cc94ce3 and 0f26a38.

📒 Files selected for processing (6)
  • src/packages/cascader/cascader.taro.tsx (2 hunks)
  • src/packages/cascader/cascader.tsx (2 hunks)
  • src/packages/cascader/demos/h5/demo1.tsx (1 hunks)
  • src/packages/cascader/demos/h5/demo2.tsx (1 hunks)
  • src/packages/cascader/demos/taro/demo1.tsx (1 hunks)
  • src/packages/cascader/demos/taro/demo2.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (9)
src/packages/cascader/cascader.tsx (2)

101-103: 添加了 selectedText 属性以改进 Tab 显示

这个更改增加了 selectedText 属性,用于存储选中选项的文本值。这是一个很好的改进,它允许在 Tab 中显示更有意义的文本。


269-272: 改进了 Tab 标题显示逻辑

之前 Tab 标题可能显示的是值而不是文本,现在使用 pane.selectedText || locale.select 作为标题,确保显示的是选项的文本值。这直接解决了 PR 中提到的问题,使用户界面更加友好。

src/packages/cascader/demos/taro/demo1.tsx (1)

15-15: 统一了选项值的格式

将选项的 value 属性从中文改为拼音(如 '浙江' 改为 'ZheJiang'),同时保留了 text 属性的中文显示。这种方式使数据结构更加一致,并且可以更好地支持国际化。

Also applies to: 19-20, 23-24, 28-29, 31-32

src/packages/cascader/demos/h5/demo2.tsx (2)

6-6: 更新了默认值以匹配新的数据格式

将默认值从中文更新为对应的拼音格式,确保与更新后的选项数据结构一致。这是一个必要的变更,确保示例能正确工作。


12-13: 统一了选项的 value 格式

将选项的 value1 属性从中文改为拼音表示,同时保留了 text1 属性的中文显示。这种方式使数据结构更加一致,并支持内部代码的新变更。

Also applies to: 16-17, 20-21, 25-26, 28-29

src/packages/cascader/demos/h5/demo1.tsx (1)

16-17: 统一了选项值的格式

将选项的 value 属性从中文改为拼音(如 '浙江' 改为 'ZheJiang'),同时保留了 text 属性的中文显示。这种改变与其他示例文件保持一致,确保了整个组件库的数据格式统一。

Also applies to: 20-21, 24-25, 29-30, 32-33

src/packages/cascader/demos/taro/demo2.tsx (1)

6-6: 优化了组件的数据结构

这次修改将中文地名的值替换为拼音形式,同时保留了中文显示文本。这种分离有助于提高代码可读性和值的一致性,使值更适合在代码中使用,同时保持了用户界面上的中文显示。

Also applies to: 12-12, 16-16, 20-21, 25-25, 28-29

src/packages/cascader/cascader.taro.tsx (2)

103-103: 为级联选择器添加了显示文本属性

通过添加selectedText属性,从匹配到的选项中获取text值,使后续在Tab中可以展示更友好的文本而非内部值。这是一个很好的用户体验改进。


274-277: 改进了标签页标题的显示逻辑

将Tab标签的标题从原来显示selected值改为显示selectedText,当没有选中项时会显示locale.select作为默认文本。这种改进使界面更加用户友好,显示的是人类可读的文本而非可能难以理解的内部值。

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@github-actions github-actions bot added 3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) labels Apr 10, 2025
@oasis-cloud oasis-cloud linked an issue Apr 10, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.20%. Comparing base (cc94ce3) to head (0f26a38).
Report is 1 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #3167      +/-   ##
=============================================
+ Coverage      87.18%   87.20%   +0.01%     
=============================================
  Files            279      279              
  Lines          18537    18540       +3     
  Branches        2820     2822       +2     
=============================================
+ Hits           16161    16167       +6     
+ Misses          2371     2368       -3     
  Partials           5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xiaoyatong xiaoyatong merged commit 79a9900 into jdf2e:feat_v3.x Apr 11, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cascader 组件数据回显异常

2 participants