Repository navigation
Forms: Migrate form fields to inner blocks JETPACK-262 - #42890
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 8 files. Only the first 5 are listed here.
88 files are newly checked for coverage. Only the first 5 are listed here.
Full summary · PHP report · JS report Coverage check overridden by
Coverage tests to be added later
|
1ce694a to
9bcd54d
Compare
a2fb901 to
4688f4e
Compare
e57e555 to
c6627ea
Compare
Thanks for the testing @andrewserong 🚀 All patterns at this stage will have legacy blocks that need to run through the block deprecations. I'd recently seen a similar issue to what you described when only some blocks had been migrated previously. It's on my list to dig deeper into but got sidetracked today fixing the style syncing for option blocks across the different field types. |
I hit a block validation error as soon as I attempted to add a Registration Form or the pattern. After tweaking the dropdown field's edit component to be a little more robust, I could replicate the issue you noted. My suspicion is that this could be related to the Quick update: For now I've added a super basic check for whether we're in the template preview mode. In that scenario, the style syncing will return early. This seems to stabilize the preview however the custom JS select field doesn't seem to get setup. That's something I'll look into after some higher priority issues. |
1a776ae to
86c2780
Compare
2171100 to
dd0c310
Compare
86c2780 to
608e4d8
Compare
|
Another couple of wrinkles that might have already been captured elsewhere (Label block issues): Hitting "Enter" from the beginning of a label block adds a new line character, where I'd expect it to insert a paragraph block preceding the parent block: 2025-04-08.13.07.00.mp4When removing the text from a Label field altogether, if you click out from the block and attempt to click back into it, it's not possible to start typing to add in label text again. You can get back to it via the up arrow by keyboard, but I imagine it's that we're not able to click the empty rich text field. Maybe we can add placeholder text while the Label block is selected or something like that? 2025-04-08.13.07.26.mp4 |
|
Appreciate the continued testing @andrewserong 🙇
This is the same behaviour as trunk at the moment but definitely something that can be improved.
Nice catch, that should be an easy enough fix. Until recently the label block had an auto width, I probably just missed also making the RichText component fill the available width when I tweaked the block for that same purpose. I'll get an issue up for the first enhancement and tweak the other one shortly on this branch to hopefully avoid it tripping up others testing. |
608e4d8 to
0f7c84c
Compare
talldan
left a comment
There was a problem hiding this comment.
I've run out of time, so this is a partial review.
| 'jetpack/field-required': 'required', | ||
| 'jetpack/field-defaultValue': 'defaultValue', |
There was a problem hiding this comment.
Minor - I feel like 'jetpack/field/defaultValue' might be preferable to reduce the mix of camel/kebab case mixing. I find it reads a little easier too.
| if ( innerBlocks.length !== 2 ) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
I don't think this condition is a good idea, because if another inner block type (e.g. a validation message block) is added in the future to the multiple choice block, isEligible would return true incorrectly, and that'll cause the migration to run when it shouldn't.
This kind of logic problem with isEligible has caused some bad bugs in the gutenberg codebase:
- Avoid stripping attributes via group block migration when no layout is specified WordPress/gutenberg#63837
- Cover: Explicitly set isUserOverlayColor to false when media is updated WordPress/gutenberg#65105
Maybe removing this if condition and reducing it to the innerBlocks.some check below is enough.
There was a problem hiding this comment.
Either way this isEligible check would need to be updated upon the addition of any validation inner block. For the time being, it's slightly quicker to check the length first.
There was a problem hiding this comment.
Ok, though there are ways that will make it more future proof:
- Return true if the are only option blocks, false otherwise
- Return false if there's a label and/or an options block present, true otherwise.
Both ways it wouldn't matter if a future new block type is supported.
| select => select( blockEditorStore ).getBlock( clientId ).innerBlocks, | ||
| [ clientId ] | ||
| ); | ||
| const options = innerBlocks?.[ 1 ]?.innerBlocks; |
There was a problem hiding this comment.
This could be made more robust, just in case the blocks are reordered for some reason,
|
|
||
| const noop = () => undefined; | ||
|
|
||
| export default function DropdownFieldEdit( props ) { |
There was a problem hiding this comment.
Nitpick
| export default function DropdownFieldEdit( props ) { | |
| export default function SelectFieldEdit( props ) { |
There was a problem hiding this comment.
I'd like to settle on what the field should be called and use that consistently. The original form components named the block field-select however gave the block a human readable label of "Dropdown" which was also used in the code too e.g. JetpackDropdown.
Should this be "dropdown" as that's what most users might expect or "select" given it represents an actual select input?
| if ( innerBlocks.length !== 2 ) { | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Same as for the other block, maybe this can be removed and it'll make the isEligible check more future-proof.
There was a problem hiding this comment.
As noted here, it won't make the check more future proof as the check below would still have to be updated in the event of further valid inner blocks being added
| if ( ! empty( $attributes['options'] ) && is_string( $attributes['options'] ) ) { | ||
| $attributes['options'] = array_map( 'trim', explode( ',', $attributes['options'] ) ); | ||
|
|
||
| // TODO: Work out where these values are set? Are they actually set anywhere? |
There was a problem hiding this comment.
Could it be set by using a shortcode like [contact-field type="checkbox-multiple" values="1,2,3" /]?
Perhaps that was an old version of the shortcode.
I see there's also some code here to construct a shortcode with a values attribute like that:
jetpack/projects/packages/forms/src/contact-form/class-contact-form.php
Lines 879 to 884 in 27ff435
There was a problem hiding this comment.
Yeah, I came to the same conclusion it was for BC purposes. Thanks for looking into it.
|
🐛 Known Issue 🐛 Unfortunately, I think I broke the style syncing when adding some fields to a form. Possibly in: 9954d62. It will be worked on over the next couple of days, so ignore bugs there for the moment. |
…yle is active (on frontend) (#43534) * Fix rogue typography attributes from input applying to label * Fix bad rebase * Update tests
* 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
* 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.
…3545) * 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
* 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
* Fix animated label vertical centering when using uneven borders in the input * Remove unused cass var
* 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>
* 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
…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
…s 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>
* 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
* 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
… 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
…s. Add 'color: unset !important;' to both editor.scss and grunion.css for consistent input appearance. (#43737)
…nner blocks refactor (#43738)
…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

JETPACK-262
Fixes #42358
Proposed changes:
Does this pull request change what data or activity we track or use?
No changes.
Testing instructions:
General Notes
Goal: Confirm all form field blocks insert and behave as expected.
⸻
Goal: Confirm block and global styles apply and override correctly.
⸻
Goal: Verify how styles are shared across synced fields of similar types.
⸻
Goal: Ensure transforming between field types behaves as expected.
⸻
Goal: Ensure all form patterns insert correctly and render well.
Test inserting:
Verify:
⸻
Goal: Validate style variations and layout combinations.
Insert:
For both, test:
⸻
Goal: Confirm fields can be used within layout blocks.
⸻
Goal: Ensure orphaned fields are auto-wrapped in a Form block.
⸻
Goal: Validate required state control across all field types.
⸻
Goal: Confirm legacy forms upgrade smoothly.
Confirm:
⸻
🧑🦯 Keyboard Accessibility
📱 Mobile Responsiveness
Switch the site language to RTL (e.g., Hebrew, Arabic).
Check that:
♻️ Reusable Blocks
⚙️ Editor Performance
🌍 Multilingual / i18n Support