-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Typography: numerical font size presets break FontSizePicker #44857
Comments
How about let's lean into what the schema says and require strings? If a number is specified then automatically switch it to a |
This fixes the "fontSizeValue.startsWith is not a function" error. It seems that the font size picker now always expects strings, while the values from SETTINGS_DEFAULTS could be numbers, and we've been using numbers throughout our codebase as well. This also enables the usage of any font size units, such as em and rem. This may be related to: WordPress/gutenberg#44857 [MAILPOET-5102]
This fixes the "fontSizeValue.startsWith is not a function" error. It seems that the font size picker now always expects strings, while the values from SETTINGS_DEFAULTS could be numbers, and we've been using numbers throughout our codebase as well. This also enables the usage of any font size units, such as em and rem. This may be related to: WordPress/gutenberg#44857 [MAILPOET-5102]
This fixes the "fontSizeValue.startsWith is not a function" error. It seems that the font size picker now always expects strings, while the values from SETTINGS_DEFAULTS could be numbers, and we've been using numbers throughout our codebase as well. This also enables the usage of any font size units, such as em and rem. This may be related to: WordPress/gutenberg#44857 [MAILPOET-5102]
This fixes the "fontSizeValue.startsWith is not a function" error. It seems that the font size picker now always expects strings, while the values from SETTINGS_DEFAULTS could be numbers, and we've been using numbers throughout our codebase as well. This also enables the usage of any font size units, such as em and rem. This may be related to: WordPress/gutenberg#44857 [MAILPOET-5102]
I spent some time trying to resolve this and I think the most appropriate place to coerce a font size, where it is a number, is in gutenberg_get_typography_font_size_value, something like this: /*
* JSON schema requires the value of "size" to be a string.
*/
if ( ! is_string( $preset_size ) ) {
_doing_it_wrong(
__FUNCTION__,
__( 'Font-size value must be a string, including units.', 'gutenberg' ),
'6.3.0'
);
}
// Tries to cast numeric values to a string and add a 'px' unit as fallback.
if ( is_numeric( $preset_size ) ) {
$preset_size = $preset_size . 'px';
} We're already coercing to "string" + px for fluid font sizes, so it makes sense to do it this way I believe. Not too sold on the |
Description
Setting the
size
property of a font size preset item to a number causes the FontSizePicker component to stop working for newly-inserted blocks.The schema for theme.json defines
"size"
as being of type 'string', however the FontSizePicker does support numbers.So question is whether we should support numbers as font sizes across the board (and coerce them to
px
values?).From @noisysocks
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: