-
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: Fix FontSizePicker Storybook control type and improve documentation #68936
base: trunk
Are you sure you want to change the base?
FontSizePicker: Fix FontSizePicker Storybook control type and improve documentation #68936
Conversation
Hi, @t-hamano I have currently applied your fix and it seems to solve the issue but I am finding better possibilities. Meanwhile, if we find any better solutions, we can explore them here. |
@@ -92,6 +92,8 @@ Size of the control. | |||
|
|||
Available units for custom font size selection. | |||
|
|||
**Important Note**: For the units property to work, font sizes must be specified as strings with units (e.g., `'12px'` instead of `12`). When font sizes are provided as numbers, the component operates in "unitless mode" where the units property has no effect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Important Note**: For the units property to work, font sizes must be specified as strings with units (e.g., `'12px'` instead of `12`). When font sizes are provided as numbers, the component operates in "unitless mode" where the units property has no effect. | |
**Note**: For the `units` property to work, the current font size value must be specified as strings with units (e.g., `'12px'` instead of `12`). When the font size is provided as a number, the component operates in "unitless mode" where the `units` property has no effect. |
My feeling is that this should be emphasized in the value
prop section, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes @t-hamano you're right, It makes more sense to emphasize the value
prop selection.
@@ -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 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too confident about this change. Because it silently squashes errors and doesn't match the expected type (string[]
).
That said, it does fix the error when trying to change the units
prop in Storybook. This error occurs because when you press the "Set object" button, the value is initialized as an empty object instead of an empty array.
cc @WordPress/gutenberg-components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tried, but would it make sense to change the Storybook control type to something like inline-check
or multi-select
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
746016f
to
32086da
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@@ -92,6 +92,8 @@ Size of the control. | |||
|
|||
Available units for custom font size selection. | |||
|
|||
**Note**: For the `units` property to work, the current font size value must be specified as strings with units (e.g., `'12px'` instead of `12`). When the font size is provided as a number, the component operates in "unitless mode" where the `units` property has no effect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about moving this to the value
prop section? Because unitless mode is based on the value
prop value, not the units
prop value.
@@ -2,6 +2,8 @@ | |||
|
|||
## Unreleased | |||
|
|||
- `FontSizePicker`: Fix Storybook units control type to use `inline-check` and improve documentation clarifying unitless mode in `README.md` ([#68936](https://github.com/WordPress/gutenberg/pull/68936)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `FontSizePicker`: Fix Storybook units control type to use `inline-check` and improve documentation clarifying unitless mode in `README.md` ([#68936](https://github.com/WordPress/gutenberg/pull/68936)). | |
### Documentation | |
- `FontSizePicker`: Fix Storybook units control type to use `inline-check` and improve documentation clarifying unitless mode in `README.md` ([#68936](https://github.com/WordPress/gutenberg/pull/68936)). |
The checklog should be included in a subheading. "Documentation" would be good.
What?
Closes: #68553
This PR fixes an issue with the FontSizePicker component in Storybook where changing the
units
prop was causing an error. It also clarifies the documentation around the component'sunitless mode
.Why?
When trying to change the units prop in Storybook, an error was occurring:
allowedUnitValues.includes is not a function
. This happened because clicking theSet object
button in Storybook initialized the value as an empty object instead of an array. Additionally, the documentation didn't clearly explain when theunits
prop would actually have an effect.How?
units
prop from the default toinline-check
with predefined optionsREADME
documentation to clearly explain the relationship betweenstring/number
font-size values and theunitless mode
Testing Instructions
npm run storybook:dev
FontSizePicker
componentunits
property only works when font sizes are specified as strings with unitsScreencast
Screen.Recording.2025-02-26.at.12.43.14.mov