WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
9.99k stars 4.02k forks source link

Improve treatment of custom values in Gutenberg form fields #35558

Open kjellr opened 2 years ago

kjellr commented 2 years ago

theme.json and block markup can accept a wide range of values that can't (and probably shouldn't appear in the Gutenberg UI. For example:

All of these are valid block markup. When they are used, Gutenberg currently just shows an empty form field in the UI. For example, here's some sample markup that uses a max() value for padding:

<!-- wp:group {"style":{"spacing":{"padding":{"top":"max(1.25rem, 5vw)","right":"max(1.25rem, 5vw)","bottom":"max(1.25rem, 5vw)","left":"max(1.25rem, 5vw)"}}},"backgroundColor":"foreground","textColor":"background"} -->
<div class="wp-block-group has-background-color has-foreground-background-color has-text-color has-background" style="padding-top:max(1.25rem, 5vw);padding-right:max(1.25rem, 5vw);padding-bottom:max(1.25rem, 5vw);padding-left:max(1.25rem, 5vw)"><!-- wp:paragraph -->
<p>Hello</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

Result:

Screen Shot 2021-10-12 at 11 49 12 AM

We don't want to display these exact CSS calculations, since that'll be too complicated for the user. But we also shouldn't show a blank form field, since the user doesn't know that there's actually a value there. Is there something else we can display in cases like this?

javierarce commented 2 years ago

Here's an idea. We could indicate that all or some of the values are being calculated dynamically showing a message and replacing the calculated field with a button.

image

Some questions:

Figma file

kjellr commented 2 years ago

Yeah, I think this makes sense. I'm not sure of the label here — "dynamic" doesn't seem specific enough, and "*" feels maybe a little vague. Maybe "custom"? 🤔

Would it make sense to show the dynamic value? Maybe in a tooltip?

In general, no — I think these values would confuse more users.

If the user sets a value manually, could we give the option to revert it to its original calculated value?

Yes, I think so. Some sort of "revert" would be great. I'm not sure if this is possible though, since the value might just come from a pasted-in block pattern. In that case, I'm not sure we'd actually be saving it anywhere.

shaunandrews commented 2 years ago

Maybe this could be simpler, and not treated so importantly. For these "dynamic" values, I think we could just dim the text color and update the unit to the "*".

image

Then we could use a tooltip to explain the "*" unit when hovered:

image
kjellr commented 2 years ago

I like that, @shaunandrews! Instead of "This value is calculated automatically", maybe something like "This is a custom dynamic value" or something like that?

Either way, that's a small detail that I think we can refine — I'd love to see a PR to try this out.