Skip to content

[WIP] Forms: migrate Outlined form style for inner block based fields - #43327

Merged
ramonjd merged 0 commit into
update/migrate-form-fields-to-inner-blocksfrom
try/migrate-form-outline-style
May 16, 2025
Merged

ramonjd merged 0 commit into
update/migrate-form-fields-to-inner-blocksfrom
try/migrate-form-outline-style

Conversation

@ramonjd

@ramonjd ramonjd commented May 1, 2025 •

Copy link
Copy Markdown
Member

Proposed changes:

Fixes https://github.com/Automattic/jetpack-roadmap/issues/2413

The main thrust of this PR is to ensure that the form style "Outlined" works as expected with inner blocks. See: #42890

The side quest is to fix many of the existing bugs in trunk including, but not exclusive to:

  • Multi option fields do not display borders, background styles on the frontend, even though they do in the editor.
  • Multi option fields are not synced with other fields when updating styles in the editor
  • Global styles do not work at all.
  • The select dropdown is styled, but it’s the HTML default in the frontend, and the select arrow icon takes on the input color, but it is always black in the frontend
  • Thick borders interfere with the multi option blocks. You cannot add items.

With this branch you can build amazing forms like this!!

Screenshot 2025-05-15 at 3 45 18 pm

This migration PR is the alternative to deprecating the form at #43366

See JETPACK-273

Prior work:

Testing instructions:

There are two objectives to this PR:

  • make sure the Outline style copes with innerblocks and global styles
  • tweak the styles/functionality so they're better than we left it

Given that, and the many complications and bugs in trunk already, let's not get too picky. The baseline for compatibility is that forms built in trunk shouldn't break when switching to this branch.

Insert a form with lots of fields. Preferably all of them, so let's say at least:

  1. Name
  2. A drop down
  3. A multi checkbox
  4. A multi radio
  5. Textarea

Apply the "outline" style to the form.

For the jetpack/input and jetpack/options blocks, play around with border and background color styles in:

  • theme.json
  • global styles (via the site editor)
  • on individual blocks in the editor

Get funky with large borders and border radii.

In the editor, make sure syncing and sync toggling works (it's a toggle button at the field level)

Check the editor/frontend.

Things should look mostly the same.

Kapture.2025-05-15.at.15.48.35.mp4

In the frontend, (not the editor) open up a few pages forms that you built in trunk previously. They shouldn't be terrible.

@github-actions

github-actions Bot commented May 1, 2025 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the try/migrate-form-outline-style branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack try/migrate-form-outline-style

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented May 1, 2025 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • 🔴 Specify whether this PR includes any changes to data or privacy.
  • 🔴 Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:

## Does this pull request change what data or activity we track or use?

My PR adds *x* and *y*.

🔴 Action required: Please add missing changelog entries for the following projects: projects/packages/forms

Use the Jetpack CLI tool to generate changelog entries by running the following command: jetpack changelog add.
Guidelines: /docs/writing-a-good-changelog-entry.md


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: June 3, 2025
    • Code freeze: June 2, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 1, 2025
@jp-launch-control

jp-launch-control Bot commented May 1, 2025 •

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit e9c1ade8, so cannot calculate coverage changes. 😴

If that commit is a feature branch rather than a trunk commit, this is expected. Otherwise, this should be updated once coverage for e9c1ade8 is available.

Full summary · PHP report · JS report

@talldan

talldan commented May 2, 2025 •

Copy link
Copy Markdown
Contributor

Thanks for exploring this. It looks like this solution has required a lot of jumping through hoops to get to something that works 😭

It feels very complicated, especially on the editor side, I have some concerns over the maintenance burden this would leave in the future.

Thought I'd also mention that I see a similar issue with the animated form style, labels aren't offset correctly when applying a thicker border and will overlap the border. Perhaps the border needs to be applied to the field and not the input, so it's a similar problem of this style requiring that border isn't applied to inputs:
Screenshot 2025-05-02 at 11 53 41 am

I think perhaps we shouldn't be afraid of thinking completely outside the box on this. I'm mentioning ever idea I have, whether good or bad:

  • Deprecating the outlined/animated styles could be an option. I personally wish someone had considered how complicated they were originally and decided to pull the plug!
  • Could adding border supports to field blocks make solving these bugs easier?
  • Alternatively, add border support to the label block since this is the block that has the border. Perhaps it's not intuitive for a user, but I also think this is a very niché feature.
  • Could we disable border controls when outlined/animated style is active? I can't think of a way, but I thought I'd mention the idea. If it were possible, I think it might be my preferred option.
  • It feels like we're being quite respectful to the html used to achieve the 'notched' look. Are there alternatives, like adding the extra html around the input element rather than the label? The input block would need to know the width of the label text (or what the label text is) to achieve the cut-out border, so it's a similar problem of a block being aware of the props of its sibling, but maybe slightly simpler given how complex it is in this PR to resolve the applied style in the editor. 🤔 (edit: I realize we also need all the font styles (size, letter spacing) to make the cut-out accurate, so this is probably also a non-starter).
  • I've also been wondering if there are any css tricks to achieve a similar look (e.g using border-image for the cut-out), but I haven't found anything that doesn't come with other issues (border-image doesn't support border-radius).

@andrewserong

andrewserong commented May 2, 2025 •

Copy link
Copy Markdown
Member

Thanks for exploring this.

💯 this is a very thorny one, thanks for diving deep on it!

Could we disable border controls when outlined/animated style is active? I can't think of a way, but I thought I'd mention the idea. If it were possible, I think it might be my preferred option.

This is a good point if we think this winds up being too complex to fix for these styles — I've been trying to think of how it could be possible to dynamically disable the controls. Unfortunately the simple filter for removing support altogether is all or nothing rather than based on conditions, so the following wouldn't work for us:

const skipBorders = settings => {
	if ( settings.name.indexOf( 'jetpack/input' ) > -1 ) {
		if ( settings.supports.__experimentalBorder ) {
			delete settings.supports.__experimentalBorder;
		}
	}
	return settings;
};

addFilter( 'blocks.registerBlockType', 'jetpack/contact-form/skip-borders', skipBorders );

Something else I'm wondering — it wouldn't be performant, but would it be possible to add a hook to the InputEdit component where we update the block editor settings if we're in a field block that's a child of a block using the Outlined styles? So we'd update settings.__experimentalFeatures.blocks.jetpack/field/border to be set to false (or its border props set to false). Then as a cleanup task, update again to remove that / reset to the original settings? I suppose I'm imagining something similar(ish) to useSyncedAttributes in that sense 🤔. I haven't tried this, so this is just an idle thought!

@talldan

talldan commented May 2, 2025 •

Copy link
Copy Markdown
Contributor

While experimenting/researching I found a way to achieve the cut-out in the border using css clip-path: https://codepen.io/talldan/pen/JoopZNO

This might allow us to keep the border applied to the input, but two issues:

  • it's a minor thing, but it also clips the input's background if we wanted it to extend under the border.
  • We'd need to know exactly where the clipping should start and end, which I think means getting the computed size and position of the label. That's not something I love the idea of, especially when you factor in every input on the screen needing to do this. 😬

@ramonjd

ramonjd commented May 4, 2025 •

Copy link
Copy Markdown
Member Author

Thanks @talldan and @andrewserong for helping to think about this issue.

I took a pretty naive approach first off, but my main objectives were to cause minimum disruption to the users running this style.

Now, this is despite the fact that this style — at least in terms of borders — does not work in the first place: on trunk, alternative border styles do not have any effect on radio and checkbox fields in my testing

Kapture.2025-05-01.at.07.38.24.mp4

So feature parity rather than feature fixing 😄

My impressions while working on this were similar to yours: I'm having serious doubts about the feasibility of this exercise, and I'd expect, with good intentions, we'd be doing users a favor by deprecating outline and possible animated styles.

It feels very complicated, especially on the editor side, I have some concerns over the maintenance burden this would leave in the future.

This is true. 💯

What's also true is that this style is already seriously complicated, and brutally fragile, by which I mean the maintenance burden already exists.

I think we'd need to weigh inconvenience to developers against user experience - which should win here?

Clearly users of this style should not be in a place where their forms break, but we also shouldn't allow users to dive deeper into a hole (the hole being the outline style) and run the risk of committing to a broken and buggy style.

Deprecating the outlined/animated styles could be an option. I personally wish someone had considered how complicated they were originally and decided to pull the plug!

+1

I would prefer deprecation, I'm just not sure how we should tackle the UX flow.

We need to make sure forms on the frontend won't be unaffected until the user edits a post and the form "migrates". That means keeping the current code, or a different version of it around.

It will cause confusion if the form in the editor looks radically different to what the user expects.

Furthermore, the user might have several outline forms on their site, all of which would have to be migrated separately assuming they need to look the same.

I think, in the case of deprecation, we'd have to inform the user of the situation in the editor, that is that editing the page would reset/remove the styles.

Could we disable border controls when outlined/animated style is active? I can't think of a way, but I thought I'd mention the idea. If it were possible, I think it might be my preferred option.

Let's say there's a performant way, or @andrewserong's idea above works, we'd still be facing the same conundrum of what to do with existing forms that have border styles.

What the UX here? A user would open their post with an outline form and any borders they've applied wouldn't be there?

I don't know.

While experimenting/researching I found a way to achieve the cut-out in the border using css clip-path:

Thanks for following up on this! Do you think it's worth investing time in going down that path?

Or would we be replacing the outline feature with another of equal complexity?

@andrewserong

andrewserong commented May 5, 2025 •

Copy link
Copy Markdown
Member

Great points @ramonjd!

What's also true is that this style is already seriously complicated, and brutally fragile, by which I mean the maintenance burden already exists.
I think we'd need to weigh inconvenience to developers against user experience - which should win here?

I think your instincts are right to prioritise the user experience. Of all the options we've discussed so far, the direction of this PR sounds the most promising to me.

Deprecating these styles sounds appealing since it'd involve reducing what we maintain, and hiding options for a style we're not sure of how to support also has its appeal. Yet I can't help but feel that in both of those cases we're actively creating a worse UX, and thinking back over my comment from last week, I don't really see how we could meaningfully "switch off" the border controls when the outlined or animated styles are applied 🤔

Whereas with the approach here, within the context of the inner blocks refactor, we're making a best effort to try to maintain compatibility. I think that's a worthy goal, but I do admit it's hard to weigh up!

Keen to hear what others think too, and I'll do some more testing of this PR, as well.

@ramonjd

ramonjd commented May 5, 2025

Copy link
Copy Markdown
Member Author

For what it's worth, here's the current state of this branch. It's pretty close.

Building a form in trunk

Kapture.2025-05-05.at.11.04.56.mp4

Switching to this branch

Kapture.2025-05-05.at.11.06.13.mp4

There are one or two things left to do as you can see in the last video, namely, ensuring that global styles/theme.json presets are applied correctly. I'm working on that now.

There is one material improvement: the editor no longer lies to the user by applying border styles to checkbox fields 😄

I reckon we can clean/abstract a few things to reduce the maintenance shock.

@talldan

talldan commented May 5, 2025

Copy link
Copy Markdown
Contributor

What's also true is that this style is already seriously complicated, and brutally fragile, by which I mean the maintenance burden already exists.

It's the exact reason in my mind why we should choose not to support it and deprecate it. The alternative is to build something complicated on top of something that we admit is already fragile. It compounds the problem. A bad experience for users is one that is fragile and breaks. I'm not saying this PR is broken, but if the code is admittedly complex and built on something fragile, then there's a good chance it'll break in the future. For me, this is particularly the case because of the way this PR is using low level APIs to merge the global style layers. This is an API that WordPress should provide, rather than Jetpack having a custom implementation.

I think we should at least discuss what deprecation would look like. I think it could be something like this:

  • Remove the style variations
  • is-style-animated and is-style-outline become custom classnames for users
  • The CSS for those styles has high enough specificity to override any global/block styles (hopefully just border) that might break the appearance
  • The frontend rendering code has a condition that checks for is-style-outline class and inserts the extra markup (and code comments explaining why it does this.
  • Tests are added to make sure it continues to work.

Anyway, if we choose to continue with this PR, I think we need to also not forget that the animated style is also broken, and make sure the solution works for both styles.

@ramonjd

ramonjd commented May 5, 2025 •

Copy link
Copy Markdown
Member Author

It's the exact reason in my mind why we should choose not to support it and deprecate it.

I'm all for deprecation, and would be more than happy to discontinue this PR. Also thanks for outlining the rough steps.

Something has to be done about these styles - we're forced into a corner either way if the inner blocks migration is to go ahead.

At least in terms of the outline style, it's already half broken so deprecating will be putting it out of its misery.

A bad experience for users is one that is fragile and breaks.

💯

I think from a user's perspective, deprecating is a breaking change in the editor. That's the main concern I have.

I think being upfront about it via a modal message or some other comms trick could mitigate.

I can get a deprecate branch started so we can see it in action.

@andrewserong

Copy link
Copy Markdown
Member

I think from a user's perspective, deprecating is a breaking change in the editor. That's the main concern I have.

Same. The other question I have is about scope: but this can go either way — with the inner blocks refactor, how do we minimise how much we're changing at once? Unfortunately both deprecation and ensuring compatibility add complexity to the code change and to what we need to test 😞

Also thanks for outlining the rough steps [...] I can get a deprecate branch started so we can see it in action.

Thank you both!

In these situations where we're trying to find a balance or trade-off, having branches to play with should help us figure out which way to go. Or at the very least, it'll help give us options we can point to when we ask other folks to help us decide!

@talldan

talldan commented May 5, 2025

Copy link
Copy Markdown
Contributor

I think from a user's perspective, deprecating is a breaking change in the editor. That's the main concern I have.

I think it's ok personally, the main thing is to keep the same appearance on the frontend. Probably the main challenge is retaining custom border sizes. Though it looks kinda broken in trunk with the label not centered correctly, so there are probably not many users doing this:
Screenshot 2025-05-05 at 12 30 26 pm

If we want to go an extra step, we could consider adding some messaging in the UI if the user has one of these deprecated styles active.

A nice follow-up to the whole global styles effort would be to introduce a new range of form style variations that use global styles properties entirely rather than custom css. I think it should be possible to come up with some better and simpler styles.

@talldan

talldan commented May 5, 2025

Copy link
Copy Markdown
Contributor

Something I just remembered. The style variations were previously broken in the editor, not sure how long for, but possibly quite a long time - #41457. Maybe if I hadn't fixed them this whole conversation would be easier 😄

@simison, it'd be great to get your thoughts on this too.

@talldan
talldan force-pushed the update/migrate-form-fields-to-inner-blocks branch from 942e010 to 3317f84 Compare May 5, 2025 05:51
@ramonjd

ramonjd commented May 5, 2025

Copy link
Copy Markdown
Member Author

I think we should at least discuss what deprecation would look like. I think it could be something like this:

Here we go:

Optionally, we could add an embedded alert in each form with a legacy style (not this one), but just to give you an idea:

Screenshot 2025-05-05 at 4 43 47 pm

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests labels May 5, 2025
@ramonjd

ramonjd commented May 5, 2025

Copy link
Copy Markdown
Member Author

The style variations were previously broken in the editor, not sure how long for, but possibly quite a long time - #41457. Maybe if I hadn't fixed them this whole conversation would be easier

Given that they've been broken for what seems like forever, I feel better about deprecation.

@ramonjd

ramonjd commented May 6, 2025

Copy link
Copy Markdown
Member Author

I've been playing around with refactoring options and I can get something close...

https://codepen.io/ramonjd/pen/ByyxExd

But even then there'll be differences.

For the outline style, the first thing to dump is the notch HTML, and also accepting that a label background color must be set.

@ramonjd
ramonjd force-pushed the try/migrate-form-outline-style branch from 0f5647c to d192258 Compare May 6, 2025 02:11

@andrewserong andrewserong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just left a couple of tiny PHP nits to please the linter, etc, when we're ready for polishing that side of things.

import { store as blockEditorStore } from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';

export default function useGetInnerBlock( clientId, blockName ) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's a path to combine this with useSibling, but I left it in case we roll back these changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The latest code seems to be going back to the old approach of setting css values on field blocks, which I'd moved away from, so I'll have a look at if we can remove it.

I think we need to have every field working the same, as otherwise it'll be too challenging to keep up with all the inconsistencies.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah yeah, fair enough. Wasn't thinking. I'll see if they can be added to the options block itself.

@ramonjd ramonjd May 9, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in: a153a80

They're doubled up by necessity (on label and options blocks) since the options needs to calculate inner padding. Same as inputs I see. I think my brain was trying to avoid the duplication. I dunno 😄

TODO on Monday: ensure the CSS vars are applied to radio/checkboxes on the frontend. (They're not)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as inputs I see. I think my brain was trying to avoid the duplication.

My thinking is it still ends up being duplication whether on the field or input/options blocks, but at least on the input/options blocks the attributes we need are the ones from the block itself, so it saves a step.

$is_animated_style = 'animated' === $form_style;
$fieldset_id = "id='" . esc_attr( "$id-label" ) . "'";

if ( $is_animated_style ) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pretty dodgy. Either this, or add the notched HTML to animated style multi fields in the editor. The less of that the better I guessed.

TODO: test this in trunk-created forms. Might need to gate it for inner block forms only.

@ramonjd
ramonjd marked this pull request as ready for review May 15, 2025 05:08
@ramonjd ramonjd removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels May 15, 2025
@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 15, 2025

@ramonjd ramonjd left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Testing okay so far. At least it's an improvement!

I checked RTL too: not shabby

template,
templateLock: 'all',
} );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can roll back this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not so sure. I think everything depends on this change. I don't want to see the whole house of cards come crashing down.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right.

This is hilarious and tragic at the same time. 🤣

Hilaragic


$css_vars .= "--jetpack--contact-form--left-offset: calc(var(--jetpack--contact-form--input-padding-left, 16px) + {$border_left_size});";
$css_vars .= '--jetpack--contact-form--label-left: max(var(--jetpack--contact-form--left-offset), var(--jetpack--contact-form--border-radius));';
$css_vars .= "--jetpack--contact-form--field-padding: calc(var(--jetpack--contact-form--label-left) - {$border_left_size});";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This PR simplifies these CSS vars #43469

I'm not convinced they're required for the animated style.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@talldan

Good news I think. I think we can remove the variable left padding for the Outlined style when there's lots of radius and border.

We've replicated the behaviour from trunk, but in trunk the indentation only occurs in the editor, and has no effect on the frontend in my testing.

Here's trunk:

Trunk editor Trunk frontend
Screenshot 2025-05-16 at 11 07 08 am Screenshot 2025-05-16 at 11 07 25 am

Comment on lines +1174 to +1182
$first_el = $this->getFirstElement( $doc, 'div' );
/**
* If the contact form has the `is-style-outlined` class name, we need to get the second div element.
* This is because, to achieve the outlined effect, the first div is the wrapper div, and the second div is the field wrapper div.
*/
if ( isset( $contact_form_attributes['className'] ) && 'is-style-outlined' === $contact_form_attributes['className'] ) {
$first_el = $this->getFirstElement( $doc, 'div', 1 );
}
return $first_el;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You know your code smells when you have to document the unit tests 😄

@talldan
talldan force-pushed the try/migrate-form-outline-style branch from 5255b49 to 9801aee Compare May 15, 2025 07:22
@ramonjd

ramonjd commented May 16, 2025 •

Copy link
Copy Markdown
Member Author

In this testing I created 6 forms in trunk, then loaded them unchanged in this branch to compare.

The screenshots are all from the frontend.

It's mostly good.

Style Trunk This branch
Default Trunk default 1 Feature default 1
Outlined Trunk outlined 3 Feature outlined 3
Outlined Trunk outlined 2 Feature outlined 2
Outlined Trunk outlined 1 Feature outlined 1
Animated Trunk animated 2 Feature animated 2
Animated Trunk animated 1 Feature animated 1

Some observations/differences. In the feature branch:

  • There is too much left padding/indentation in the controls in Outlined style. I think we can get rid of it. See comment
  • The options label (legend tag) hovers too far above the fieldset in Outlined style when other inputs have border radii, but the options don't. This one is weird.
  • The button style option checkboxes are square. They are round in trunk

Minor things... Getting close!

