fix(components): 把字段 label 转发给内置 textarea 的全屏编辑对话框 (#3393) - #3399
Merged
Conversation
`renderFormField` 解构字段配置时把 `label` 单独取走(它要渲染
`<FormLabel>`),而唯一的 `renderFieldComponent` 调用点重建 props 对象时
补回了 field/inputType/options/placeholder/emptyHint/dependsOnLabels,
唯独漏了 `label`。内置 `textarea` 分支的 `label` 因此恒为 undefined,
`FullscreenTextarea` 里两条依赖它的分支从未走到:对话框标题恒为通用词
「编辑文本」,展开按钮的无障碍名在同一表单的三个长文本字段上完全一样。
- 调用点显式转发 `label`(与 placeholder/emptyHint 同法)。
- `label` 为 renderer-only:两个 strip 各加一条丢弃项,既不落 DOM 属性,
也不进注册路径(FieldWidgetProps 契约不变,widget 仍从 `field` 读)。
- 删掉 textarea 分支里那句只护一个分支、且从来没东西可护的
`const { label: _label, ...rest }`。
十个语言包零改动:#3272 已把 `form.fullscreen.toggle` 做成带 {{label}}
插值的整句;无 label 的字段仍回落到被翻译的通用词。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3393
前提复核(对 origin/main@9cbcbf478,#3392/#3397 落地之后)
issue 的前提机械可复核,复核结论:成立。
renderFieldComponent唯一调用点的 props 对象里没有任何label:键 —— 它显式补了field/inputType/options/placeholder/disabled/readonly/emptyHint/dataSource/dependentValues/dependsOnLabels/error/aria-required,唯独没有label;而上游renderFormField早在...fieldProps之前就把label单独解构走了(它要渲染字段自己的 FormLabel)。于是内置textarea分支里const { mobile_fullscreen, label } = fieldProps拿到的label恒为undefined,FullscreenTextarea中两条依赖它的表达式从写下那天起没走到过。但 issue 关于「strip 已经挡着 label」的那半句不成立,这一点改变了修法的形状:
stripRendererOnlyProps和stripRegisteredFieldProps里都没有label条目。真正拦着的只有内置textarea分支自己那句const { label: _label, ...rest },它只护住这一个分支。所以「只在调用点补一个label」是不够的 —— 那样会让 label 立刻变成 input / textarea / checkbox / switch / 默认分支上的杂 DOM 属性label="备注"(每个分支都把剩余 props 直接摊到 DOM 节点上),并且会凭空多送注册型 widget 一个新 prop。改了什么
label(与placeholder/emptyHint同法)。这是唯一的行为改动。label定性为 renderer-only,两个 strip 各加一条丢弃项:stripRendererOnlyProps—— 字段的 label 由 FormLabel 渲染在控件上方,DOM 属性上不需要第二份;stripRegisteredFieldProps—— 注册路径的载荷与改动前逐字节相同。自 v17 起field是 widget 唯一的元数据载体(field与schema是同一个意思的两个载体,~25 个 widget 读field || schema#3233),label 本来就在那里。不加这条,注册型 widget 会突然多收到一个labelprop,并顺着它们的...props摊到七个 widget 的 DOM 上;要不要在FieldWidgetPropsSchema里发布labelprop 是另一次裁决,本单不开这个口。const { label: _label, ...rest }。它本想拦 label 落 DOM,但既然从来没有 label 送进来,它拦的是不存在的东西(ESLint 一直报着'_label' is assigned a value but never used),而且只护一个分支。现在这件事由 strip 统一负责,所有内置分支同等受护。RenderFieldProps上把label?: string显式声明出来(与error同法),让「转发什么、给谁看」写在类型上而不是靠索引签名兜住。十个语言包零改动:#3272/PR #3392 把
form.fullscreen.toggle做成了带{{label}}插值的整句(zh 插句尾、ja 插句首),label 一通,十个语言的句子直接就对。测试
新增
form-fullscreen-textarea-label.test.tsx(9 例),覆盖两个方向:label 送到了(标题 = 字段名而非通用词;按钮无障碍名插值;一张表单三个长文本字段的按钮名互不相同,且第二个按钮打开的是第二个字段的对话框;zh 下整句正确),以及 label 只送到了那里(所有内置分支渲染出的 DOM 上没有任何label属性;注册型 widget 的 props 里props.label为 undefined 而props.field.label仍是「Notes」)。form-fullscreen-textarea-i18n.test.tsx的 fixture 从「有 label」改成「无 label」:这一组的被测对象是两个通用串(form.fullscreen.title与被插值的form.fullscreen.textFallback),而通用串只在字段没有 label 时可达。写这组用例时字段叫Notes却仍显示通用词,正是本单修掉的缺陷 —— 把 fixture 指向 fallback 真正服务的那个栈,这十个语言包才继续被覆盖,而不是继续断言一个已修的缺陷。提交 draft 那一例仍用带 label 的 fixture(它断言的是接线而不是文案)。反向验证(三条肢,方向各自预先判定,结果与预判一致)
label,expected [ 'Edit text fullscreen', …(2) ] to deeply equal [ 'Edit Notes fullscreen', …(2) ]stripRendererOnlyProps的labelexpected input …(8) ...stripRegisteredFieldProps的labelexpected 'Notes' to be undefinedi18n 组在第一条肢下保持全绿,是这次 fixture 改判正确的独立证据:它已经不再依赖缺陷行为。
跑过的命令
从仓根跑(包内
--root packages/components+ 相对路径过滤会命中 objectui#3288/#3378 的假绿:No test files found, exiting with code 0,退出码 0):npx vitest run --maxWorkers=2 packages/components/src/renderers/form/ packages/components/src/__tests__/form-renderers.test.tsx packages/components/src/__tests__/form-write-error-message.test.tsx→ Test Files 30 passed (30) / Tests 177 passed (177)packages/fields的三个 e2e 门禁(其中widget-dom-leak-e2e就是注册型 widget 的 DOM 泄漏门禁): → Test Files 3 passed (3) / Tests 294 passed (294)pnpm --workspace-concurrency=2 --filter @object-ui/components type-check→ 通过(tsc --noEmit && tsc -p tsconfig.typetests.json,无输出)npx eslint packages/components/src/renderers/form/form.tsx→ 0 errors。warning 数 89 → 90:textarea 分支那条'_label' ...never used消失了,strip 两函数各多一条同类 warning。这与 issue 的预期略有出入,如实记录:_label的告警不是消失,而是搬了家 —— 该文件里每一个 strip 绑定(_dataSource/_inputType/_schema…)本来就各报一条同类 warning,新增两条与既有约定完全一致。pnpm run check:control-bytes→ OK(3587 个文件);另按 AGENTS.md 对改动文件做了越过门禁的自扫grep -naP '[\x00-\x08\x0b\x0c\x0e-\x1f]'→ 干净。范围
只动
packages/components/src/renderers/form/form.tsx+ 相应测试 + 一个 patch changeset。⛔ 未改注册路径的对外契约(载荷逐字节不变),⛔ 未碰packages/fields的FullscreenFieldEditor(#3398 另议)。🤖 Generated with Claude Code
https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
Generated by Claude Code