Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library: Add 'No fonts installed' message on library tab when fonts aren't available #63740

Merged
merged 5 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/edit-site/src/components/global-styles/font-families.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function InstalledFonts() {
refreshLibrary();
}, [] );

const hasFonts = baseThemeFonts.length > 0 || baseCustomFonts.length > 0;
return (
<div className="font-library-modal__tabpanel-layout">
{ isResolvingLibrary && (
Expand All @@ -173,6 +174,11 @@ function InstalledFonts() {
{ notice.message }
</Notice>
) }
{ ! hasFonts && (
<Text as="p">
{ __( 'No fonts installed.' ) }
</Text>
) }
{ baseThemeFonts.length > 0 && (
<VStack>
<h2 className="font-library-modal__fonts-title">
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/specs/site-editor/font-library.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading