Skip to content

feat: add wrapper root #159

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

wanpan11
Copy link

@wanpan11 wanpan11 commented Jun 13, 2025

添加一层节点,方便使用 flex 布局实现水平对齐

image

Summary by CodeRabbit

  • 新功能

    • 无新增功能。
  • 样式

    • 优化了样式文件的格式和变量书写方式,提升代码可读性。
    • Switch 组件外层新增了包裹标签,并调整了内部内容的排列顺序,实现更好的内容对齐和展示效果。
  • 测试

    • 更新了 Switch 组件的测试用例,提升了事件模拟的准确性。
  • 杂项

    • 新增了 React 类型声明依赖,优化依赖项顺序。

Copy link

coderabbitai bot commented Jun 13, 2025

"""

Walkthrough

本次更改主要调整了 Switch 组件的渲染结构和样式:在样式文件中为 Switch 外层新增了 flex 居中规则,并在组件渲染结构中增加了 label 包裹。测试用例也相应更新,事件模拟更精确地定位到 Switch 元素本身。

Changes

文件/分组 变更摘要
assets/index.less transition 时长格式规范化;新增 switch-wrapper 的 flex 居中规则;格式化与细节调整。
src/index.tsx Switch 组件外层新增 label 包裹,内部 children 排列结构调整。
tests/index.spec.js 事件模拟对象从根节点调整为 .rc-switch 元素,测试更精确。
package.json 依赖顺序调整,新增 @types/react,无功能性影响。

Sequence Diagram(s)

sequenceDiagram
    participant Form
    participant SwitchWrapper
    participant SwitchButton

    Form->>SwitchWrapper: 渲染 label.switch-wrapper
    SwitchWrapper->>SwitchButton: 渲染 button.rc-switch
    SwitchButton->>SwitchButton: 内部渲染 checked/unchecked children
Loading

Assessment against linked issues

Objective Addressed Explanation
Switch 和 label 在表单内未居中对齐(#54042)

Assessment against linked issues: Out-of-scope changes

无发现超出关联 issue 目标的更改。

Suggested reviewers

  • zombieJ

Poem

小兔挥爪理 Switch,
label 包裹样式齐,
Flex 居中真神奇,
表单对齐好欢喜。
测试定位更精细,
代码整洁皆如意!
🐰✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

tests/index.spec.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


📜 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 ef2e74e and d1d5b6b.

📒 Files selected for processing (1)
  • tests/index.spec.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/index.spec.js
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch wrapper
  • Post Copyable Unit Tests in 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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this 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

@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

🧹 Nitpick comments (4)
assets/index.less (1)

5-8: 新增 .rc-switch-wrapper 建议开放自定义 className / style

包装层采用 display: flex 可解决对齐,但目前只能通过固定类名 rc-switch-wrapper 选中。
如果业务侧需自定义 margin / theme,仍得写覆盖样式。可以考虑将 className 透传到 wrapper,或提供 wrapperClassName prop,增强扩展性。

tests/index.spec.js (3)

37-40: 保持用例一致性:其余 wrapper.simulate 也应定位到 .rc-switch

此处已改为 wrapper.find('.rc-switch'),但前面的 it('works')、键盘用例仍直接对根 wrapper 触发事件,结构变动后可能只点击到 <label>
为避免回归风险,建议统一全部事件触发目标。


45-50: 同上,保持事件触发一致性

同一测试块内多次选择器写法不同,最好提取变量或 helper,减少修改点。


120-122: mouseup 事件选取方式一致化

与 click 用例保持一致有助于阅读与维护。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 86b7162 and a4f7d8a.

📒 Files selected for processing (4)
  • assets/index.less (4 hunks)
  • package.json (1 hunks)
  • src/index.tsx (1 hunks)
  • tests/index.spec.js (2 hunks)

Copy link

socket-security bot commented Jun 14, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​react@​19.1.81001007896100

View full report

Copy link

codecov bot commented Jun 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.35%. Comparing base (86b7162) to head (ef2e74e).

Additional details and impacted files
@@             Coverage Diff              @@
##            master     #159       +/-   ##
============================================
- Coverage   100.00%   82.35%   -17.65%     
============================================
  Files            1        1               
  Lines           34       34               
  Branches         8        8               
============================================
- Hits            34       28        -6     
- Misses           0        4        +4     
- Partials         0        2        +2     

☔ 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.

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.

The Switch and label inside the Form are not centered
1 participant