Skip to content

Forms: fix choice options inheriting the previous option's label - #51628

Merged
enejb merged 3 commits into
trunkfrom
fix/forms-option-split-inherits-label
Aug 27, 2026
Merged

enejb merged 3 commits into
trunkfrom
fix/forms-option-split-inherits-label

Conversation

@enejb

@enejb enejb commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Fixes pdtkmj-4Ub#comment-9473

Proposed changes

Two fixes to the choice-field option block (jetpack/option), both reported while authoring a Single choice (radio) field.

1. Pressing Enter created a copy of the previous option instead of an empty one.

Recent Gutenberg builds changed what a split produces. __unstableSplitSelection now builds the new sibling via getSiblingBlockAttributes(), which copies every attribute of the current block except those declared role: 'content' (plus metadata) — the idea being that a new sibling inherits configuration but starts empty:

const excluded = new Set( getBlockAttributesNamesByRole( blockName, 'content' ) );
excluded.add( 'metadata' );
return Object.fromEntries( Object.entries( attributes ).filter( ( [ key ] ) => ! excluded.has( key ) ) );

jetpack/option declared no attribute with that role, so label counted as configuration and rode along into the new option. The same applied to isOther, so pressing Enter at the end of the "Other" option produced a second "Other" option — a state the field's own "Include Other option" toggle can neither create nor represent.

This annotates label, isOther and otherPlaceholder as role: 'content'. placeholder, requiredText, hideInput and isStandalone stay unmarked, because a new sibling should inherit those. The two deprecated option blocks (field-option-radio, field-option-checkbox) already carry the annotation on their label — it was dropped when they were migrated to jetpack/option in #43765.

Note this only reproduces where Gutenberg is installed, which includes WordPress.com Simple sites. Core's older createEmpty() did a bare createBlock( name ), so the released core path was unaffected. insertAfterBlock / insertBeforeBlock use the same helper, so "Insert before/after" on an option was affected too and is fixed by the same change.

2. Toggling an option to "Other" wiped a label the author had already written.

The per-option "Other" option toggle set label: value ? '' : label, so naming an option "Something else" and then switching it to Other silently discarded that text. That clearing came from #47316, whose goal was that an option switched to Other should read "Other" rather than keep a stale name — but the same PR added the placeholderValue fallback that already achieves this: an option with an empty label renders the "Other" placeholder on its own. So the wipe is redundant for unnamed options and destructive for named ones. The toggle now only flips the flag.

Related product discussion/links

  • Reported while testing choice fields on a WordPress.com Simple site.

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

No.

Testing instructions

These changes are only observable with the Gutenberg plugin active (or on a WordPress.com Simple site). On stock core the split path differs and the first bug does not reproduce.

Setup

  • On a site with Jetpack and the Gutenberg plugin active, create a page and add a Form block.
  • Add a Single choice (radio) field.

1. Enter no longer duplicates the label

  • Click into the first option and type Apple.
  • Put the caret at the end of Apple and press Enter.
  • Expected: a new, empty option appears below, showing the Add option… placeholder.
  • Before this PR: the new option read Apple.
  • Repeat with the caret at the end of a middle option in a three-option list — the new empty option should land directly after it, leaving the following options untouched.

2. Enter on the "Other" option

  • In the field's sidebar, turn on Include "Other" option.
  • Click into the Other option, put the caret at the end, press Enter.
  • Expected: a plain empty option, not a second "Other" option (check the block breadcrumb — it should read Option, not Option (other), and there should be only one "Please specify…" text input).
  • Before this PR: a second Other option with its own free-text input.

3. The "Other" toggle keeps your label

  • Type Something else into an option.
  • With that option selected, open the sidebar and turn on "Other" option.
  • Expected: the label stays Something else, and the "Please specify…" input appears beneath it.
  • Before this PR: the label was wiped and the option showed the Other placeholder.
  • Turn the toggle back off — the label should still read Something else.
  • Now do the same on an option you have not named: toggling "Other" option on should make it display Other, as before.

4. Nothing else about option editing changed

  • Press Enter on an empty trailing option — it should still exit the list and drop you into a paragraph after the field.
  • With options Apple and Banana, put the caret at the very start of Banana and press Backspace — they should still merge into one option reading AppleBanana.
  • Deactivate Gutenberg and re-run step 1 — behavior should be unchanged (a new empty option), confirming no regression on stock core.

@enejb enejb added the [Status] Needs Review This PR is ready for review. label Aug 26, 2026
@enejb enejb self-assigned this Aug 26, 2026
@github-actions

github-actions Bot commented Aug 26, 2026 •

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/forms-option-split-inherits-label branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/forms-option-split-inherits-label

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 Aug 26, 2026 •

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 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 🤖


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: September 7, 2026

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

@jp-launch-control

jp-launch-control Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 4 files.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/blocks/option/use-enter.js 1/40 (2.50%) 2.50% -1 💚
projects/packages/forms/src/blocks/shared/hooks/use-synced-attributes.jsx 1/37 (2.70%) 2.70% -1 💚
projects/packages/forms/src/blocks/option/index.jsx 2/6 (33.33%) 33.33% -2 💚
projects/packages/forms/src/blocks/option/edit.jsx 32/46 (69.57%) 69.57% -32 💚

Full summary · PHP report · JS report

@enejb
enejb merged commit e787b20 into trunk Aug 27, 2026
80 checks passed
@enejb
enejb deleted the fix/forms-option-split-inherits-label branch August 27, 2026 17:36
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Aug 27, 2026
@github-actions github-actions Bot added this to the jetpack/16.2 milestone Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant