From e0124786f522796058a50f8fbec2a3754eccba3c Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 11 Aug 2023 11:25:58 +1000 Subject: [PATCH] Fallback to default max viewport if layout wide size is fluid. --- lib/block-supports/typography.php | 2 +- .../components/global-styles/typography-utils.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/block-supports/typography.php b/lib/block-supports/typography.php index bdcb2bbe98896..c4e1316ac3893 100644 --- a/lib/block-supports/typography.php +++ b/lib/block-supports/typography.php @@ -468,7 +468,7 @@ function gutenberg_get_typography_font_size_value( $preset, $should_use_fluid_ty // Defaults overrides. $minimum_viewport_width = isset( $fluid_settings['minViewportWidth'] ) ? $fluid_settings['minViewportWidth'] : $default_minimum_viewport_width; - $maximum_viewport_width = isset( $layout_settings['wideSize'] ) ? $layout_settings['wideSize'] : $default_maximum_viewport_width; + $maximum_viewport_width = isset( $layout_settings['wideSize'] ) && ! empty( gutenberg_get_typography_value_and_unit( $layout_settings['wideSize'] ) ) ? $layout_settings['wideSize'] : $default_maximum_viewport_width; if ( isset( $fluid_settings['maxViewportWidth'] ) ) { $maximum_viewport_width = $fluid_settings['maxViewportWidth']; } diff --git a/packages/block-editor/src/components/global-styles/typography-utils.js b/packages/block-editor/src/components/global-styles/typography-utils.js index c88019adc38dd..cd1340033e377 100644 --- a/packages/block-editor/src/components/global-styles/typography-utils.js +++ b/packages/block-editor/src/components/global-styles/typography-utils.js @@ -7,7 +7,10 @@ /** * Internal dependencies */ -import { getComputedFluidTypographyValue } from '../font-sizes/fluid-utils'; +import { + getComputedFluidTypographyValue, + getTypographyValueAndUnit, +} from '../font-sizes/fluid-utils'; /** * @typedef {Object} FluidPreset @@ -99,11 +102,16 @@ function isFluidTypographyEnabled( typographySettings ) { export function getFluidTypographyOptionsFromSettings( settings ) { const typographySettings = settings?.typography; const layoutSettings = settings?.layout; - return isFluidTypographyEnabled( typographySettings ) && + const defaultMaxViewportWidth = getTypographyValueAndUnit( layoutSettings?.wideSize + ) + ? layoutSettings?.wideSize + : null; + return isFluidTypographyEnabled( typographySettings ) && + defaultMaxViewportWidth ? { fluid: { - maxViewportWidth: layoutSettings.wideSize, + maxViewportWidth: defaultMaxViewportWidth, ...typographySettings.fluid, }, }