Skip to content

Commit

Permalink
handle string and undefined fontweights when getting in site editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Imran92 committed Aug 30, 2024
1 parent dbe7731 commit b9dd96c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/block-editor/src/utils/get-font-styles-and-weights.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export function getFontStylesAndWeights( fontFamilyFaces ) {

fontFamilyFaces?.forEach( ( face ) => {
// Check for variable font by looking for a space in the font weight value. e.g. "100 900"
if ( /\s/.test( face.fontWeight.trim() ) ) {
if (
'string' === typeof face.fontWeight &&
/\s/.test( face.fontWeight.trim() )
) {
isVariableFont = true;

// Find font weight start and end values.
Expand All @@ -105,7 +108,11 @@ export function getFontStylesAndWeights( fontFamilyFaces ) {
}

// Format font style and weight values.
const fontWeight = formatFontWeight( face.fontWeight );
const fontWeight = formatFontWeight(
'number' === typeof face.fontWeight
? face.fontWeight.toString()
: face.fontWeight
);
const fontStyle = formatFontStyle( face.fontStyle );

// Create font style and font weight lists without duplicates.
Expand All @@ -118,7 +125,8 @@ export function getFontStylesAndWeights( fontFamilyFaces ) {
fontStyles.push( fontStyle );
}
}
if ( fontWeight ) {

if ( Object.keys( fontWeight ).length ) {
if (
! fontWeights.some(
( weight ) => weight.value === fontWeight.value
Expand Down

0 comments on commit b9dd96c

Please sign in to comment.