Skip to content

Radius preset don't support clamp #73018

Closed

Description

@benoitchantre

Description

With the following radius sizes, the UI doesn't allow us to select medium or large because they contain fluid values using clamp.

The slider jumps from small to full.

"radiusSizes": [
	{
		"name": "S",
		"slug": "small",
		"size": "0.3125rem"
	},
	{
		"name": "M",
		"slug": "medium",
		"size": "clamp(0.3125rem, 0.00391rem + 0.39063vw, 0.625rem)"
	},
	{
		"name": "L",
		"slug": "large",
		"size": "clamp(0.625rem, 0.00781rem + 0.78125vw, 1.25rem)"
	},
	{
		"name": "Full",
		"slug": "full",
		"size": "9999px"
	}
]

Step-by-step reproduction instructions

  1. Set some radius sizes from the provided example
  2. Try to apply a medium or large radius using the UI
  3. See that you can select only small or full presets

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 6.9 beta 3

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

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    Needs TestingNeeds further testing to be confirmed.
    Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json
    on Nov 5, 2025
  2. t-hamano commented on Nov 6, 2025

    @t-hamano
    Contributor

    Thanks for the report. The radius preset is a new feature added in the 6.9 release, so let's try fixing it in the 6.9 release.

  3. t-hamano commented on Nov 6, 2025

    @t-hamano
    Contributor

    @aaronrobertshaw @andrewserong @ramonjd, based on my understanding, I suspect that the initial implementation of the radius presets does not allow for complex CSS values. Is it possible to support values ​​that include the clamp function, similar to the spacingSizes preset?

  4. ramonjd commented on Nov 6, 2025

    @ramonjd
    Member

    I'll defer to @aaronrobertshaw but I'm not sure it can work the same way as spacing because of corners?

    From what I've debugged however, it's because the presetIndex is undefined for clamp|min|... values because getPresetValueFromCustomValue is trying to parse value + pixel values.

    When parseQuantityAndUnitFromRawValue can't parse a clamp value like "clamp(1rem, 2vw, 3rem)", it returns [undefined, undefined],

    The following diff fixes it I think

    With the fix, if the original value is a string and parsing fails, we return [value, ''], preserving the clamp value.

    This ensures clamp values flow through getAllValue → getPresetValueFromCustomValue → the component state, so they aren't lost when converting between presets and custom values.

    I left a comment wondering if we should try to check for valid values rather than letting the string through, but sanitization is probably happening in the backend anyway.

    diff --git a/packages/block-editor/src/components/border-radius-control/utils.js b/packages/block-editor/src/components/border-radius-control/utils.js
    index ad39ebdf0a..9b6b56e2a0 100644
    --- a/packages/block-editor/src/components/border-radius-control/utils.js
    +++ b/packages/block-editor/src/components/border-radius-control/utils.js
    @@ -60,9 +60,14 @@ export function getAllValue( values = {} ) {
     		return values;
     	}
     
    -	const parsedQuantitiesAndUnits = Object.values( values ).map( ( value ) =>
    -		parseQuantityAndUnitFromRawValue( value )
    -	);
    +	const parsedQuantitiesAndUnits = Object.values( values ).map( ( value ) => {
    +		const newValue = parseQuantityAndUnitFromRawValue( value );
    +		if ( typeof value === 'string' && newValue[ 0 ] === undefined ) {
    +			// Should we do some string testing here, like the font size picker's `isSimpleCssValue`?
    +			return [ value, '' ];
    +		}
    +		return newValue;
    +	} );
     
     	const allValues = parsedQuantitiesAndUnits.map(
     		( value ) => value[ 0 ] ?? ''
  5. ramonjd commented on Nov 6, 2025

    @ramonjd
    Member
  6. moved this from 📥 Todo to 🏗️ In Progress in WordPress 6.9 Editor Taskson Nov 6, 2025
  7. moved this from 🏗️ In Progress to ✅ Done in WordPress 6.9 Editor Taskson Nov 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Global StylesAnything related to the broader Global Styles efforts, including Styles Engine and theme.json[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions