Repository navigation
Prototype: look Appearance font faces up from the family a block's text is drawn in - #83462
Jiwoon-Kim wants to merge 5 commits into
Conversation
In Styles > Blocks > <block>, the Appearance options come from the block's own font family. A block that draws its text in the root font has none of its own, so the control falls back to the built-in weight list and offers weights the font does not provide. Give TypographyPanel an optional `capabilityFontFamily`: the family the text is drawn in when neither the panel's value nor the value it inherits names one. It feeds the face lookup and nothing else, so the Font control still reads `Default`, no value is written, and the inheritance treatment the other controls show is unchanged. The Blocks screen reads the root family separately rather than folding it into `inheritedStyle`, which 22 controls in the panel read for their own display. Prototype for WordPress#83459, which asks whether this screen should resolve the family the block renders in at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A block records its font family in one of two places: the attribute a preset sets, or `style.typography.fontFamily` when the value was written inline. The style the Typography panel is given read only the attribute, so a block of the second kind arrived without a family at all, and everything that asks what font it is drawn in answered with the inherited one instead. The three values beside it already fall back this way. Font size, text shadow and text colour each read their attribute and, failing that, the style; the family alone dropped to `undefined`. What that cost is not cosmetic. The faces a family declares decide which styles, weights and widths the panel can offer, so reading the wrong family offers the wrong ones. Measured in the editor, a paragraph whose own family is an icon font declaring `fontWeight: "100 700"` was offered weights up to 1000, which is the range of the site's font rather than its own. With the family preserved the same control stops at 700. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Thanks for picking this up! I tested this PR, and I have one suggestion. Testing
So Paragraph is fixed, but Heading still gets the wrong list. Suggestion The block inspector already resolves this cascade with const capabilityFontFamily = useMemo(
() =>
resolveStyle( mergedConfig, {
blockName: name,
variationName: variation ?? null,
elements: getElementLayers( name ),
} ).value?.typography?.fontFamily,
[ mergedConfig, name, variation ]
);This needs I think this also answers the A/B/C question: go with B (the family the text is actually drawn in), resolved the same way the inspector does it. That way the Blocks screen and the block inspector offer the same weights for the same block. A smaller note (this bug already exists; this PR didn't cause it): Not tested yet: a manual check in the editor. |
|
Thank you — this is the case I could not find, and the Twenty Twenty-Four setup is what makes it obvious. It also answers the A/B/C question, in favour of B: the family the text is actually drawn in, resolved the same way the inspector resolves it, so that the Blocks screen and the block inspector offer the same weights for the same block. Could you open a pull request against this branch with the One thing worth a case, since your test models Twenty Twenty-Four rather than running it: the shipped themes do not agree on how a family is written into That the element screen already handles the second form is a point for One note for whoever reads the diff after us: passing only the block name to On the |
Prototype for #83459. Opened to ask a question rather than to merge, and happy to close it if the answer is no.
What?
In Styles → Blocks → , Appearance is built from the block's own font family. A block that draws its text in the root font has none, so the control falls back to the built-in list and offers weights the font does not provide.
This adds an optional
capabilityFontFamilytoTypographyPanel: the family the text is drawn in when neither the panel's value nor the value it inherits names one. The Blocks screen passes the root font family, and the control looks its faces up instead of falling back.It also carries a fix found while testing that: the panel style now preserves a family written inline in
style.typography.fontFamily, matching the existing attribute path. A block that records its family that way reached the panel with none at all, so the faces looked up were the inherited font's rather than its own.The three places a family can come from, all of which the faces are now read through:
Why?
The question behind #83459 is which family should decide what Appearance offers:
fontFamilyonly, as today.This prototype implements B, because the text really is drawn in the inherited family and #49090 asked for the control to offer what the font has. If A is the intended model for this screen, the bug is instead that the built-in list stands in for "unknown", and this should be closed in favour of C or of saying so in the UI.
Worth noting that the three surfaces disagree today. The block inspector resolves the inherited family already, through
resolveStyle()and itsrootlayer; the Blocks screen readsgetStyle( gs, path, blockName ), which stops atstyles.blocks.<name>. The same block gets different Appearance options depending on where it is edited.How?
TypographyPaneltakescapabilityFontFamilyand uses it for one thing:That value feeds
getMergedFontFamiliesAndFontFamilyFaces()and nothing else. It does not become a value, is not written on change, does not affect what the Font control displays, and does not mark anything as inherited:fontFamily,inheritedFontFamilyandisFontFamilyPlaceholderare untouched, so the Font control still readsDefaultand the inheritance treatment is unchanged.screen-block.tsxreads the root family separately, rather than folding it intoinheritedStyle, which 22 controls in the panel read for their own inheritance display.The inline family is a separate commit.
attributesToStyle()read thefontFamilyattribute and fell toundefinedwithout one, while the three values beside it — font size, text shadow and text colour — each fall back to the style. Measured in the editor: a paragraph whose own family is an icon font declaringfontWeight: "100 700"was offered weights to 1000, the range of the site's font; with the family preserved the same control stops at 700.Deliberately not included, because they are the broader change #83459 mentions: making the Blocks screen resolve inheritance generally, and widening the inheritance indicators to match.
Testing Instructions
theme.json, register a family whose face declares"fontWeight": "100 700"and set it as the root font, as in Typography: the Blocks screen does not resolve a block's inherited font family, so Appearance offers weights the font lacks #83459.Default, and open Appearance.ThintoExtra Black. With this change it stops atBold, and the Font control still readsDefault.Testing Instructions for Keyboard
No change to the controls themselves; only the options listed for a block that inherits its font change.
Not included
No browser test for what Appearance offers. The inline family fix has unit coverage, binding the three paths above to one expectation, but the options a block is offered are behind the panel's menu and the existing coverage for that control is browser-based. That test would have to be rewritten if the answer to the question above is A or C, so I would rather add it once the model is settled.
One known limitation: the root family is read without the screen's
prefix, so a block style variation screen reads the root rather than the variation's typography. Worth fixing if this direction is taken.Use of AI Tools
AI tools (Claude Code, Claude Opus 5) assisted with implementation and with the measurements in #83459. I reviewed the changes and the results.
🤖 Generated with Claude Code