Skip to content

style(Switch): support round and line shapes#2604

Open
Seeridia wants to merge 2 commits into
Tencent:developfrom
Seeridia:feat/switch-shape
Open

style(Switch): support round and line shapes#2604
Seeridia wants to merge 2 commits into
Tencent:developfrom
Seeridia:feat/switch-shape

Conversation

@Seeridia

@Seeridia Seeridia commented Jul 2, 2026

Copy link
Copy Markdown

犀牛鸟 Issue,关联 Issue: /issues/2563

fix #2563

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

Related issue: #2563

💡 需求背景和解决方案

为 Switch 增加多形态外观支持,配合组件库侧新增的 shape API:

  • circle:默认胶囊形态,继续沿用当前基础样式,不改变既有视觉。
  • round:圆角矩形形态。
  • line:线性形态。

相关 PR:

  1. tdesign-api:feat(Switch): add shape api for web TDesignOteam/tdesign-api#914
  2. tdesign-common:style(Switch): support round and line shapes #2604
  3. tdesign-vue-next:feat(Switch): support shape prop tdesign-vue-next#6776
  4. tdesign-react:feat(Switch): support shape prop tdesign-react#4320
  5. Tdsign-vue:feat(Switch): support shape prop tdesign-vue#3855

设计稿:https://www.figma.com/design/r9jPY6A4EUDvEdoWQ1LVxe/TDesign-for-web--Community----Select?node-id=45757-378235&t=5X597ofKeSefwy0q-1

image

📝 更新日志

  • feat(Switch): 新增 Web Switch roundline 形态样式

  • 本条 PR 不需要纳入 Changelog

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

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

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

Copilot AI review requested due to automatic review settings July 2, 2026 13:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds new Switch visual “shape” variants (round, line) to the common Web styles and exposes a corresponding “Different Shapes” example entry in the Switch API docs, aligning with upstream component libraries’ new shape API.

Changes:

  • Added Switch shape-related design tokens (Less variables) for round and line.
  • Implemented .t-switch--shape-round and .t-switch--shape-line styling, including size variants for line.
  • Extended Switch API docs (ZH/EN) with a “Different Shapes” section and {{ shape }} example placeholder.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
style/web/components/switch/_var.less Adds design tokens for round/line shapes (widths, radii, track/handle sizing).
style/web/components/switch/_index.less Adds concrete CSS rules for --shape-round and --shape-line (including size L/S variants).
docs/web/api/switch.md Adds “不同形状的开关” section and {{ shape }} placeholder.
docs/web/api/switch.en-US.md Adds “Switches of Different Shapes” section and {{ shape }} placeholder.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread style/web/components/switch/_index.less
Comment thread style/web/components/switch/_var.less
Comment thread style/web/components/switch/_var.less
Comment thread docs/web/api/switch.en-US.md Outdated
@Seeridia

Seeridia commented Jul 2, 2026

Copy link
Copy Markdown
Author

另外有一个问题可能需要指导一下:

目前的 Line 样式的开关的滑块 Thumb 的无障碍上的对比度问题,原先在 loadingdisabled 下是无阴影的,这造成了 Thumb 在白色背景下可读性不佳,而就算(目前我的做法)加上 @shadow-1 依然不够深,白色背景下对比度并不够(因为没有了 bg 的背景色)

可以见 https://www.figma.com/design/r9jPY6A4EUDvEdoWQ1LVxe/TDesign-for-web--Community----Select?node-id=45757-378235&t=5X597ofKeSefwy0q-1 的设计稿,也可以在各个组件库的 PR 中查看效果(比如 Tencent/tdesign-vue-next#6776
image

所以需要更强的阴影。但是如果从 @shadow-1 改成 @shadow-2 不符合 td 的设计规范,这边需要商榷讨论一下。个人建议是定义 @switch-line-handle-shadow: @shadow-1, 0 0 0 1px rgba(0, 0, 0, 6%); 额外定义一个更强的阴影

@Seeridia

Seeridia commented Jul 2, 2026

Copy link
Copy Markdown
Author

另外,原 issue 有用户评论:#2563 (comment)

同样想要顶一下楼主的这个需求,目前的确switch的可自定义设定太少了,建议可以参考一下arco的模式,对外开放checked-color和 unchecked-color,方便对组件的显示状态进行自定义

本次我没有实现,需要评估一下是否需要实现,如有需要,我这边同步跟进

@Wesley-0808

Copy link
Copy Markdown
Collaborator

另外,原 issue 有用户评论:#2563 (comment)
本次我没有实现,需要评估一下是否需要实现,如有需要,我这边同步跟进

此pr不必完成额外的内容,用户也可通过style自行覆盖需要的颜色,在组件内实现也是差不多的做法
image

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.

[Switch] 支持方形等外观设计

3 participants