Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ToggleControl,
} from '@wordpress/components';
import { moreVertical } from '@wordpress/icons';
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -36,7 +36,6 @@ function FontSize() {

const {
params: { origin, slug },
goBack,
goTo,
} = useNavigator();

Expand All @@ -54,10 +53,10 @@ function FontSize() {

// Whether the font size is fluid. If not defined, use the global fluid value of the theme.
const isFluid =
fontSize.fluid !== undefined ? !! fontSize.fluid : !! globalFluid;
fontSize?.fluid !== undefined ? !! fontSize.fluid : !! globalFluid;

// Whether custom fluid values are used.
const isCustomFluid = typeof fontSize.fluid === 'object';
const isCustomFluid = typeof fontSize?.fluid === 'object';

const handleNameChange = ( value ) => {
updateFontSize( 'name', value );
Expand Down Expand Up @@ -107,9 +106,6 @@ function FontSize() {
};

const handleRemoveFontSize = () => {
// Navigate to the font sizes list.
goBack();

const newFontSizes = sizes.filter( ( size ) => size.slug !== slug );
setFontSizes( {
...fontSizes,
Expand All @@ -125,6 +121,18 @@ function FontSize() {
setIsRenameDialogOpen( ! isRenameDialogOpen );
};

// Navigate to the font sizes list if the font size is not available.
useEffect( () => {
if ( ! fontSize ) {
goTo( '/typography/font-sizes/', { isBack: true } );
}
}, [ fontSize, goTo ] );

// Avoid rendering if the font size is not available.
if ( ! fontSize ) {
return null;
}

return (
<>
<ConfirmDeleteFontSizeDialog
Expand Down