Skip to content

Forms: Fix confusion over label/defaultLabel/placeholder - #43767

Merged
talldan merged 4 commits into
update/migrate-form-fields-to-inner-blocksfrom
fix/label-block-placeholder
Jun 5, 2025
Merged

talldan merged 4 commits into
update/migrate-form-fields-to-inner-blocksfrom
fix/label-block-placeholder

Conversation

@talldan

@talldan talldan commented Jun 4, 2025 •

Copy link
Copy Markdown
Contributor

Note: merges into #43765 and not trunk

In #43765 it looks like there's some confusion over the concepts of a placeholder and a default label for the label block. This is what caused the tests to fail when there was an initial attempt to merge #42890.

My take on it is that:

  • placeholder should be what the label block shows in the editor when there’s no label value.
  • defaultLabel should be the value of the label when first inserted, and what the label block shows on the frontend when there’s no label.

In most cases when the code used an attribute called defaultLabel it seems like it should have instead been using an attribute called placeholder (which wasn't a thing before, but it's being added in this PR to replace defaultLabel). The placeholder is only shown in the editor and is used for the label block's aria label, so this is used for text like 'Add label...' and 'Add option...'.

There are a couple of exceptions:

  • The textarea block was actually using defaultLabel differently, to specify a default value of 'Message' or 'Other Details' for the label (which is not a placeholder).
  • The consent block has two different default labels depending on whether the consent type is explicit or not.

In this PR I try to preserve those, but just pass them through as the label value rather than keeping a separate defaultLabel attribute.

Fixes #

Proposed changes:

  • Rename the label block's defaultLabel attribute to placeholder
  • Rename the option block's defaultLabel attribute to placeholder (it has similar ambiguity)
  • Update everywhere to use placeholder where the code was legitimately passing a placeholder value through to the blocks
  • In other instances (Textarea / Consent) where there actually was a default label value, instead pass through that value to the label prop.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

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

Testing instructions:

  • Go to '..'

@talldan talldan self-assigned this Jun 4, 2025
@talldan talldan added Bug When a feature is broken and / or not performing as intended [Feature] Forms [Block] Form Form block (also see Form package label) [Package] Forms [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. Bug labels Jun 4, 2025
@github-actions

github-actions Bot commented Jun 4, 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 fix/label-block-placeholder branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/label-block-placeholder

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 Jun 4, 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: 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!

@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 Jun 4, 2025
Comment on lines -28 to -29
const labelBlockType = getBlockType( 'jetpack/label' );
const defaultLabel = labelBlockType.attributes.label.default;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This bit confused me, as the default value of the label block's label attribute is an empty string.

It seems like there's no need to pass it through.

const { attributes, clientId, id, isSelected, label, requiredText, setAttributes } = props;
const { required, width } = attributes;
const { attributes, clientId, isSelected, setAttributes } = props;
const { id, required, requiredText, width } = attributes;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's no attribute called label from what I could see, and I'm also not sure about requiredText 🤔

That's a label block attribute.

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.

Yeah I think maybe these were simply never updated in this component, as they previously existed on FieldDefaults for all field blocks:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've removed requiredText as well.


const { label, defaultLabel, requiredText } = attributes;
const defaultPlaceholder = __( 'Add label…', 'jetpack-forms' );
const placeholder = emptyToNull( defaultLabel ) ?? emptyToNull( label ) ?? defaultPlaceholder;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is where the bug is that caused the e2e to fail. Anytime the user types in a label, the placeholder gets updated to that label. That includes the aria-label.

Instead the placeholder should stay as something like 'Add label ...' or 'Add option ...'.

return select( blockEditorStore ).getSettings().isPreviewMode;
}, [] );
const placeholder = __( 'Add label…', 'jetpack-forms' );
const placeholderValue = placeholder !== '' ? placeholder : __( 'Add option…', 'jetpack-forms' );

@talldan talldan Jun 4, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The option block needed a similar fix as the label block.

@ramonjd ramonjd Jun 4, 2025 •

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.

I think the option block needs a similar fix.

Isn't this the option block, or did you mean jetpack/options?

I've been testing all blocks and can't see any issues so far with either.

@talldan talldan Jun 5, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, I meant this block (option) needs the same fix as the label block.

It doesn't make much sense when I read it back! (edited it now)

@jp-launch-control

jp-launch-control Bot commented Jun 4, 2025 •

Copy link
Copy Markdown

Code Coverage Summary

No summary data is available for parent commit d4110fa, 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 d4110fa is available.

Full summary · PHP report · JS report

@ramonjd ramonjd 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.

Here's how I've been testing:

  1. In trunk, I created 3 forms (default, outline, animated styles) containing all fields
  2. I switched to this branch, compared results on the frontend (no regressions)
  3. In the editor, fiddled with field labels (update/delete).
  4. Transformed fields

All is working as expected.

I noticed only one regression.

If you remove a label from a field, e.g., name, and then transform it to a select the has-placeholder classname isn't applied in the animated form style. So the label sits in the middle. See the first field in the screenshot. It should look like the second field.

Screenshot 2025-06-05 at 9 35 35 am

I'll look into it.

return select( blockEditorStore ).getSettings().isPreviewMode;
}, [] );
const placeholder = __( 'Add label…', 'jetpack-forms' );
const placeholderValue = placeholder !== '' ? placeholder : __( 'Add option…', 'jetpack-forms' );

@ramonjd ramonjd Jun 4, 2025 •

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.

I think the option block needs a similar fix.

Isn't this the option block, or did you mean jetpack/options?

I've been testing all blocks and can't see any issues so far with either.

@ramonjd

ramonjd commented Jun 4, 2025

Copy link
Copy Markdown
Member

If you remove a label from a field, e.g., name, and then transform it to a select the has-placeholder classname isn't applied in the animated form style. So the label sits in the middle. See the first field in the screenshot. It should look like the second field.

Nothing to do with this PR. I think it's related to my select transform hack. Carry on!

@ramonjd ramonjd 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.

Works well in my testing. I also ran the latest commit against the E2E Calypso PR (passed)

✅

@talldan
talldan marked this pull request as ready for review June 5, 2025 02:50
@talldan

talldan commented Jun 5, 2025 •

Copy link
Copy Markdown
Contributor Author

I think I've addressed all the changes needed. I checked the various patterns and they all work as expected.

Transforms are working too.

@talldan
talldan merged commit 6dbb4c2 into update/migrate-form-fields-to-inner-blocks Jun 5, 2025
@talldan
talldan deleted the fix/label-block-placeholder branch June 5, 2025 02:55
@github-actions github-actions Bot 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 Jun 5, 2025
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) Bug When a feature is broken and / or not performing as intended [Feature] Forms Blocks Blocks designed to streamline user input and engagement, such as contact, newsletter sign-ups, etc. [Feature] Forms [Package] Forms [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants