Repository navigation
Show no option in a native select without a stored value - #131
Contributolo wants to merge 1 commit into
Conversation
A native select without default and allowNull showed its first option while nothing was stored, so the template received false although the editor suggested a choice. Add a disabled empty placeholder while the value is empty, as the SelectControl docs suggest, so the editor shows what is stored. Stored values and rendering are unchanged.
Address #132 with the WordPress ConfirmDialog, retaining textRemove overrides, immediate removal, minimum-row restrictions and nested-row isolation. Prevent portal keyboard events from reordering ancestor rows and cover cancellation, focus, keyboard confirmation and saved deletions in CI browser tests. Integrate reviewed PR #131 with client regression tests and direct first-option selection coverage. Update schemas, generated docs and types, translations, LLM context, changelog and the production editor bundle. Local checks pass: 2048 PHP tests / 6067 assertions, 41 client tests, lint, TypeScript, PHPCS, docs, schemas, translations and build. No local E2E execution. Co-authored-by: Contributolo <[email protected]>
|
Reviewed and incorporated into the unreleased 7.7.4 preparation branch in d1d9ef8, without merging this PR yet. Kept the disabled empty-option policy, added client coverage for empty/null/zero and existing nullable options, and extended the browser regression to choose the first option directly from an untouched empty field. Docs and changelog are included. Local checks pass; the combined branch is going through full [all] CI. Thank you for the focused fix and reproduction. |
|
Included in Blockstudio 7.7.4. The native-select empty state has shipped, including direct selection of the first option and outer/InnerBlocks browser coverage. Your changes were incorporated into the consolidated release branch with integration tests and release adjustments, so I am closing this PR as shipped rather than merging the original branch again. Full CI (14/14) and Distribution (5/5) passed on release commit e1d38df. Thank you for the contribution. |
A
selectfield withoutdefaultand withoutallowNullshows its first option in the inspector while nothing is stored. The block attribute stays"",Block::transform_attributes()turns it intofalse, and the template getsfalse. The editor suggests a choice the frontend never receives. A browser fires no change event when the user picks the option that is already selected, so users cannot store it without first picking another option. Conditions on that field see the empty value too.Cause:
Selectpassesvalue=""(orundefined) toSelectControl, no option has that value, and the browser selects the first<option>. The stylised select (ComboboxControl) and radio fields already show an empty value as nothing selected.Reproduction on main (ec7950d), test block
blockstudio/type-select-emptywith options one/two and no default, in WordPress Playground:one/ "One"{"choice":""}"choice":false<!-- wp:blockstudio/type-select-empty /-->"choice":false{"choice":""}"choice":false"choice":false{"value":"one","label":"One"}"choice":"one""choice":"one"Change: while the value is empty and no option has the value
"", the native select gets a disabled empty option in front, the placeholder pattern from the SelectControl README. It disappears once a value is stored, so the field still cannot be cleared withoutallowNull. Fields withallowNullalready have a""option and are unchanged. Stored values, defaults, the PHP side and the stylised and multiple selects are not touched. Existing posts keep their stored data; an untouched field now shows as empty instead of showing the first option.An alternative would be to store the first option when the block is inserted (what a submitted HTML form would do). I did not do that because it changes stored data and render output for existing blocks, for example
select/InnerBlocksexpects"layout":falseuntil a layout is picked. Happy to switch if you prefer that behavior.Tests:
tests/e2e/types/select/empty.tswith test blocktypes/select/empty: the default renders"choice":false, the inspector value is"", then pickingtwoandonerenders and shows each value, at top level and inside InnerBlocks. On main it fails at "shows no option while nothing is stored" (received"one"), with this change 12/12 pass.types/select/innerBlocks.ts,types/options/select.ts,select-plain-string.ts; also passing with this change:types/conditions-default.ts,types/repeater.types/select/fetch.tsfails at "add test entry" on main and with this change alike in my local setup (port differs from wp-env).npm run checkpasses.Run against WordPress Playground instead of wp-env (no Docker here). The bundle in
includes/admin/assetsis not rebuilt in this branch, so the browser test needsnpm run buildfirst. No docs change: the select section is generated from the schema and documents no behavior for this case.