diff --git a/apps/taro/src/app.css b/apps/taro/src/app.css index 05126d3..51fd47f 100644 --- a/apps/taro/src/app.css +++ b/apps/taro/src/app.css @@ -1,5 +1,9 @@ page { background: #fafaf9; +} +/* H5 渲染树里没有 page 元素,令牌必须同时声明在真实根节点 body 上,双端按钮高度才一致。 */ +page, +body { --brand-button-height: 88px; --brand-button-compact-height: 46px; } diff --git a/apps/taro/test/browser/preview.spec.ts b/apps/taro/test/browser/preview.spec.ts index a513200..00f1bb3 100644 --- a/apps/taro/test/browser/preview.spec.ts +++ b/apps/taro/test/browser/preview.spec.ts @@ -3,6 +3,20 @@ import { test, expect } from "@playwright/test"; // 产物会遮蔽 Taro 运行时命名,选择器同时接受源码名称与遮蔽名称。 const BUTTON_CORE = ":is(taro-button-core, appkit-button-core)"; const TABBAR = ":is(.taro-tabbar__tabbar, .appkit-tabbar__tabbar)"; +test("共享按钮令牌在 H5 生效并与小程序高度一致", async ({ page }) => { + await page.setViewportSize({ width: 375, height: 812 }); + await page.goto("/"); + const measured = await page + .locator(`.food-home .actions ${BUTTON_CORE}`) + .first() + .evaluate((element) => ({ + minHeight: getComputedStyle(element).minHeight, + height: element.getBoundingClientRect().height, + })); + // 750 设计宽度下 88rpx 在 375px 视口等于 44px;H5 若取不到令牌会退化成 auto。 + expect(measured.minHeight).toBe("44px"); + expect(measured.height).toBe(44); +}); test("真实 API 驱动首页、出摊和主理人视觉槽位", async ({ page }) => { const errors: string[] = []; page.on("pageerror", (error) => errors.push(error.message)); diff --git a/docs/template-completion-rules.md b/docs/template-completion-rules.md index 90b5178..6d1b48f 100644 --- a/docs/template-completion-rules.md +++ b/docs/template-completion-rules.md @@ -74,6 +74,8 @@ Taro 小程序构建默认会把 CSS 中的 HTML 标签选择器重写为 `.h5-< 共享 reset 必须让微信 `