Skip to content

feat(switch): 支持 circle/round/line 三种 shape - #2651

Open
shide-chuanzhang wants to merge 1 commit into
Tencent:developfrom
shide-chuanzhang:feat/switch-shape
Open

feat(switch): 支持 circle/round/line 三种 shape#2651
shide-chuanzhang wants to merge 1 commit into
Tencent:developfrom
shide-chuanzhang:feat/switch-shape

Conversation

@shide-chuanzhang

@shide-chuanzhang shide-chuanzhang commented Jul 30, 2026

Copy link
Copy Markdown

对应 issue #2563,给 Switch 加了 shape 属性,支持 circle(默认)、round、line 三种。

round 比较简单,改了 track 和 handle 的圆角就行。

line 做了一些单独处理。选中态轨道用半透明品牌色而不是实色,因为 line 整体偏轻,实色蓝会显得太重。handle 加了 1px border,这样禁用态去掉 shadow 后边缘还是清晰的,不用给禁用态单独写一套。颜色定制走 CSS 变量,暴露了四个变量,运行时覆盖就能换色,不用加 checkedColor 这种 prop。另外补了 :focus-visible,现有组件 outline: none 键盘用不了。暗色模式在支持 color-mix() 的浏览器里自动跟随品牌色。

只改了 style 下的 _var.less 和 _index.less。组件代码(React)在 tdesign-react 仓库,对应 PR tdesign-react#4342。

line 形态做了几个单独处理:
- 选中态轨道用半透明品牌色,line 整体偏轻,实色太重
- handle 加 1px border,禁用态去掉 shadow 后边缘仍清晰
- 暴露 CSS 变量,运行时定制轨道色不用加 prop
- 补了 :focus-visible,键盘能切到开关
- line 不渲染 content DOM,从 label 推导 aria-label

round 改了 track 和 handle 的圆角。

issue Tencent#2563
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.

2 participants