Skip to content

Fix: Global Styles: Font Appearance doesn't work well with theme.json default value #70976

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

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

hbhalodia
Copy link
Contributor

What?

Closes #70937

Why?

How?

  • PR adds the mapping object to check for the fontWeight text and use it's corresponding number.

Testing Instructions

  1. Add theme.json as per - Global Styles: Font Appearance doesn't work well with theme.json default value #70937 (comment)
  2. Open global styles --> Typography.
  3. Add the patch, and check, Now Bold fontWeight would be selected.

Testing Instructions for Keyboard

  • NIL

Screenshots or screencast

Screen.Recording.2025-07-30.at.4.11.21.PM.mov

Comment on lines +42 to +57
const fontWeightMapping = {
thin: 100,
'extra light': 200,
'extra-light': 200,
light: 300,
regular: 400,
medium: 500,
'semi bold': 600,
'semi-bold': 600,
bold: 700,
'extra bold': 800,
'extra-bold': 800,
black: 900,
'extra black': 1000,
'extra-black': 1000,
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, is this the ideal approach, or do we have this object mapping present somewhere else so we can utilize that? @t-hamano

Comment on lines +207 to +211
// Check if newFontWeightValue is not a numeric number, but it is a valid string.
if ( isNaN( parseInt( newFontWeightValue ) ) ) {
newFontWeightValue = fontWeightMapping[ newFontWeightValue ] ?? '100';
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would needed because, else the comparision and difference would always be on NaN value, hence it always uses 100 at the end.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global Styles: Font Appearance doesn't work well with theme.json default value
2 participants