diff --git a/packages/edit-site/src/components/global-styles/font-families.js b/packages/edit-site/src/components/global-styles/font-families.js index 5119ca679e40ad..7a05a66c6efdfe 100644 --- a/packages/edit-site/src/components/global-styles/font-families.js +++ b/packages/edit-site/src/components/global-styles/font-families.js @@ -26,7 +26,7 @@ import { unlock } from '../../lock-unlock'; const { useGlobalSetting } = unlock( blockEditorPrivateApis ); function FontFamilies() { - const { baseCustomFonts, modalTabOpen, setModalTabOpen } = + const { baseCustomFonts, modalTabOpen, setModalTabOpen, setNotice } = useContext( FontLibraryContext ); const [ fontFamilies ] = useGlobalSetting( 'typography.fontFamilies' ); const [ baseFontFamilies ] = useGlobalSetting( @@ -111,13 +111,15 @@ function FontFamilies() { className="edit-site-global-styles-font-families__manage-fonts" variant="secondary" __next40pxDefaultSize - onClick={ () => + onClick={ () => { + // Reset notice when opening the modal. + setNotice( null ); setModalTabOpen( hasInstalledFonts ? 'installed-fonts' : 'upload-fonts' - ) - } + ); + } } > { hasInstalledFonts ? __( 'Manage fonts' ) diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js index f3c8d73eef307e..76618a54aeb92f 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/installed-fonts.js @@ -148,6 +148,7 @@ function InstalledFonts() { refreshLibrary(); }, [] ); + const hasFonts = baseThemeFonts.length > 0 || baseCustomFonts.length > 0; return (
{ isResolvingLibrary && ( @@ -173,6 +174,11 @@ function InstalledFonts() { { notice.message } ) } + { ! hasFonts && ( + + { __( 'No fonts installed.' ) } + + ) } { baseThemeFonts.length > 0 && (

diff --git a/test/e2e/specs/site-editor/font-library.spec.js b/test/e2e/specs/site-editor/font-library.spec.js index 36b12eaf186c65..3025e61303c22e 100644 --- a/test/e2e/specs/site-editor/font-library.spec.js +++ b/test/e2e/specs/site-editor/font-library.spec.js @@ -14,6 +14,24 @@ test.describe( 'Font Library', () => { await editor.canvas.locator( 'body' ).click(); } ); + test( 'should display the "no font installed." message', async ( { + page, + } ) => { + await page.getByRole( 'button', { name: 'Styles' } ).click(); + await page + .getByRole( 'button', { name: 'Typography Styles' } ) + .click(); + await page + .getByRole( 'button', { + name: 'Add fonts', + } ) + .click(); + await page.getByRole( 'tab', { name: 'Library' } ).click(); + await expect( + page.getByLabel( 'library' ).getByText( 'No fonts installed.' ) + ).toBeVisible(); + } ); + test( 'should display the "Add fonts" button', async ( { page } ) => { await page.getByRole( 'button', { name: 'Styles' } ).click(); await page