gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Font Library: Add font family name next to "Default" label

Open Nyiriland opened this issue 2 years ago • 6 comments

SUGGESTION When looking at a block’s Font Family, it would be very helpful to see the name of default font next to the word “Default”. It can be hard to remember what you set as default in your global styles.

image

Nyiriland avatar Mar 18 '24 12:03 Nyiriland

Can you assign it to me?This is my first contribution,so where can i get this code?

sahiladit avatar Mar 19 '24 05:03 sahiladit

Hi folks 👋

I'm working on this issue and I came across this working implementation in:

packages/edit-site/src/components/global-styles/typography-elements.js

In that file, default font families are accessed like this:

const [ fontFamily ] = useGlobalStyle( 'typography.fontFamily' );

So, I tried using the same approach in a different part of the codebase (in FontFamilyControl at packages/block-editor/src/components), by importing useGlobalStyle via:

import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
const { useGlobalStyle } = unlock( blockEditorPrivateApis );

However, doing this causes a fatal memory error during build:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in wp-includes/class-wp-scripts.php on line 631

This happens on a local environment (Local by Flywheel) with default PHP memory settings (256MB).


❓ My questions:

  1. Why does this work fine inside edit-site (Site Editor context), but not when used elsewhere like block-editor or components?
  2. Is there a recommended way to safely fetch global typography values (especially default font families) outside the Site Editor?
  3. Should I avoid using useGlobalStyle from private APIs in shared packages altogether?
  4. Any alternative direction or pattern to achieve this?

cc : @mikachan @creativecoder

Ta5r avatar May 16 '25 10:05 Ta5r

Hi Team,

While investigating the issue and reviewing the related codebase, I identified that the Default value is currently hardcoded within the following section:

https://github.com/WordPress/gutenberg/blob/cebf65e50f7b7b2bc9eddc3c1f5d63dc771607b6/packages/block-editor/src/components/font-family/index.js#L38-L47

Key Observations

  • The hardcoding of Default makes it challenging to customize or intercept the "default" font family at runtime.
  • Ideally, the Default label should be sourced from the settings, specifically from:
    TypographyPanel => settings.typography.fontFamily.default
    
    so that modifications can be handled dynamically wherever required.

Recommended Next Steps

  1. Investigate Data Persistence

    • Examine how Gutenberg currently saves the default value for fontFamily within its settings structure.
    • Verify why, when the TypographyPanel component is rendered, the settings for the default font family appear as undefined.
  2. Implement Settings Retrieval

    • If the default value is not present in the settings, ensure it is correctly initialized in settings.typography.fontFamily.default.
  3. Refactor FontFamilyControl

    • Once the proper default is set in the configuration, update the FontFamilyControl component to reference the newly available value rather than rely on the hardcoded fallback.
    • As a safeguard, only use the hardcoded Default if a proper value cannot be obtained from the settings.

Thank You,

hbhalodia avatar Jul 18 '25 08:07 hbhalodia

Yes please, I would love this feature!

davewhitley avatar Feb 26 '26 20:02 davewhitley

I tested this on trunk and it looks resolved by #77894. With Twenty Twenty-Five, a Paragraph block with no font of its own now shows the inherited font ("Manrope") in the Font control instead of "Default", and the dropdown marks Manrope as the current value.

The only remaining gap is that the "Default" option inside the dropdown doesn't name the font. That could be a small follow-up ("Default (Manrope)") if it's still wanted, otherwise I think this can be closed.

image image

dhananjaykuber avatar Nov 16 '26 11:11 dhananjaykuber

Indeed, thank you for testing. Closing as resolved!

jasmussen avatar Nov 16 '26 11:11 jasmussen