Skip to content

Improve the way we handle custom units and how we interact with themes config. #33470

@youknowriad

Description

@youknowriad

There are a couple of issues with the way we handle units right now. Themes provide the available themes by adding spacing.units to their theme.json or by defining add_theme_support( 'custom-units' )

I noticed a number of issues though:

  • If the theme doesn't define anything, we end up with false value for the config but since we have fallbacks each time we do useSetting( 'spacing.units' ) in core blocks, it means we'll still allow custom units. I guess that means custom units are opt-out these days, that's fine but we should clarify how themes can opt-out of custom units and if that's even something we allow.
  • The other point is that if a theme removes % from the available units, it is still possible to use a pattern or a variation with that unit (for instance columns variations), Right now, the block works well but the UI in the inspector shows another unit as selected, maybe we should show the unit but disabled?
  • The third item I noted is that right now it's too complex for blocks to use the units config, a fallback is necessary and a call to an experimental useCustomUnits hook is needed, I think ideally we should simplify that and just pass useSetting( 'spacing.units' ) as a prop to the UI component. Some refactoring/simplification might be needed there.

cc @nosolosw @aristath

Metadata

Metadata

Assignees

No one assigned

    Labels

    CustomizationIssues related to Phase 2: Customization efforts[Feature] ThemesQuestions or issues with incorporating or styling blocks in a theme.[Type] Code QualityIssues or PRs that relate to code quality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions