From 914e64e406d91aa616314b65e11c5f6b2afff262 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 22 Feb 2024 11:16:02 -0300 Subject: [PATCH] Font collection pagination: add min height to avoid infinite number (#59241) * Add min height to avoid infinite number * improve syntax Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> --------- Co-authored-by: matiasbenedetto Co-authored-by: t-hamano Co-authored-by: carolinan # Conflicts: # packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js --- .../global-styles/font-library-modal/font-collection.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js index 5f6977ef7df743..01f7a90357c8ba 100644 --- a/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js +++ b/packages/edit-site/src/components/global-styles/font-library-modal/font-collection.js @@ -58,6 +58,7 @@ const DEFAULT_CATEGORY = { }; const LOCAL_STORAGE_ITEM = 'wp-font-library-google-fonts-permission'; +const MIN_WINDOW_HEIGHT = 500; function FontCollection( { slug } ) { const requiresPermission = slug === 'google-fonts'; @@ -143,7 +144,8 @@ function FontCollection( { slug } ) { // NOTE: The height of the font library modal unavailable to use for rendering font family items is roughly 417px // The height of each font family item is 61px. - const pageSize = Math.floor( ( window.innerHeight - 417 ) / 61 ); + const windowHeight = Math.max( window.innerHeight, MIN_WINDOW_HEIGHT ); + const pageSize = Math.floor( ( windowHeight - 417 ) / 61 ); const totalPages = Math.ceil( fonts.length / pageSize ); const itemsStart = ( page - 1 ) * pageSize; const itemsLimit = page * pageSize;