Skip to content

Commit 8fd85e5

Browse files
committed
feat(ui): Button 补 style 透传以对齐 Text/Surface
1 parent 67651b8 commit 8fd85e5

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎app/src/ui/primitives/Button.test.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,16 @@ describe("Button 透传与内容", () => {
199199
expect(cls).toContain("my-slot");
200200
expect(cls).toContain("ed-btn");
201201
});
202+
203+
it("style 纯透传且不影响类名顺序(与 Text/Surface 同一写法;视觉权威仍在类)", () => {
204+
const { container } = render(<Button className="my-slot" style={{ marginTop: 4 }}>x</Button>);
205+
expect(root(container).style.marginTop).toBe("4px");
206+
expect(root(container).className).toBe("ed-btn ed-btn--secondary ed-btn--md my-slot");
207+
});
202208
});
203209

204210
describe("Button 反例守门(批 6 要一处改对所有地方)", () => {
205-
it("四态与位移**只走类**,绝不落内联 style", () => {
211+
it("四态与位移**只走类**:不传 style 时不产生任何内联样式", () => {
206212
const el = root(
207213
render(<Button variant="primary" size="lg" block disabled>x</Button>).container,
208214
);

‎app/src/ui/primitives/Button.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
* 这一行即可,CSS 的 `:disabled` 分支与测试不受影响。
2222
* ② 不可用时**不派发 `onClick`**:`busy` 没有原生 `disabled` 替我们拦截,click 仍会到达 ⇒ 处理器
2323
* 显式 `preventDefault()` 后返回(顺带挡住 `type="submit"` 的隐式表单提交)。
24-
* ③ 四态与位移**只出类名、不出内联 style**(否则批 6 只能逐处改)。本组件**不提供 `style` 参数**
25-
* —— 计划的 Produces 未列它,且样式一律走类(唯一例外是 z-index 走 `zIndex()` 标尺,本组件不涉)。
24+
* ③ 四态与位移**只出类名、不出内联 style**(否则批 6 只能逐处改)。`style` 是**纯透传**
25+
* (与 `Text` / `Surface` 逐字同一写法,控制方 2026-09-11 裁决补入):本组件**没有基类内联
26+
* style**,故不存在合并与顺序问题 —— 调用点传什么就是什么。视觉权威仍在类:调用点若用
27+
* `style` 去覆盖四态的底色/位移,等于把批 6 的"一处改对所有地方"重新打散(那正是本批要消灭的形态)。
2628
* ④ **不加 `tabIndex` / `role`**:它是**真实 `<button>`**,Tab 到达与 Enter/Space 激活由浏览器免费
2729
* 提供(现状全仓 `tabIndex` 仅 1 处、大量可点 `<div>` 不可键盘到达,见 recon §8.2 与 §8.6.1 第 4 条)。
2830
* ⑤ **无 `danger` 变体**:危险语义由 `ConfirmDialog` 的印章标记 + 级联影响清单承载,按钮保持中性
@@ -31,7 +33,7 @@
3133
* 类名,而该类名不在 `motion.css` 的 reduced-motion 基类名单里,会给 Task 14 的守卫制造假红。
3234
*/
3335

34-
import type { MouseEvent, ReactElement, ReactNode } from "react";
36+
import type { CSSProperties, MouseEvent, ReactElement, ReactNode } from "react";
3537
import "./Button.css";
3638

3739
/** 三档变体:`primary` 墨底(主行动)· `secondary` 纸底(默认)· `ghost` 透明(工具条 / 关闭) */
@@ -63,6 +65,8 @@ export interface ButtonProps {
6365
icon?: ReactNode;
6466
/** 追加类名(调用点只做定位,不参与按钮的视觉权威) */
6567
className?: string;
68+
/** 透传内联样式(纯透传:调用点布局微调、批 6 的动效接缝;**视觉一律由类决定**) */
69+
style?: CSSProperties;
6670
/** 落到 `data-testid`;不传时不产生该属性 */
6771
testId?: string;
6872
}
@@ -85,6 +89,7 @@ export function Button({
8589
title,
8690
icon,
8791
className,
92+
style,
8893
testId,
8994
}: ButtonProps): ReactElement {
9095
const unavailable = disabled || busy;
@@ -117,6 +122,7 @@ export function Button({
117122
aria-disabled={unavailable ? true : undefined}
118123
aria-busy={busy ? true : undefined}
119124
title={title}
125+
style={style}
120126
data-testid={testId}
121127
>
122128
{icon}

0 commit comments

Comments
 (0)