-
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
FontSizePicker: units property does not work in Block Editor #68553
Comments
And |
Hey @slaFFik, Tried replicating the issue as mentioned above. In my testing, I found that even after passing the units prop to FontSizePicker, the option to change units does not appear. Edit.js Used: /**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { FontSizePicker } from '@wordpress/components';
import { useBlockProps } from '@wordpress/block-editor';
export default function Edit( { attributes, setAttributes } ) {
return (
<div { ...useBlockProps() }>
<FontSizePicker
__next40pxDefaultSize
fontSizes={ [
{
name: __( 'Normal' ),
size: 16,
slug: 'normal',
},
{
name: __( 'Big' ),
size: 26,
slug: 'big',
},
{
name: __( 'Huge' ),
size: 36,
slug: 'huge',
},
] }
units={ [ 'px', 'em', 'rem', 'vw', 'vh' ] }
onChange={ ( value ) => setAttributes( { text_size: value } ) }
value={ attributes.text_size }
/>
</div>
);
} 2025-01-09.07-33-46.mp4 |
Thank you @slaFFik for reporting the issue , I was able to reproduce this issue in the storybook for FontSizePicker component. Also a slightly related issue: The dropdown to select the units does not function as expected. I believe the expected behavior should be that, upon clicking the button, a dropdown of units appears. However, that is not happening currently. Screen.Recording.2025-01-09.at.10.20.11.AM.mov |
From what I understand, this component works perfectly according to the spec, but the code, documentation, and Storybook could use some slight improvements.
I think this is because this component is operating in "unitless mode". If the value or the first font size is not a string, the In other words, if you give this component props that set
Because Some stories of this component are running in unitless mode. See this code. Notice that the
Clicking the "Set object" button on the We can avoid this critical error by making the following changes, but I'm not sure if this is the ideal approach: diff --git a/packages/components/src/unit-control/utils.ts b/packages/components/src/unit-control/utils.ts
index c80b34ef3a..0a7c1160d0 100644
--- a/packages/components/src/unit-control/utils.ts
+++ b/packages/components/src/unit-control/utils.ts
@@ -394,7 +394,7 @@ export function filterUnitsWithSettings(
// Although the `isArray` check shouldn't be necessary (given the signature of
// this typed function), it's better to stay on the side of caution, since
// this function may be called from un-typed environments.
- return Array.isArray( availableUnits )
+ return Array.isArray( availableUnits ) && Array.isArray( allowedUnitValues )
? availableUnits.filter( ( unit ) =>
allowedUnitValues.includes( unit.value )
) cc @WordPress/gutenberg-components |
@t-hamano Thank you for additional info. There should be quite a few updates to the docs about all of that. tl;dr
|
Description
What problem does this address?
I think
units
property does not work.Here is the component properties I have:
I cannot disable units selection in the
units
property by passing the empty array.But even if I pass a single value (like
units={['pt']}
) or multiple items in the array (likeunits={['px', 'em']}
- they are still not picked up by the component.Styleguid page - https://wordpress.github.io/gutenberg/?path=/docs/components-fontsizepicker--docs - is also failing with
Error: allowedUnitValues.includes is not a function
errorwhenever I try to set custom values here:
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
WP 6.7.1, Chrome 131, MacOS 15.2
Same behavior with and without Gutenberg 19.9.0.
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
The text was updated successfully, but these errors were encountered: