Pinned button link (absolute, inset:0) loses authored width:max-content: generated width:100%!important clips the label
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 79/100
调研方向
从 php-transformer/src/HtmlToBlocks/Style/GeneratedBlockStyleProjector.php 开始,阅读按钮载体的尺寸调整分支和 sourceControlPinsToItsWrapper(),并结合 issue 中提到的已设置宽度检查。使用 B-button-max-content.html 作为精简 fixture,验证生成的规则保留非 auto 宽度,同时维持固定的高度;完成标准是导入的链接仍约为 186px 宽,且完整标签显示在其背景上。
由索引模型根据 Issue 内容生成。
描述
Summary
A source button link that is absolutely positioned with inset:0 inside a small sized wrapper, but also declares width:max-content; min-width:100%, is wider than its wrapper in the source. It sizes to its label. After import it becomes core/buttons > core/button, and a generated rule forces the link to width:100%!important. The link shrinks to the wrapper's width, and the label overflows on both sides. Light label text that overflows the button background disappears against the page, so the visible text is clipped. For example, "Get in touch with the team" renders as "n touch with the".
Owning stage: WordPress materialization (generated block style projection for lowered core/button).
Reduced fixture
B-button-max-content.html (standalone, CSS inline):
<!doctype html><html><head><meta charset="utf-8"><title>Button fixture</title><style>
body{margin:0;font-family:sans-serif}
.box{position:relative;width:110px;height:40px;margin:40px}
.btn{box-sizing:border-box;display:flex;align-items:center;justify-content:center;width:max-content;min-width:100%;background:#5d1ff2;color:#fff;white-space:nowrap}
[data-variant] .box .btn{position:absolute;inset:0}
</style></head><body><main><div data-variant="solid"><div class="box"><a class="btn" href="/about/">Get in touch with the team</a></div></div></main></body></html>
The [data-variant] ancestor in the positioning rule matters. It sends the rule through the attribute-ancestry selector projection, which keeps position:absolute; inset:0 on .wp-block-button__link, matching the source. The same rule written as a plain .box .btn moves position:absolute onto the .wp-block-buttons wrapper, without its inset. That wrapper then shrink-wraps to the label, which hides this bug by accident. Large captured sites hit the first path because their author rules carry attribute-gated ancestors.
Observed
Viewport 1280px, Chromium (Playwright), measured with getBoundingClientRect():
| Wrapper width | Link width | Label text extent (x) | Link extent (x) | |
|---|---|---|---|---|
| Source | 110 | 185.9 (max-content) | 40 → 225.9 | 40 → 225.9 |
| Imported | 110 | 110 | 2.1 → 187.9 | 40 → 150 |
Imported block structure: core/group.box > core/buttons > core/button > a.wp-block-button__link (position:absolute; inset:0, from the projected author rule).
Winning generated rule:
.blocks-engine-control-<hash>-0.blocks-engine-control-<hash>-0>.wp-block-button__link{width:100%!important;height:100%!important;border-radius:0!important;text-align:start!important}
It overrides the projected author declaration width:max-content;min-width:100% on the same link.
The same thing happened on a full captured site: a 109px × 40px button wrapper whose link was 196px wide in the source became 109px after import.
Root cause
php-transformer/src/HtmlToBlocks/Style/GeneratedBlockStyleProjector.php (trunk ad346db3), in the button carrier sizing chain:
} elseif ( self::sourceControlPinsToItsWrapper($sourceDeclarations) ) {
// The source control takes its box from a sized wrapper by pinning
// to every edge. ...
$outerWrapperDeclarations[] = 'height:100%';
$wrapperDeclarations[] = 'height:100%';
$declarations[] = 'width:100%!important';
$declarations[] = 'height:100%!important';
}
sourceControlPinsToItsWrapper() (line ~631) only checks position:absolute and inset:0 (or all four edges set to 0). In CSS an absolutely positioned box with left:0; right:0 only fills its containing block when width is auto. If width is set to anything else, the box is over-constrained: right is ignored and the authored width wins. Here the source declares width:max-content and min-width:100%, so the box is at least as wide as the wrapper and grows to its label. The branch never checks $hasAuthoredWidth or the authored width value (both are computed earlier in the same method, line ~267). It emits width:100%!important, which turns "at least the wrapper" into "exactly the wrapper".
Expected
When the source control declares a non-auto width (for example max-content, fit-content, or a length), the pins-to-wrapper branch should not force width:100%!important. Keep the authored width and min-width:100%. The pinned height:100% behavior can stay. The imported link in the fixture should measure about 186px wide and show the full label on the button background, as in the source.
Reduced and filed with AI assistance (Claude, via coding agent).
- 主要语言
- PHP
- 星标
- 28
- 派生
- 5
- 平均合并
- 2 小时 59 分钟
- 30 天内合并 PR
- 942
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Automattic/blocks-engine 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
Automattic/blocks-engine#4943 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
Automattic/blocks-engine#4942 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
Automattic/blocks-engine#4921 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
Automattic/blocks-engine#775 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 66/100
Automattic/blocks-engine#6325 ·
维护者通常 1 天内回复
查看 Automattic/blocks-engine 的全部 Issue
相似的 Issue
-
kind/enhancement
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
[remove-resource] Delete Open Course Hub, Open Multicourse Hub, and Learn2 with GitSync skeletons未关闭
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
-
难度 1/5 1 小时以内 新手友好度 82/100