Repository navigation
Forms: fix choice options inheriting the previous option's label - #51628
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
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: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 4 files.
|
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.
__unstableSplitSelectionnow builds the new sibling viagetSiblingBlockAttributes(), which copies every attribute of the current block except those declaredrole: 'content'(plusmetadata) — the idea being that a new sibling inherits configuration but starts empty:jetpack/optiondeclared no attribute with that role, solabelcounted as configuration and rode along into the new option. The same applied toisOther, 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,isOtherandotherPlaceholderasrole: 'content'.placeholder,requiredText,hideInputandisStandalonestay 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 tojetpack/optionin #43765.Note this only reproduces where Gutenberg is installed, which includes WordPress.com Simple sites. Core's older
createEmpty()did a barecreateBlock( name ), so the released core path was unaffected.insertAfterBlock/insertBeforeBlockuse 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" optiontoggle setlabel: 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 theplaceholderValuefallback 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
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
1. Enter no longer duplicates the label
Apple.Appleand press Enter.Add option…placeholder.Apple.2. Enter on the "Other" option
Otheroption, put the caret at the end, press Enter.Option, notOption (other), and there should be only one "Please specify…" text input).Otheroption with its own free-text input.3. The "Other" toggle keeps your label
Something elseinto an option.Something else, and the "Please specify…" input appears beneath it.Otherplaceholder.Something else.Other, as before.4. Nothing else about option editing changed
AppleandBanana, put the caret at the very start ofBananaand press Backspace — they should still merge into one option readingAppleBanana.