// We check the left side due to writing direction—this variable is used to offset text.
// TODO: this should factor in RTL languages.
if ( style?.borderTopLeftRadius || style?.borderBottomLeftRadius ) {
return `max( ${ style?.borderTopLeftRadius ?? 0 }, ${ style?.borderBottomLeftRadius ?? 0 } )`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it might be better to refactor to individual css vars like this:

--jetpack--contact-form--border-top-left-radius: ${ style?.borderRadius ?? style?.borderTopLeftRadius };
--jetpack--contact-form--border-top-right-radius: ${ style?.borderRadius ?? style?.borderTopRightRadius };
--jetpack--contact-form--border-bottom-right-radius: ${ style?.borderRadius ?? style?.borderBottomRightRadius };
--jetpack--contact-form--border-bottom-left-radius: ${ style?.borderRadius ?? style?.borderBottomLeftRadius };

Assuming a single border radius value from the two corners is a shortcut to get it working and not very clear in terms of the naming of the css var. It's something that could cause confusion for devs later, so I think better to be explicit with the naming.

Possibly the same for the border size css var.

However, I might leave it to later for a smaller PR.

@ramonjd
ramonjd merged this pull request into update/migrate-form-fields-to-inner-blocks May 16, 2025
@ramonjd
ramonjd deleted the try/migrate-form-outline-style branch May 16, 2025 04:04
@github-actions github-actions Bot removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 16, 2025
ramonjd added a commit that referenced this pull request May 16, 2025
…#43327)

* first commit

* backend mania

* Removing dividing two top of label. Can reinstate

* fix number conversion

* Match legacy form behaviour when deriving px values for CSS vars

* color, typography

* Adjust clip path to cater for 1px borders

* Implement outline style support for form fields by integrating useFormStyleOutlineClassesAndStyles hook across various blocks. Update CSS variables and styles for outlined and animated form styles in the contact form backend and frontend components.

* Cannot fix overlap right now

* Trying to fix select, options, etc

* desperately trying to assign the right values to css vars

* get background working

* path to syncing options

* use lodash for merging

* global styles specificity

* Remove isSynced from hook and related code

* Try only using hook on label

* Inject CSS vars for input as well as label so that it can calculate correct padding

* Call it a jetpack contact form notch width

* Fix overflowing background when a narrow border-width is set

* Fix input block placeholders not selectable/visible when outlined style is active

* Fix animated style label and input offset

* Animated style: fix label and input offset when using distinct border left style in editor

* Fix trailing notch background color

* Inputs should take border radius styles so they match the notched border. Fix global style derivation for borders

* Fix incorrect block names

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Improve support for split border radii in outlined form style

* Remove min width for notch

* This commit syncs jetpack/options with jetpack/input

* abstract get inner block hook

* esc notched attrs

* Check $legacy values before assignment

* move css vars to inner elems

* Apply the background to the notch elements again instead of the input to ensure border aligns with background. Remove the z-index rule so that the input/placeholder is visible and can be edited

* Adding padding where there's a border

Enhance contact form styles and structure by adding support for animated styles, adjusting border colors, and refining fieldset rendering logic.

* Add filler notch element on frontend

* Fix flex shrink/grow of notch elements with new filler notch element

* Limit padding of inputs to support a wider range of border radii units

This helps prevent situations where the calculated padding can end up
being a huge number when units like % are used. 100% might make sense for
a border radius, but that value used for a padding is huge. Cap the padding
at 100px to match trunk's max border radius value.

* Ensure dropdowns have same styles for input as other fields, DRY up

* Updated rendering logic in the contact form fields to differentiate between outlined and animated styles. Introduced a new helper function to manage outlined style attributes and adjusted CSS to ensure proper styling for outlined fields. Cleaned up related code for clarity and maintainability.

* Ensure default padding for outlined styles in inputs

* Refactor contact form styles to ensure global styles can override default border and padding settings. Updated class logic for option groups to conditionally apply border styles based on attributes, enhancing flexibility and maintainability.

* Account for split border radius when calculating css var on the frontend

* Set a max width for any elements using --jetpack--contact-form--notch-width of 100px

* Update tests with new shortcode attributes and styles for outline and options

* Switch inputs and labels for the outlined and animated style so that label is above input

* Remove background on inputs for outlined style, background is being applied to labels instead

* Add filler notch element to match editor styles

* Add max-width for trailing notch element

* Fix border radius css var not picking up single values with a unit

* Remove border radius and clip path on inputs for outlined style (border radius is applied on the label, clip path does nothing)

* Update tests with new attributes and outline HTML

* Default white background in the editor

* Ensure the Button variation on the Multiple Choice (Checkbox) block inherits the current color from the option block.

* Add background color support for outlined style in contact form inputs and update related tests

* Fix outlined border radius for checkbox multiple

* Fix css border-radius var calculation

* Fix checkbox multiple radius for outlined style

* Small tidy up

* Enhance outline styles handling in contact form fields by adding form style parameter and refining border radius calculations. Update CSS to include z-index for animated labels.

* Apply outlined border radius style to radio fields to match other fields

* Remove spaces in inline styles

* Select arrow position, default padding for has-background

* Padding magic on the options in outlined

* Add font size adjustment for legend in outlined contact form style

* Fix position of legend and right padding for options

* Remove export of constant

* Combine is_outlined `if` statements for checkbox multiple

* Combine is_outlined `if` statements for radio

* Rename useFormStyleOutlineClassesAndStyles to useVariationStyleProperties

* Only memoize based on changes to block type when merging global styles

* Add documentation to useVariationStyleProperties

* Small tidy up, rename a function and add docs

* Remove commented out css declarations

* Remove dead code. Context is unused. Anywhere. Go look if you don't believe me.

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
talldan added a commit that referenced this pull request May 28, 2025
…#43327)

* first commit

* backend mania

* Removing dividing two top of label. Can reinstate

* fix number conversion

* Match legacy form behaviour when deriving px values for CSS vars

* color, typography

* Adjust clip path to cater for 1px borders

* Implement outline style support for form fields by integrating useFormStyleOutlineClassesAndStyles hook across various blocks. Update CSS variables and styles for outlined and animated form styles in the contact form backend and frontend components.

* Cannot fix overlap right now

* Trying to fix select, options, etc

* desperately trying to assign the right values to css vars

* get background working

* path to syncing options

* use lodash for merging

* global styles specificity

* Remove isSynced from hook and related code

* Try only using hook on label

* Inject CSS vars for input as well as label so that it can calculate correct padding

* Call it a jetpack contact form notch width

* Fix overflowing background when a narrow border-width is set

* Fix input block placeholders not selectable/visible when outlined style is active

* Fix animated style label and input offset

* Animated style: fix label and input offset when using distinct border left style in editor

* Fix trailing notch background color

* Inputs should take border radius styles so they match the notched border. Fix global style derivation for borders

* Fix incorrect block names

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Improve support for split border radii in outlined form style

* Remove min width for notch

* This commit syncs jetpack/options with jetpack/input

* abstract get inner block hook

* esc notched attrs

* Check $legacy values before assignment

* move css vars to inner elems

* Apply the background to the notch elements again instead of the input to ensure border aligns with background. Remove the z-index rule so that the input/placeholder is visible and can be edited

* Adding padding where there's a border

Enhance contact form styles and structure by adding support for animated styles, adjusting border colors, and refining fieldset rendering logic.

* Add filler notch element on frontend

* Fix flex shrink/grow of notch elements with new filler notch element

* Limit padding of inputs to support a wider range of border radii units

This helps prevent situations where the calculated padding can end up
being a huge number when units like % are used. 100% might make sense for
a border radius, but that value used for a padding is huge. Cap the padding
at 100px to match trunk's max border radius value.

* Ensure dropdowns have same styles for input as other fields, DRY up

* Updated rendering logic in the contact form fields to differentiate between outlined and animated styles. Introduced a new helper function to manage outlined style attributes and adjusted CSS to ensure proper styling for outlined fields. Cleaned up related code for clarity and maintainability.

* Ensure default padding for outlined styles in inputs

* Refactor contact form styles to ensure global styles can override default border and padding settings. Updated class logic for option groups to conditionally apply border styles based on attributes, enhancing flexibility and maintainability.

* Account for split border radius when calculating css var on the frontend

* Set a max width for any elements using --jetpack--contact-form--notch-width of 100px

* Update tests with new shortcode attributes and styles for outline and options

* Switch inputs and labels for the outlined and animated style so that label is above input

* Remove background on inputs for outlined style, background is being applied to labels instead

* Add filler notch element to match editor styles

* Add max-width for trailing notch element

* Fix border radius css var not picking up single values with a unit

* Remove border radius and clip path on inputs for outlined style (border radius is applied on the label, clip path does nothing)

* Update tests with new attributes and outline HTML

* Default white background in the editor

* Ensure the Button variation on the Multiple Choice (Checkbox) block inherits the current color from the option block.

* Add background color support for outlined style in contact form inputs and update related tests

* Fix outlined border radius for checkbox multiple

* Fix css border-radius var calculation

* Fix checkbox multiple radius for outlined style

* Small tidy up

* Enhance outline styles handling in contact form fields by adding form style parameter and refining border radius calculations. Update CSS to include z-index for animated labels.

* Apply outlined border radius style to radio fields to match other fields

* Remove spaces in inline styles

* Select arrow position, default padding for has-background

* Padding magic on the options in outlined

* Add font size adjustment for legend in outlined contact form style

* Fix position of legend and right padding for options

* Remove export of constant

* Combine is_outlined `if` statements for checkbox multiple

* Combine is_outlined `if` statements for radio

* Rename useFormStyleOutlineClassesAndStyles to useVariationStyleProperties

* Only memoize based on changes to block type when merging global styles

* Add documentation to useVariationStyleProperties

* Small tidy up, rename a function and add docs

* Remove commented out css declarations

* Remove dead code. Context is unused. Anywhere. Go look if you don't believe me.

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
ramonjd added a commit that referenced this pull request Jun 3, 2025
…#43327)

* first commit

* backend mania

* Removing dividing two top of label. Can reinstate

* fix number conversion

* Match legacy form behaviour when deriving px values for CSS vars

* color, typography

* Adjust clip path to cater for 1px borders

* Implement outline style support for form fields by integrating useFormStyleOutlineClassesAndStyles hook across various blocks. Update CSS variables and styles for outlined and animated form styles in the contact form backend and frontend components.

* Cannot fix overlap right now

* Trying to fix select, options, etc

* desperately trying to assign the right values to css vars

* get background working

* path to syncing options

* use lodash for merging

* global styles specificity

* Remove isSynced from hook and related code

* Try only using hook on label

* Inject CSS vars for input as well as label so that it can calculate correct padding

* Call it a jetpack contact form notch width

* Fix overflowing background when a narrow border-width is set

* Fix input block placeholders not selectable/visible when outlined style is active

* Fix animated style label and input offset

* Animated style: fix label and input offset when using distinct border left style in editor

* Fix trailing notch background color

* Inputs should take border radius styles so they match the notched border. Fix global style derivation for borders

* Fix incorrect block names

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Improve support for split border radii in outlined form style

* Remove min width for notch

* This commit syncs jetpack/options with jetpack/input

* abstract get inner block hook

* esc notched attrs

* Check $legacy values before assignment

* move css vars to inner elems

* Apply the background to the notch elements again instead of the input to ensure border aligns with background. Remove the z-index rule so that the input/placeholder is visible and can be edited

* Adding padding where there's a border

Enhance contact form styles and structure by adding support for animated styles, adjusting border colors, and refining fieldset rendering logic.

* Add filler notch element on frontend

* Fix flex shrink/grow of notch elements with new filler notch element

* Limit padding of inputs to support a wider range of border radii units

This helps prevent situations where the calculated padding can end up
being a huge number when units like % are used. 100% might make sense for
a border radius, but that value used for a padding is huge. Cap the padding
at 100px to match trunk's max border radius value.

* Ensure dropdowns have same styles for input as other fields, DRY up

* Updated rendering logic in the contact form fields to differentiate between outlined and animated styles. Introduced a new helper function to manage outlined style attributes and adjusted CSS to ensure proper styling for outlined fields. Cleaned up related code for clarity and maintainability.

* Ensure default padding for outlined styles in inputs

* Refactor contact form styles to ensure global styles can override default border and padding settings. Updated class logic for option groups to conditionally apply border styles based on attributes, enhancing flexibility and maintainability.

* Account for split border radius when calculating css var on the frontend

* Set a max width for any elements using --jetpack--contact-form--notch-width of 100px

* Update tests with new shortcode attributes and styles for outline and options

* Switch inputs and labels for the outlined and animated style so that label is above input

* Remove background on inputs for outlined style, background is being applied to labels instead

* Add filler notch element to match editor styles

* Add max-width for trailing notch element

* Fix border radius css var not picking up single values with a unit

* Remove border radius and clip path on inputs for outlined style (border radius is applied on the label, clip path does nothing)

* Update tests with new attributes and outline HTML

* Default white background in the editor

* Ensure the Button variation on the Multiple Choice (Checkbox) block inherits the current color from the option block.

* Add background color support for outlined style in contact form inputs and update related tests

* Fix outlined border radius for checkbox multiple

* Fix css border-radius var calculation

* Fix checkbox multiple radius for outlined style

* Small tidy up

* Enhance outline styles handling in contact form fields by adding form style parameter and refining border radius calculations. Update CSS to include z-index for animated labels.

* Apply outlined border radius style to radio fields to match other fields

* Remove spaces in inline styles

* Select arrow position, default padding for has-background

* Padding magic on the options in outlined

* Add font size adjustment for legend in outlined contact form style

* Fix position of legend and right padding for options

* Remove export of constant

* Combine is_outlined `if` statements for checkbox multiple

* Combine is_outlined `if` statements for radio

* Rename useFormStyleOutlineClassesAndStyles to useVariationStyleProperties

* Only memoize based on changes to block type when merging global styles

* Add documentation to useVariationStyleProperties

* Small tidy up, rename a function and add docs

* Remove commented out css declarations

* Remove dead code. Context is unused. Anywhere. Go look if you don't believe me.

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
talldan added a commit that referenced this pull request Jun 4, 2025
…#43327)

* first commit

* backend mania

* Removing dividing two top of label. Can reinstate

* fix number conversion

* Match legacy form behaviour when deriving px values for CSS vars

* color, typography

* Adjust clip path to cater for 1px borders

* Implement outline style support for form fields by integrating useFormStyleOutlineClassesAndStyles hook across various blocks. Update CSS variables and styles for outlined and animated form styles in the contact form backend and frontend components.

* Cannot fix overlap right now

* Trying to fix select, options, etc

* desperately trying to assign the right values to css vars

* get background working

* path to syncing options

* use lodash for merging

* global styles specificity

* Remove isSynced from hook and related code

* Try only using hook on label

* Inject CSS vars for input as well as label so that it can calculate correct padding

* Call it a jetpack contact form notch width

* Fix overflowing background when a narrow border-width is set

* Fix input block placeholders not selectable/visible when outlined style is active

* Fix animated style label and input offset

* Animated style: fix label and input offset when using distinct border left style in editor

* Fix trailing notch background color

* Inputs should take border radius styles so they match the notched border. Fix global style derivation for borders

* Fix incorrect block names

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Improve support for split border radii in outlined form style

* Remove min width for notch

* This commit syncs jetpack/options with jetpack/input

* abstract get inner block hook

* esc notched attrs

* Check $legacy values before assignment

* move css vars to inner elems

* Apply the background to the notch elements again instead of the input to ensure border aligns with background. Remove the z-index rule so that the input/placeholder is visible and can be edited

* Adding padding where there's a border

Enhance contact form styles and structure by adding support for animated styles, adjusting border colors, and refining fieldset rendering logic.

* Add filler notch element on frontend

* Fix flex shrink/grow of notch elements with new filler notch element

* Limit padding of inputs to support a wider range of border radii units

This helps prevent situations where the calculated padding can end up
being a huge number when units like % are used. 100% might make sense for
a border radius, but that value used for a padding is huge. Cap the padding
at 100px to match trunk's max border radius value.

* Ensure dropdowns have same styles for input as other fields, DRY up

* Updated rendering logic in the contact form fields to differentiate between outlined and animated styles. Introduced a new helper function to manage outlined style attributes and adjusted CSS to ensure proper styling for outlined fields. Cleaned up related code for clarity and maintainability.

* Ensure default padding for outlined styles in inputs

* Refactor contact form styles to ensure global styles can override default border and padding settings. Updated class logic for option groups to conditionally apply border styles based on attributes, enhancing flexibility and maintainability.

* Account for split border radius when calculating css var on the frontend

* Set a max width for any elements using --jetpack--contact-form--notch-width of 100px

* Update tests with new shortcode attributes and styles for outline and options

* Switch inputs and labels for the outlined and animated style so that label is above input

* Remove background on inputs for outlined style, background is being applied to labels instead

* Add filler notch element to match editor styles

* Add max-width for trailing notch element

* Fix border radius css var not picking up single values with a unit

* Remove border radius and clip path on inputs for outlined style (border radius is applied on the label, clip path does nothing)

* Update tests with new attributes and outline HTML

* Default white background in the editor

* Ensure the Button variation on the Multiple Choice (Checkbox) block inherits the current color from the option block.

* Add background color support for outlined style in contact form inputs and update related tests

* Fix outlined border radius for checkbox multiple

* Fix css border-radius var calculation

* Fix checkbox multiple radius for outlined style

* Small tidy up

* Enhance outline styles handling in contact form fields by adding form style parameter and refining border radius calculations. Update CSS to include z-index for animated labels.

* Apply outlined border radius style to radio fields to match other fields

* Remove spaces in inline styles

* Select arrow position, default padding for has-background

* Padding magic on the options in outlined

* Add font size adjustment for legend in outlined contact form style

* Fix position of legend and right padding for options

* Remove export of constant

* Combine is_outlined `if` statements for checkbox multiple

* Combine is_outlined `if` statements for radio

* Rename useFormStyleOutlineClassesAndStyles to useVariationStyleProperties

* Only memoize based on changes to block type when merging global styles

* Add documentation to useVariationStyleProperties

* Small tidy up, rename a function and add docs

* Remove commented out css declarations

* Remove dead code. Context is unused. Anywhere. Go look if you don't believe me.

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
talldan added a commit that referenced this pull request Jun 4, 2025
* Add base form field blocks

Introduces foundational form field blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

These blocks will be reused across all field types using inner blocks.

* changelog

* Fix issues with style syncing hook:

- Prevents adding bulk changes when syncing blocks to the undo stack
- Correctly determines the parent field block for option blocks to check
  if syncing is enabled
- Correctly find all option blocks regardless of whether they are a
  field's direct child, e.g. consent, or nested within an options block
  e.g. single/multiple choice fields.

* Prevent style syncing when blocks are reused in previews

* Ensure label is editable after being emptied and placeholder shows

* Opt out of block gap spacing for Options block

This is an enhancement over trunk however the is some work required to
make this actually work, especially given the shortcode rendering on the
frontend. For the time being this support will explicitly be opted out
of. It can be revisited when the benefit justifies the additional
complexity and work.

* Migrate form field blocks to use new base blocks

Updates legacy form field blocks to use shared inner blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

This commit also updates the registration of form blocks so the new
shared blocks are available in the editor.

* changelog

* Fix CSS linting issues

* Make select dropdown field's edit component more robust

* First pass at updating form variations

* Quick clean up of form variations

* Pass required block toolbar control through to Option block for checkbox field

* Clean up form field and inner block attributes

* Remove lodash dependency from dropdown field edit component

* Remove remaining lodash uses in new or updated form blocks

* Remove TODO as Dropdown fields didn't use option styles

* Fix default styling for Consent field option label

* Clean up unrequired TODO item

* Clean some more TODOs

* Restore empty string defaults for input, option, and label blocks

* Revert use sync style hook to previous version retaining undo stack fix

* Fix typo

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Update form field style syncing (#43004)

* Refactor and update form field syncing.

- Use a parent react context provider as the source of truth instead of an
arbitrary sibling block.
- Perform a deep equality check before syncing to prevent against spurious
updates.

* When updating the block own attributes, mark the change as not persistent so that the user can undo

* Prime the previousOwnAttributes value so that we avoid updating syncedAttributes unnecessarily

* Update inline docs

* Prime the synced attributes when they are initially unset

* Fix syncing of styles across checkbox and consent options

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Fix linting error in editor.scss

* Attempt to fix warnings about PhanUndeclaredTypeParameter for WP_Block

* Fix linting issue in class-contact-form.php

* Forms: Prevent errors when synced attribute context is not available (#43027)

* Forms: Fix error thrown in previews for synced form fields

* Clean up

* Rename the context type stuff

* For html_entity_decode, use ENT_COMPAT since we only care about double quotes for the purposes of JSON decoding

* Remove is_array and empty check as we now will always have at least one 'class' attribute on the extra_attrs array

* Add transforms for new inner blocks based fields

* Clean up standalone checkbox inner blocks template

* Clean up dropdown field inner blocks template

* Add example definitions for field block types

* Allow default checked status for standalone option fields

* Fix choice field deprecation edge case

* Fix handling of required and width attributes for Textarea field.

* Fix label block's placeholder fallbacks

* Fix form undo redo issues (#43036)

* Fix undo stack issue with useFormWrapper

* Fix undo stack issue with text area

* Fix undo stack issue with duplicated useFormWrapper

* Fix undo stack issue with consent field block

* Fix undoing after selecting a block variation causing multiple undo steps

* Fix comment typos

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Remove `required` property from template

This is now provided to the child block through context

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Forms: Add PHP unit tests for Migrate form fields to inner blocks JETPACK-262  (#43002)

* inital commit - exploratory

* do_shortcode

* Add test_block_attributes_to_shortcode_attributes_with_styles

* add more simple tests

* remove unnecessary changes

* changelog

* LINTO!

* Adding WP namespaces

* test_gutenblock_render_field_checkbox

* Add test for trim

* Use optionsdata to presume that block_attributes_to_shortcode_attributes has taken place. Let's test that as a unit

* Adding classes and styles in attributes.

* block_attributes_to_shortcode_attributes tests

* text field which has input and label

* Phan complains about \DOMNode::getAttribute. Shut it up.

* Try to quiet Phan again by passing a WP_Block instance

* Attempt to fix a couple of the code coverage warnings

* Try to fix namespace again

* Try using the full namespace for the covers annotation instead of the relative name

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Clean up TODO as the important style for Outlined form style can not be avoided

* Remove extraneous hook dependency

* Remove useFormWrapper audit TODO - all fields use it

* Remove TODOs already captured by issues

* Remove unused ids from consent, checkbox, single choice and multiple choice fields (#43055)

* Fix saving and display of dropdown field placeholder

* Fix dropdown field placeholder default

This commit also updates the dropdown field input's styles to make it
easier to click when the placeholder has previously been cleared.

* Fix style linting error

* Form inner blocks: supplement existing PHP unit tests (#43076)

* Enhance unit tests for Contact_Form_Block by adding support checks

This commit updates the `test_register_child_blocks` method to include an optional parameter for expected block supports and introduces a new test method, `test_child_blocks_block_supports`, to verify the configuration of block supports for various Jetpack blocks. The data provider for the new test method is also added, ensuring comprehensive testing of block support attributes.

* Add unit test for gutenblock_render_field_radio method

This commit introduces a new test method, `test_gutenblock_gutenblock_render_field_radio`, to validate the rendering of the radio field block in the Contact Form Plugin. The test checks that the generated shortcode matches the expected output, ensuring proper functionality of the radio field block with various attributes and inner blocks.

* changelog

* remove duplicate tests. silly me!

* Apply suggestions from code review

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* syncing server block supports with frontend

* try again

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Allow default checked status for standalone option fields (#43077)

* Fix date picker field incorrect classname (#43059)

* Ensure jetpack-field__input classname applies to date picker input instead of jetpack-field__date

* Remove explicit date type in appointment form variation

* Specify the field type for the date field in the block template

* Iron out inconsistency of date type for date picker inputs

* Tied up text fields array

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Revert "Remove deprecated covers annotations in line with #42902"

This reverts commit 38791a8.

Restoring these in case they were in place for coverage requirements.

* Forms: move @Covers to class level in PHP unit tests (#43081)

* Hoist @cover annotations to class level.

* changelog

* Fix field block examples (#43096)

* Fix field block examples being altered by useFormWrapper

useFormWrapper adds a form wrapper around any field that doesn't have one.

It wasn't preserving the field's own inner blocks, which became visible in the block
examples, where single or multiple choice fields have inner blocks but no wrapper.

This PR ensures the inner blocks are preserved by calling getBlocks to get the inner
blocks of the field and passing that as the inner blocks in the replaceBlocks call
within useFormWrapper.

* Small improvement to variable name

* Add missing useEffect deps

* Fix select/dropdown example

* Switch e2e test close welcome guide code to use preferences

* Forms: Fix display of label and option fallback values in transform previews JETPACK-278 (#43100)

* Add fallback styles for dropdown block when css vars are not populated (#43101)

* Add missed cleaned up label fallback handling

* Fix rendering of legend as a label

- Ensure block class is added to legend element
- Add custom block classes and styles to legend
- Tweak default style specificity so global styles can apply

* Remove redundant array check to make linter happy.

* Clean up dead code in shared JetpackFieldControls

* Try to fix metadata in doc comments warning

* Try updating PHP test attributes again, to hopefully please the linter

* Forms: ensure custom CSS in global styles applies correctly to checkbox and radio wrappers (#43184)

* Refactor class attribute handling in Contact_Form_Field

- Trimmed type variable to ensure consistent class generation.
- Added specific classes for 'checkbox-multiple' and 'radio' types.
- Included TODOs for potential improvements and testing.

* changelog

* Add block styles for checkbox-multiple and radio fields

- Registered new block styles for 'jetpack/field-checkbox-multiple' and 'jetpack/field-radio'.
- Updated class handling in Contact_Form_Field to ensure proper application of styles.
- Adjusted CSS selectors to reflect changes in class structure for button styles.

* Enhance class handling for checkbox-multiple and radio fields

- Updated Contact_Form_Field to apply block style classes to wrapper divs for checkbox-multiple and radio types.
- Introduced a new method to extract block style classes from the class attribute.
- Modified tests to validate the addition of block style classes in the rendering process.

* Refactor block style registration for checkbox-multiple and radio fields

- Consolidated block style registration for 'jetpack/field-checkbox-multiple' and 'jetpack/field-radio' into a single call.
- Updated comments to clarify the purpose of style registration and future improvements.
- Adjusted class handling in Contact_Form_Field to include new class naming conventions.

* Refactor block style application for checkbox-multiple and radio fields

- Streamlined the handling of block style classes for 'checkbox-multiple' and 'radio' types in Contact_Form_Field.
- Improved code readability by consolidating conditional checks for block style class assignment.
- Ensured consistent application of styles to wrapper divs for both field types.

* Enhance radio field rendering tests and block style application

- Added tests to validate rendering of radio fields with block style classes.
- Improved handling of block style classes for radio fields in Contact_Form_Field to ensure consistent application.
- Updated assertions in tests to reflect changes in class structure for radio fields.

* Remove outdated changelog entry for migrating form fields to inner blocks with multiple wrapper styles

* Enhance field wrapper class handling for contact form fields

- Introduced 'fieldwrapperclasses' attribute to allow custom wrapper classes for form fields.
- Updated rendering logic in Contact_Form_Field to utilize the new attribute for consistent styling.
- Refactored tests to validate the addition of 'fieldwrapperclasses' for various field types, ensuring proper application of block styles.

* Try fixing a linting issue with the DataProvider

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Add icons for input, label, option, and options blocks (#43270)

* Form Global Styles: Update CSS specificity to 0-1-0 for default editor styles (excluding outlined style) (#43125)

* Reduce specificity of text area styles to 0-1-0

* Update specificity of option block styles

* Fix option input not scaling with font size for single/multiple choice fields

* Fix font:inherit rule overriding global styles font family setting by reduce specificity

* Add dead code comments

* Forms: only apply `wp-` and `is-style-` classes to fields of new inner block types (#43268)

* Only apply the block style classes to the field wrapper if the field is one of the new inner block types.

* update tests

* Refactor get_block_style_classes to return field wrapper classes and simplify class handling

* Ensure there's no whitespace in unimgrated fields

* Fix missing checkmark for single choice options on frontend (#43301)

* Forms: Fix CSS specificity for compatibility with global styles on the frontend (#43299)

* Fix consent field label css specificity preventing global typography styles

* Fix checkbox/radio option font-weight css specificity preventing global styles

* Remove empty line and duplicate classname

* Fix mixed spaces/tabs indentation

* Fix checkbox/radio input not scaling with font size for single/multiple options fields

* Fix indentation

* Fix button style multiple choice checkbox not receiving global styles font color due to css specificity

* Fix single choice option not receiving text color due to styles not applying to correct element

* Reinstate missing color style

* Move option block style classnames to parent wrapper on frontend

* Make option label font weight inherited from parent block wrapper, add some back compat for default css styles

* Fix tests

* Move option styles to parent block level element

* Forms: remove color gradients block supports (#43427)

* Forms: Update gradient property naming in contact form block and tests to ensure consistency

* Forms: Update gradient property naming to 'gradients' for consistency in input and option blocks

* Fix label typo

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* [WIP] Forms: migrate Outlined form style for inner block based fields (#43327)

* first commit

* backend mania

* Removing dividing two top of label. Can reinstate

* fix number conversion

* Match legacy form behaviour when deriving px values for CSS vars

* color, typography

* Adjust clip path to cater for 1px borders

* Implement outline style support for form fields by integrating useFormStyleOutlineClassesAndStyles hook across various blocks. Update CSS variables and styles for outlined and animated form styles in the contact form backend and frontend components.

* Cannot fix overlap right now

* Trying to fix select, options, etc

* desperately trying to assign the right values to css vars

* get background working

* path to syncing options

* use lodash for merging

* global styles specificity

* Remove isSynced from hook and related code

* Try only using hook on label

* Inject CSS vars for input as well as label so that it can calculate correct padding

* Call it a jetpack contact form notch width

* Fix overflowing background when a narrow border-width is set

* Fix input block placeholders not selectable/visible when outlined style is active

* Fix animated style label and input offset

* Animated style: fix label and input offset when using distinct border left style in editor

* Fix trailing notch background color

* Inputs should take border radius styles so they match the notched border. Fix global style derivation for borders

* Fix incorrect block names

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Improve support for split border radii in outlined form style

* Remove min width for notch

* This commit syncs jetpack/options with jetpack/input

* abstract get inner block hook

* esc notched attrs

* Check $legacy values before assignment

* move css vars to inner elems

* Apply the background to the notch elements again instead of the input to ensure border aligns with background. Remove the z-index rule so that the input/placeholder is visible and can be edited

* Adding padding where there's a border

Enhance contact form styles and structure by adding support for animated styles, adjusting border colors, and refining fieldset rendering logic.

* Add filler notch element on frontend

* Fix flex shrink/grow of notch elements with new filler notch element

* Limit padding of inputs to support a wider range of border radii units

This helps prevent situations where the calculated padding can end up
being a huge number when units like % are used. 100% might make sense for
a border radius, but that value used for a padding is huge. Cap the padding
at 100px to match trunk's max border radius value.

* Ensure dropdowns have same styles for input as other fields, DRY up

* Updated rendering logic in the contact form fields to differentiate between outlined and animated styles. Introduced a new helper function to manage outlined style attributes and adjusted CSS to ensure proper styling for outlined fields. Cleaned up related code for clarity and maintainability.

* Ensure default padding for outlined styles in inputs

* Refactor contact form styles to ensure global styles can override default border and padding settings. Updated class logic for option groups to conditionally apply border styles based on attributes, enhancing flexibility and maintainability.

* Account for split border radius when calculating css var on the frontend

* Set a max width for any elements using --jetpack--contact-form--notch-width of 100px

* Update tests with new shortcode attributes and styles for outline and options

* Switch inputs and labels for the outlined and animated style so that label is above input

* Remove background on inputs for outlined style, background is being applied to labels instead

* Add filler notch element to match editor styles

* Add max-width for trailing notch element

* Fix border radius css var not picking up single values with a unit

* Remove border radius and clip path on inputs for outlined style (border radius is applied on the label, clip path does nothing)

* Update tests with new attributes and outline HTML

* Default white background in the editor

* Ensure the Button variation on the Multiple Choice (Checkbox) block inherits the current color from the option block.

* Add background color support for outlined style in contact form inputs and update related tests

* Fix outlined border radius for checkbox multiple

* Fix css border-radius var calculation

* Fix checkbox multiple radius for outlined style

* Small tidy up

* Enhance outline styles handling in contact form fields by adding form style parameter and refining border radius calculations. Update CSS to include z-index for animated labels.

* Apply outlined border radius style to radio fields to match other fields

* Remove spaces in inline styles

* Select arrow position, default padding for has-background

* Padding magic on the options in outlined

* Add font size adjustment for legend in outlined contact form style

* Fix position of legend and right padding for options

* Remove export of constant

* Combine is_outlined `if` statements for checkbox multiple

* Combine is_outlined `if` statements for radio

* Rename useFormStyleOutlineClassesAndStyles to useVariationStyleProperties

* Only memoize based on changes to block type when merging global styles

* Add documentation to useVariationStyleProperties

* Small tidy up, rename a function and add docs

* Remove commented out css declarations

* Remove dead code. Context is unused. Anywhere. Go look if you don't believe me.

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>

* Add esc_attr calls to render_radio_field (#43488)

* Reinstate default padding where there's a border. Add option chaining to innerBlock look up as trunk forms won't have it.

* Use correct block name in get_ouline_styles (#43489)

* Forms: standardize animated variation style paddings (#43469)

* Update padding for animated style

* Fix updated function

* Rename get_outline_styles

* check borderradius

* Calculate border widths with all sides via CSS vars

* Fix text area top position

* Reinstate default (trunk) padding for animated labels etc

* Default value of null on border sizes

* Remove dupe CSS

* JS Doc :success:

* Add legacy CSS var as default

* Use the `borderwidth` field attribute as the legacy legacy border width value

* Explain use of `borderwidth` value

* Update projects/packages/forms/src/contact-form/class-contact-form-field.php

Use var `$border_width_attribute`

* Add bottom width CSS var to backend, and use border sides in the notched CSS

* Remove styles that we're overriding

* Switch from !empty to isset for legacy borderwidth attribute check

* Do empty/zero check on legacy border widths

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>

* Forms: Fix block instance border color not overriding global styles border color with outlined style active (on the frontend) (#43532)

* Allow block instance border color to override global styles border color

* Remove extra space in class name

* Revert input + option syncing. Bad!

* Forms: Fix typography input styles applying to labels when outline style is active (on frontend) (#43534)

* Fix rogue typography attributes from input applying to label

* Fix bad rebase

* Update tests

* For classic themes, do not destructure theme config objects that don't exist.

* Forms: Fix custom classnames support in inner blocks migration (#43564)

* Forms: fix custom class handling in contact form plugin (#43587)

* Forms: Enhance class handling in contact form plugin and tests

- Updated class handling in `class-contact-form-plugin.php` to filter empty block style classes.
- Modified test cases in `Contact_Form_Plugin_Test.php` and `Contact_Form_Test.php` to include additional attributes and ensure proper class wrapping for various field types.
- Improved assertions to validate class attributes in rendered output.

* Make innerblocks optional. Just for linting

* Forms: Fix outline style label font size (#43590)

* Fix text input-style field label font size when outlined style is active.

* Remove scaling using variable

* Fix scaling of multiple option fields when using outlined style

* Tidy up styles

* Wrap labels

* Fix outlined label font size and animation

* Fix animation by ensuring top is a valid value

* Remove will-change: transform on frontend too. Transform usually does not change.

* Forms: fix inconsistent weights in outline style and terms labels (#43545)

* Ensure that existing font-weight styles do not override block and global label styles.

* Consent weights

* Revert options positioning kram

* Increase specificity to 0 1 0 for classic themes

* Bump specificity of consent label

* Bump specificity

* Forms: Fix animated style label font scaling (#43615)

* Fix animated style label font size in editor

* Add span wrapper around label text

* Update animated label styles on frontend

* Size and animation adjustments for required text

* Fix label animating when selected in editor if using the animated form style variation and no placeholder is set

* Forms Fix animated label centered positioning (#43635)

* Fix animated label vertical centering when using uneven borders in the input

* Remove unused cass var

* Forms: Remove options text color support (#43612)

* Remove text color support for jetpack/options, since frontend does not replicate the markup of the editor and so style parity cannot be achieved

* Try to fix tests

* Whoops, wrong flag

* One more time

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Forms: options block layout tweaks (#43531)

* Refactor contact form styles and rendering logic to enhance alignment and maintainability. Update CSS for radio and checkbox options to use consistent alignment, and streamline fieldset and div class attributes by removing unnecessary prefixes. Improve handling of border styles and attributes for outlined forms, ensuring compatibility with global styles.

* Try baseline for the options

* Revert changes to "fix" option alignment

* Revert option alignment v2

* Add classes to tests

* Reinstate tweaks for option positioning

* Apply wp-block-jetpack-option class in the attribute migration method

* Use em instead of rem. Remove unnecessary tweaks

* Border support for classic themes

* Ensure radio inputs don't warp in classic themes. Update options description

* Force opinionated dimensions on the options inputs

* wp-block-jetpack-option was not being applied to inner options blocks

* Forms: update padding for jetpack options in contact form to conform with trunk (#43634)

* consolidate legends

* Remove styles that are inconsistent with existing trunk spacing. (frontend)

* Remove padding in editor

* editor

* The feature branch has different markup for .wp-block-jetpack-options so we need to target the fieldset using different selectors

* comments

* Fix date field label suffix font size for outlined/animated styles

* Fix option input color not inherited in editor

* Forms: Update border radius and width handling in deprecateFieldStyles function (#43653)

* Attempt to fix warnings about PhanUndeclaredTypeParameter for WP_Block

* Forms: Update border radius and width handling in deprecateFieldStyles function

* Ensure border radius and width are correctly set to 'undefined' only when they are not provided or are null, allowing for proper handling of zero values.

* Coerce lineheight to str

* REvert  - bad rebase

* Update class-contact-form-plugin.php

My IDE auto formatted this

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Remove duplicated styles

* Form: fix default fallbacks for unmigrated forms (#43676)

* Outlined multi option backgrounds defaults

* Don't concat the label and option styles for consent and single option in unmigrated forms

* PHPCS warning - Use statements are not alphabetically sorted (MediaWiki.Classes.UnsortedUseStatements.UnsortedUse

* Forms: tame select arrow positioning (#43674)

* initial commit - adding extra markup to the select rendering and fixing positioning of labels

* uncommenting

* Remove default select border

* Update select field rendering to include a wrapper div with the correct class structure for improved styling and consistency in tests.

* Update contact form styles to inherit text color and adjust z-index for select wrapper elements

* Only run `getAttribute` on select wrapper if there is one

* Reinstate padding change

* phan me

* phanos

* whitespace

* Ensure that animated labels sit above active input elements.

* Forms: account for missing placeholder when transforming input fields to select dropdown and fix z-index (#43721)

* Enhance select field transformation by adding default placeholder for input block. Update contact form plugin to correctly reference placeholder attribute. Adjust z-index values in CSS for improved label positioning.

* Update z-index values in contact form CSS for improved label positioning and remove redundant styles for outlined fields.

* Complete CSS comment

* Refactor select field transformation to set placeholder attribute directly from attributes. Remove redundant placeholder handling in inner block creation.

* Revert createTextFieldInnerBlocks

* Revert experiment. Add default placeholder for select in createTextFieldInnerBlocks

* Don't mutate the attributes object

* Don't spread optional chaining just in case

* Update contact form styles to prevent color overrides by global styles. Add 'color: unset !important;' to both editor.scss and grunion.css for consistent input appearance. (#43737)

* Fix consent field spacing between checkbox and label (#43743)

* Update context types to use kebab casing (#43740)

* Forms: Fix required form field validation for options blocks in the inner blocks refactor (#43738)

* Update accessible form selectors for single/multiple choice fields (#43760)

* Forms: refactor placeholder handling for outlined and styled forms (#43759)

* Forms: Refactor placeholder handling in contact form fields

* Simplify placeholder logic to ensure consistent rendering of input fields.
* Remove unnecessary conditionals for placeholder assignment and improve code clarity.

* Forms: Update contact form styles and placeholder handling

* Adjusted placeholder logic to ensure it only renders when a value is present, improving input field consistency.
* Updated the contact form stylesheet to include a version query string for better cache management.
* Commented out specific CSS rules to prevent unintended side effects related to placeholder visibility in outlined and animated label styles.

* Remove other :not(:placeholder-shown) styles

* Remove multiple changelogs for branches that were never merged to trunk

---------

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Ramon <ramonjd@gmail.com>
mikestottuk pushed a commit that referenced this pull request Jun 26, 2025
* Add base form field blocks

Introduces foundational form field blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

These blocks will be reused across all field types using inner blocks.

* changelog

* Fix issues with style syncing hook:

- Prevents adding bulk changes when syncing blocks to the undo stack
- Correctly determines the parent field block for option blocks to check
  if syncing is enabled
- Correctly find all option blocks regardless of whether they are a
  field's direct child, e.g. consent, or nested within an options block
  e.g. single/multiple choice fields.

* Prevent style syncing when blocks are reused in previews

* Ensure label is editable after being emptied and placeholder shows

* Opt out of block gap spacing for Options block

This is an enhancement over trunk however the is some work required to
make this actually work, especially given the shortcode rendering on the
frontend. For the time being this support will explicitly be opted out
of. It can be revisited when the benefit justifies the additional
complexity and work.

* Migrate form field blocks to use new base blocks

Updates legacy form field blocks to use shared inner blocks:
- jetpack/input
- jetpack/label
- jetpack/option
- jetpack/options

This commit also updates the registration of form blocks so the new
shared blocks are available in the editor.

* changelog

* Fix CSS linting issues

* Make select dropdown field's edit component more robust

* First pass at updating form variations

* Quick clean up of form variations

* Pass required block toolbar control through to Option block for checkbox field

* Clean up form field and inner block attributes

* Remove lodash dependency from dropdown field edit component

* Remove remaining lodash uses in new or updated form blocks

* Remove TODO as Dropdown fields didn't use option styles

* Fix default styling for Consent field option label

* Clean up unrequired TODO item

* Clean some more TODOs

* Restore empty string defaults for input, option, and label blocks

* Revert use sync style hook to previous version retaining undo stack fix

* Fix typo

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Update form field style syncing (#43004)

* Refactor and update form field syncing.

- Use a parent react context provider as the source of truth instead of an
arbitrary sibling block.
- Perform a deep equality check before syncing to prevent against spurious
updates.

* When updating the block own attributes, mark the change as not persistent so that the user can undo

* Prime the previousOwnAttributes value so that we avoid updating syncedAttributes unnecessarily

* Update inline docs

* Prime the synced attributes when they are initially unset

* Fix syncing of styles across checkbox and consent options

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Fix linting error in editor.scss

* Attempt to fix warnings about PhanUndeclaredTypeParameter for WP_Block

* Fix linting issue in class-contact-form.php

* Forms: Prevent errors when synced attribute context is not available (#43027)

* Forms: Fix error thrown in previews for synced form fields

* Clean up

* Rename the context type stuff

* For html_entity_decode, use ENT_COMPAT since we only care about double quotes for the purposes of JSON decoding

* Remove is_array and empty check as we now will always have at least one 'class' attribute on the extra_attrs array

* Add transforms for new inner blocks based fields

* Clean up standalone checkbox inner blocks template

* Clean up dropdown field inner blocks template

* Add example definitions for field block types

* Allow default checked status for standalone option fields

* Fix choice field deprecation edge case

* Fix handling of required and width attributes for Textarea field.

* Fix label block's placeholder fallbacks

* Fix form undo redo issues (#43036)

* Fix undo stack issue with useFormWrapper

* Fix undo stack issue with text area

* Fix undo stack issue with duplicated useFormWrapper

* Fix undo stack issue with consent field block

* Fix undoing after selecting a block variation causing multiple undo steps

* Fix comment typos

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Remove `required` property from template

This is now provided to the child block through context

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Forms: Add PHP unit tests for Migrate form fields to inner blocks JETPACK-262  (#43002)

* inital commit - exploratory

* do_shortcode

* Add test_block_attributes_to_shortcode_attributes_with_styles

* add more simple tests

* remove unnecessary changes

* changelog

* LINTO!

* Adding WP namespaces

* test_gutenblock_render_field_checkbox

* Add test for trim

* Use optionsdata to presume that block_attributes_to_shortcode_attributes has taken place. Let's test that as a unit

* Adding classes and styles in attributes.

* block_attributes_to_shortcode_attributes tests

* text field which has input and label

* Phan complains about \DOMNode::getAttribute. Shut it up.

* Try to quiet Phan again by passing a WP_Block instance

* Attempt to fix a couple of the code coverage warnings

* Try to fix namespace again

* Try using the full namespace for the covers annotation instead of the relative name

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Clean up TODO as the important style for Outlined form style can not be avoided

* Remove extraneous hook dependency

* Remove useFormWrapper audit TODO - all fields use it

* Remove TODOs already captured by issues

* Remove unused ids from consent, checkbox, single choice and multiple choice fields (#43055)

* Fix saving and display of dropdown field placeholder

* Fix dropdown field placeholder default

This commit also updates the dropdown field input's styles to make it
easier to click when the placeholder has previously been cleared.

* Fix style linting error

* Form inner blocks: supplement existing PHP unit tests (#43076)

* Enhance unit tests for Contact_Form_Block by adding support checks

This commit updates the `test_register_child_blocks` method to include an optional parameter for expected block supports and introduces a new test method, `test_child_blocks_block_supports`, to verify the configuration of block supports for various Jetpack blocks. The data provider for the new test method is also added, ensuring comprehensive testing of block support attributes.

* Add unit test for gutenblock_render_field_radio method

This commit introduces a new test method, `test_gutenblock_gutenblock_render_field_radio`, to validate the rendering of the radio field block in the Contact Form Plugin. The test checks that the generated shortcode matches the expected output, ensuring proper functionality of the radio field block with various attributes and inner blocks.

* changelog

* remove duplicate tests. silly me!

* Apply suggestions from code review

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* syncing server block supports with frontend

* try again

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Allow default checked status for standalone option fields (#43077)

* Fix date picker field incorrect classname (#43059)

* Ensure jetpack-field__input classname applies to date picker input instead of jetpack-field__date

* Remove explicit date type in appointment form variation

* Specify the field type for the date field in the block template

* Iron out inconsistency of date type for date picker inputs

* Tied up text fields array

---------

Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>

* Revert "Remove deprecated covers annotations in line with #42902"

This reverts commit 38791a8.

Restoring these in case they were in place for coverage requirements.

* Forms: move @Covers to class level in PHP unit tests (#43081)

* Hoist @cover annotations to class level.

* changelog

* Fix field block examples (#43096)

* Fix field block examples being altered by useFormWrapper

useFormWrapper adds a form wrapper around any field that doesn't have one.

It wasn't preserving the field's own inner blocks, which became visible in the block
examples, where single or multiple choice fields have inner blocks but no wrapper.

This PR ensures the inner blocks are preserved by calling getBlocks to get the inner
blocks of the field and passing that as the inner blocks in the replaceBlocks call
within useFormWrapper.

* Small improvement to variable name

* Add missing useEffect deps

* Fix select/dropdown example

* Switch e2e test close welcome guide code to use preferences

* Forms: Fix display of label and option fallback values in transform previews JETPACK-278 (#43100)

* Add fallback styles for dropdown block when css vars are not populated (#43101)

* Add missed cleaned up label fallback handling

* Fix rendering of legend as a label

- Ensure block class is added to legend element
- Add custom block classes and styles to legend
- Tweak default style specificity so global styles can apply

* Remove redundant array check to make linter happy.

* Clean up dead code in shared JetpackFieldControls

* Try to fix metadata in doc comments warning

* Try updating PHP test attributes again, to hopefully please the linter

* Forms: ensure custom CSS in global styles applies correctly to checkbox and radio wrappers (#43184)

* Refactor class attribute handling in Contact_Form_Field

- Trimmed type variable to ensure consistent class generation.
- Added specific classes for 'checkbox-multiple' and 'radio' types.
- Included TODOs for potential improvements and testing.

* changelog

* Add block styles for checkbox-multiple and radio fields

- Registered new block styles for 'jetpack/field-checkbox-multiple' and 'jetpack/field-radio'.
- Updated class handling in Contact_Form_Field to ensure proper application of styles.
- Adjusted CSS selectors to reflect changes in class structure for button styles.

* Enhance class handling for checkbox-multiple and radio fields

- Updated Contact_Form_Field to apply block style classes to wrapper divs for checkbox-multiple and radio types.
- Introduced a new method to extract block style classes from the class attribute.
- Modified tests to validate the addition of block style classes in the rendering process.

* Refactor block style registration for checkbox-multiple and radio fields

- Consolidated block style registration for 'jetpack/field-checkbox-multiple' and 'jetpack/field-radio' into a single call.
- Updated comments to clarify the purpose of style registration and future improvements.
- Adjusted class handling in Contact_Form_Field to include new class naming conventions.

* Refactor block style application for checkbox-multiple and radio fields

- Streamlined the handling of block style classes for 'checkbox-multiple' and 'radio' types in Contact_Form_Field.
- Improved code readability by consolidating conditional checks for block style class assignment.
- Ensured consistent application of styles to wrapper divs for both field types.

* Enhance radio field rendering tests and block style application

- Added tests to validate rendering of radio fields with block style classes.
- Improved handling of block style classes for radio fields in Contact_Form_Field to ensure consistent application.
- Updated assertions in tests to reflect changes in class structure for radio fields.

* Remove outdated changelog entry for migrating form fields to inner blocks with multiple wrapper styles

* Enhance field wrapper class handling for contact form fields

- Introduced 'fieldwrapperclasses' attribute to allow custom wrapper classes for form fields.
- Updated rendering logic in Contact_Form_Field to utilize the new attribute for consistent styling.
- Refactored tests to validate the addition of 'fieldwrapperclasses' for various field types, ensuring proper application of block styles.

* Try fixing a linting issue with the DataProvider

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Add icons for input, label, option, and options blocks (#43270)

* Form Global Styles: Update CSS specificity to 0-1-0 for default editor styles (excluding outlined style) (#43125)

* Reduce specificity of text area styles to 0-1-0

* Update specificity of option block styles

* Fix option input not scaling with font size for single/multiple choice fields

* Fix font:inherit rule overriding global styles font family setting by reduce specificity

* Add dead code comments

* Forms: only apply `wp-` and `is-style-` classes to fields of new inner block types (#43268)

* Only apply the block style classes to the field wrapper if the field is one of the new inner block types.

* update tests

* Refactor get_block_style_classes to return field wrapper classes and simplify class handling

* Ensure there's no whitespace in unimgrated fields

* Fix missing checkmark for single choice options on frontend (#43301)

* Forms: Fix CSS specificity for compatibility with global styles on the frontend (#43299)

* Fix consent field label css specificity preventing global typography styles

* Fix checkbox/radio option font-weight css specificity preventing global styles

* Remove empty line and duplicate classname

* Fix mixed spaces/tabs indentation

* Fix checkbox/radio input not scaling with font size for single/multiple options fields

* Fix indentation

* Fix button style multiple choice checkbox not receiving global styles font color due to css specificity

* Fix single choice option not receiving text color due to styles not applying to correct element

* Reinstate missing color style

* Move option block style classnames to parent wrapper on frontend

* Make option label font weight inherited from parent block wrapper, add some back compat for default css styles

* Fix tests

* Move option styles to parent block level element

* Forms: remove color gradients block supports (#43427)

* Forms: Update gradient property naming in contact form block and tests to ensure consistency

* Forms: Update gradient property naming to 'gradients' for consistency in input and option blocks

* Fix label typo

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* [WIP] Forms: migrate Outlined form style for inner block based fields (#43327)

* first commit

* backend mania

* Removing dividing two top of label. Can reinstate

* fix number conversion

* Match legacy form behaviour when deriving px values for CSS vars

* color, typography

* Adjust clip path to cater for 1px borders

* Implement outline style support for form fields by integrating useFormStyleOutlineClassesAndStyles hook across various blocks. Update CSS variables and styles for outlined and animated form styles in the contact form backend and frontend components.

* Cannot fix overlap right now

* Trying to fix select, options, etc

* desperately trying to assign the right values to css vars

* get background working

* path to syncing options

* use lodash for merging

* global styles specificity

* Remove isSynced from hook and related code

* Try only using hook on label

* Inject CSS vars for input as well as label so that it can calculate correct padding

* Call it a jetpack contact form notch width

* Fix overflowing background when a narrow border-width is set

* Fix input block placeholders not selectable/visible when outlined style is active

* Fix animated style label and input offset

* Animated style: fix label and input offset when using distinct border left style in editor

* Fix trailing notch background color

* Inputs should take border radius styles so they match the notched border. Fix global style derivation for borders

* Fix incorrect block names

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>

* Improve support for split border radii in outlined form style

* Remove min width for notch

* This commit syncs jetpack/options with jetpack/input

* abstract get inner block hook

* esc notched attrs

* Check $legacy values before assignment

* move css vars to inner elems

* Apply the background to the notch elements again instead of the input to ensure border aligns with background. Remove the z-index rule so that the input/placeholder is visible and can be edited

* Adding padding where there's a border

Enhance contact form styles and structure by adding support for animated styles, adjusting border colors, and refining fieldset rendering logic.

* Add filler notch element on frontend

* Fix flex shrink/grow of notch elements with new filler notch element

* Limit padding of inputs to support a wider range of border radii units

This helps prevent situations where the calculated padding can end up
being a huge number when units like % are used. 100% might make sense for
a border radius, but that value used for a padding is huge. Cap the padding
at 100px to match trunk's max border radius value.

* Ensure dropdowns have same styles for input as other fields, DRY up

* Updated rendering logic in the contact form fields to differentiate between outlined and animated styles. Introduced a new helper function to manage outlined style attributes and adjusted CSS to ensure proper styling for outlined fields. Cleaned up related code for clarity and maintainability.

* Ensure default padding for outlined styles in inputs

* Refactor contact form styles to ensure global styles can override default border and padding settings. Updated class logic for option groups to conditionally apply border styles based on attributes, enhancing flexibility and maintainability.

* Account for split border radius when calculating css var on the frontend

* Set a max width for any elements using --jetpack--contact-form--notch-width of 100px

* Update tests with new shortcode attributes and styles for outline and options

* Switch inputs and labels for the outlined and animated style so that label is above input

* Remove background on inputs for outlined style, background is being applied to labels instead

* Add filler notch element to match editor styles

* Add max-width for trailing notch element

* Fix border radius css var not picking up single values with a unit

* Remove border radius and clip path on inputs for outlined style (border radius is applied on the label, clip path does nothing)

* Update tests with new attributes and outline HTML

* Default white background in the editor

* Ensure the Button variation on the Multiple Choice (Checkbox) block inherits the current color from the option block.

* Add background color support for outlined style in contact form inputs and update related tests

* Fix outlined border radius for checkbox multiple

* Fix css border-radius var calculation

* Fix checkbox multiple radius for outlined style

* Small tidy up

* Enhance outline styles handling in contact form fields by adding form style parameter and refining border radius calculations. Update CSS to include z-index for animated labels.

* Apply outlined border radius style to radio fields to match other fields

* Remove spaces in inline styles

* Select arrow position, default padding for has-background

* Padding magic on the options in outlined

* Add font size adjustment for legend in outlined contact form style

* Fix position of legend and right padding for options

* Remove export of constant

* Combine is_outlined `if` statements for checkbox multiple

* Combine is_outlined `if` statements for radio

* Rename useFormStyleOutlineClassesAndStyles to useVariationStyleProperties

* Only memoize based on changes to block type when merging global styles

* Add documentation to useVariationStyleProperties

* Small tidy up, rename a function and add docs

* Remove commented out css declarations

* Remove dead code. Context is unused. Anywhere. Go look if you don't believe me.

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>

* Add esc_attr calls to render_radio_field (#43488)

* Reinstate default padding where there's a border. Add option chaining to innerBlock look up as trunk forms won't have it.

* Use correct block name in get_ouline_styles (#43489)

* Forms: standardize animated variation style paddings (#43469)

* Update padding for animated style

* Fix updated function

* Rename get_outline_styles

* check borderradius

* Calculate border widths with all sides via CSS vars

* Fix text area top position

* Reinstate default (trunk) padding for animated labels etc

* Default value of null on border sizes

* Remove dupe CSS

* JS Doc :success:

* Add legacy CSS var as default

* Use the `borderwidth` field attribute as the legacy legacy border width value

* Explain use of `borderwidth` value

* Update projects/packages/forms/src/contact-form/class-contact-form-field.php

Use var `$border_width_attribute`

* Add bottom width CSS var to backend, and use border sides in the notched CSS

* Remove styles that we're overriding

* Switch from !empty to isset for legacy borderwidth attribute check

* Do empty/zero check on legacy border widths

---------

Co-authored-by: Daniel Richards <daniel.richards@automattic.com>

* Forms: Fix block instance border color not overriding global styles border color with outlined style active (on the frontend) (#43532)

* Allow block instance border color to override global styles border color

* Remove extra space in class name

* Revert input + option syncing. Bad!

* Forms: Fix typography input styles applying to labels when outline style is active (on frontend) (#43534)

* Fix rogue typography attributes from input applying to label

* Fix bad rebase

* Update tests

* For classic themes, do not destructure theme config objects that don't exist.

* Forms: Fix custom classnames support in inner blocks migration (#43564)

* Forms: fix custom class handling in contact form plugin (#43587)

* Forms: Enhance class handling in contact form plugin and tests

- Updated class handling in `class-contact-form-plugin.php` to filter empty block style classes.
- Modified test cases in `Contact_Form_Plugin_Test.php` and `Contact_Form_Test.php` to include additional attributes and ensure proper class wrapping for various field types.
- Improved assertions to validate class attributes in rendered output.

* Make innerblocks optional. Just for linting

* Forms: Fix outline style label font size (#43590)

* Fix text input-style field label font size when outlined style is active.

* Remove scaling using variable

* Fix scaling of multiple option fields when using outlined style

* Tidy up styles

* Wrap labels

* Fix outlined label font size and animation

* Fix animation by ensuring top is a valid value

* Remove will-change: transform on frontend too. Transform usually does not change.

* Forms: fix inconsistent weights in outline style and terms labels (#43545)

* Ensure that existing font-weight styles do not override block and global label styles.

* Consent weights

* Revert options positioning kram

* Increase specificity to 0 1 0 for classic themes

* Bump specificity of consent label

* Bump specificity

* Forms: Fix animated style label font scaling (#43615)

* Fix animated style label font size in editor

* Add span wrapper around label text

* Update animated label styles on frontend

* Size and animation adjustments for required text

* Fix label animating when selected in editor if using the animated form style variation and no placeholder is set

* Forms Fix animated label centered positioning (#43635)

* Fix animated label vertical centering when using uneven borders in the input

* Remove unused cass var

* Forms: Remove options text color support (#43612)

* Remove text color support for jetpack/options, since frontend does not replicate the markup of the editor and so style parity cannot be achieved

* Try to fix tests

* Whoops, wrong flag

* One more time

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Forms: options block layout tweaks (#43531)

* Refactor contact form styles and rendering logic to enhance alignment and maintainability. Update CSS for radio and checkbox options to use consistent alignment, and streamline fieldset and div class attributes by removing unnecessary prefixes. Improve handling of border styles and attributes for outlined forms, ensuring compatibility with global styles.

* Try baseline for the options

* Revert changes to "fix" option alignment

* Revert option alignment v2

* Add classes to tests

* Reinstate tweaks for option positioning

* Apply wp-block-jetpack-option class in the attribute migration method

* Use em instead of rem. Remove unnecessary tweaks

* Border support for classic themes

* Ensure radio inputs don't warp in classic themes. Update options description

* Force opinionated dimensions on the options inputs

* wp-block-jetpack-option was not being applied to inner options blocks

* Forms: update padding for jetpack options in contact form to conform with trunk (#43634)

* consolidate legends

* Remove styles that are inconsistent with existing trunk spacing. (frontend)

* Remove padding in editor

* editor

* The feature branch has different markup for .wp-block-jetpack-options so we need to target the fieldset using different selectors

* comments

* Fix date field label suffix font size for outlined/animated styles

* Fix option input color not inherited in editor

* Forms: Update border radius and width handling in deprecateFieldStyles function (#43653)

* Attempt to fix warnings about PhanUndeclaredTypeParameter for WP_Block

* Forms: Update border radius and width handling in deprecateFieldStyles function

* Ensure border radius and width are correctly set to 'undefined' only when they are not provided or are null, allowing for proper handling of zero values.

* Coerce lineheight to str

* REvert  - bad rebase

* Update class-contact-form-plugin.php

My IDE auto formatted this

---------

Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>

* Remove duplicated styles

* Form: fix default fallbacks for unmigrated forms (#43676)

* Outlined multi option backgrounds defaults

* Don't concat the label and option styles for consent and single option in unmigrated forms

* PHPCS warning - Use statements are not alphabetically sorted (MediaWiki.Classes.UnsortedUseStatements.UnsortedUse

* Forms: tame select arrow positioning (#43674)

* initial commit - adding extra markup to the select rendering and fixing positioning of labels

* uncommenting

* Remove default select border

* Update select field rendering to include a wrapper div with the correct class structure for improved styling and consistency in tests.

* Update contact form styles to inherit text color and adjust z-index for select wrapper elements

* Only run `getAttribute` on select wrapper if there is one

* Reinstate padding change

* phan me

* phanos

* whitespace

* Ensure that animated labels sit above active input elements.

* Forms: account for missing placeholder when transforming input fields to select dropdown and fix z-index (#43721)

* Enhance select field transformation by adding default placeholder for input block. Update contact form plugin to correctly reference placeholder attribute. Adjust z-index values in CSS for improved label positioning.

* Update z-index values in contact form CSS for improved label positioning and remove redundant styles for outlined fields.

* Complete CSS comment

* Refactor select field transformation to set placeholder attribute directly from attributes. Remove redundant placeholder handling in inner block creation.

* Revert createTextFieldInnerBlocks

* Revert experiment. Add default placeholder for select in createTextFieldInnerBlocks

* Don't mutate the attributes object

* Don't spread optional chaining just in case

* Update contact form styles to prevent color overrides by global styles. Add 'color: unset !important;' to both editor.scss and grunion.css for consistent input appearance. (#43737)

* Fix consent field spacing between checkbox and label (#43743)

* Update context types to use kebab casing (#43740)

* Forms: Fix required form field validation for options blocks in the inner blocks refactor (#43738)

* Update accessible form selectors for single/multiple choice fields (#43760)

* Forms: refactor placeholder handling for outlined and styled forms (#43759)

* Forms: Refactor placeholder handling in contact form fields

* Simplify placeholder logic to ensure consistent rendering of input fields.
* Remove unnecessary conditionals for placeholder assignment and improve code clarity.

* Forms: Update contact form styles and placeholder handling

* Adjusted placeholder logic to ensure it only renders when a value is present, improving input field consistency.
* Updated the contact form stylesheet to include a version query string for better cache management.
* Commented out specific CSS rules to prevent unintended side effects related to placeholder visibility in outlined and animated label styles.

* Remove other :not(:placeholder-shown) styles

* Remove multiple changelogs for branches that were never merged to trunk

---------

Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Co-authored-by: Ramon <ramonjd@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Form Form block (also see Form package label) [Feature] Forms [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants