Skip to content
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

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

himanshupathak95
Copy link
Contributor

@himanshupathak95 himanshupathak95 commented Jan 29, 2025

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's unitless 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 the Set object button in Storybook initialized the value as an empty object instead of an array. Additionally, the documentation didn't clearly explain when the units prop would actually have an effect.

How?

  • Changes the Storybook control type for the units prop from the default to inline-check with predefined options
  • Improves the README documentation to clearly explain the relationship between string/number font-size values and the unitless mode

Testing Instructions

  • Run Storybook with npm run storybook:dev
  • Navigate to the FontSizePicker component
  • Verify you can select different unit options using the checkboxes without any errors
  • Verify that the component's documentation explains that the units property only works when font sizes are specified as strings with units

Screencast

Screen.Recording.2025-02-26.at.12.43.14.mov

@himanshupathak95
Copy link
Contributor Author

Hi, @t-hamano I have currently applied your fix and it seems to solve the issue but I am finding better possibilities.
This might not be the final solution but I think this is a discussion starter.
I will be updating the README and the storybook in the following commits.

Meanwhile, if we find any better solutions, we can explore them here.

@shail-mehta shail-mehta added [Type] Developer Documentation Documentation for developers [Package] Components /packages/components Storybook Storybook and its stories for components labels Jan 30, 2025
@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
**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?

Copy link
Contributor Author

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 )
Copy link
Contributor

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.

storybook

cc @WordPress/gutenberg-components

Copy link
Member

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the feedback! I've tried both controls and it feels like the inline-check control is the better fit.

inline-check;

image

multi-select:

image

@himanshupathak95 himanshupathak95 force-pushed the fix/68553-font-size-picker-unit-filtering branch from 746016f to 32086da Compare February 26, 2025 06:56
@himanshupathak95 himanshupathak95 marked this pull request as ready for review February 26, 2025 07:17
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: himanshupathak95 <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: SainathPoojary <[email protected]>
Co-authored-by: im3dabasia <[email protected]>
Co-authored-by: slaFFik <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@himanshupathak95 himanshupathak95 changed the title Components: Improve FontSizePicker units documentation and fix unit filtering FontSizePicker: Fix FontSizePicker Storybook control type and improve documentation Feb 26, 2025
@@ -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.
Copy link
Contributor

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)).
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components Storybook Storybook and its stories for components [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FontSizePicker: units property does not work in Block Editor
4 participants