From 1e62a5d8c1d1abd643eab25e6457ae7c3296a81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:53:31 +0100 Subject: [PATCH 1/3] Status field: Leave the trash out of the status options A post goes to the trash through the "Move to trash" action, not by editing its status. The field keeps the `trash` element, which filters and views need to label a trashed post, and its own `Edit` now leaves it out of the radio options, so every form gets that without filtering the elements itself. Co-Authored-By: Claude Opus 5.5 --- .../src/post_type_supports/status/edit.tsx | 56 +++++++++++++++ .../src/post_type_supports/status/field.php | 7 +- .../src/post_type_supports/status/field.tsx | 2 + .../src/test/status-edit.jsdom.test.tsx | 71 +++++++++++++++++++ 4 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 packages/core-fields/src/post_type_supports/status/edit.tsx create mode 100644 packages/core-fields/src/test/status-edit.jsdom.test.tsx diff --git a/packages/core-fields/src/post_type_supports/status/edit.tsx b/packages/core-fields/src/post_type_supports/status/edit.tsx new file mode 100644 index 00000000000000..14023df3e2cafa --- /dev/null +++ b/packages/core-fields/src/post_type_supports/status/edit.tsx @@ -0,0 +1,56 @@ +import { useMemo } from '@wordpress/element'; +import type { DataFormControlProps } from '@wordpress/dataviews'; +import { RadioGroupControl } from '@wordpress/ui'; +import type { PostWithStatus } from './types'; + +/* + * The statuses that can't be picked. A post goes to the trash through the + * "Move to trash" action, not by editing its status, yet the field keeps the + * `trash` element so that filters and views can label a trashed post. + */ +const STATUSES_NOT_EDITABLE = [ 'trash' ]; + +/* + * The status control: a radio group of the field's elements, without the + * statuses that can't be picked. + */ +export default function StatusEdit( { + data, + field, + onChange, + hideLabelFromVision, +}: DataFormControlProps< PostWithStatus > ) { + const { label, description, elements, getValue, setValue } = field; + const items = useMemo( + () => + ( elements ?? [] ) + .filter( + ( element ) => + ! STATUSES_NOT_EDITABLE.includes( + String( element.value ) + ) + ) + .map( ( element ) => ( { + value: String( element.value ), + label: element.label, + description: element.description, + } ) ), + [ elements ] + ); + return ( + + onChange( setValue( { item: data, value } ) ) + } + disabled={ field.isDisabled( { item: data, field } ) } + /> + ); +} diff --git a/packages/core-fields/src/post_type_supports/status/field.php b/packages/core-fields/src/post_type_supports/status/field.php index 00ca88fab20535..c7c81eac8ab43f 100644 --- a/packages/core-fields/src/post_type_supports/status/field.php +++ b/packages/core-fields/src/post_type_supports/status/field.php @@ -1,8 +1,10 @@ 'text', 'label' => __( 'Status' ), - 'Edit' => 'radio', 'elements' => array( array( 'value' => 'draft', diff --git a/packages/core-fields/src/post_type_supports/status/field.tsx b/packages/core-fields/src/post_type_supports/status/field.tsx index 5c6b73c4ef206e..71c9b30870c5af 100644 --- a/packages/core-fields/src/post_type_supports/status/field.tsx +++ b/packages/core-fields/src/post_type_supports/status/field.tsx @@ -1,6 +1,7 @@ import { isInTheFuture } from '@wordpress/date'; import type { FieldsScriptParts } from '../../types'; import { hasActionLink } from '../../shared/has-action-link'; +import StatusEdit from './edit'; import type { PostWithStatus } from './types'; import StatusView from './view'; @@ -31,6 +32,7 @@ export const fieldExtensions: FieldsScriptParts< PostWithStatus >[ string ] = { return edits; }, render: StatusView, + Edit: StatusEdit, // A user who can't publish can't change the status either. isDisabled: ( { item } ) => ! hasActionLink( item, 'wp:action-publish' ), }; diff --git a/packages/core-fields/src/test/status-edit.jsdom.test.tsx b/packages/core-fields/src/test/status-edit.jsdom.test.tsx new file mode 100644 index 00000000000000..1327eb6b28fffa --- /dev/null +++ b/packages/core-fields/src/test/status-edit.jsdom.test.tsx @@ -0,0 +1,71 @@ +import { fireEvent, render, screen } from '@testing-library/react'; +import { describe, expect, it, vi } from 'vitest'; +import StatusEdit from '../post_type_supports/status/edit'; +import { fieldExtensions } from '../post_type_supports/status/field'; +import StatusView from '../post_type_supports/status/view'; +import type { PostWithStatus } from '../post_type_supports/status/types'; + +const elements = [ + { value: 'draft', label: 'Draft' }, + { value: 'publish', label: 'Published' }, + { value: 'trash', label: 'Trash' }, +]; + +const field = { + id: 'status', + label: 'Status', + elements, + getValue: fieldExtensions.getValue!, + setValue: fieldExtensions.setValue!, + isDisabled: fieldExtensions.isDisabled!, +} as any; + +const post: PostWithStatus = { + status: 'draft', + _links: { 'wp:action-publish': [ { href: '' } ] }, +}; + +describe( 'StatusEdit', () => { + it( 'offers every status but the trash', () => { + render( + + ); + expect( screen.getAllByRole( 'radio' ) ).toHaveLength( 2 ); + expect( + screen.getByRole( 'radio', { name: 'Published' } ) + ).toBeInTheDocument(); + expect( + screen.queryByRole( 'radio', { name: 'Trash' } ) + ).not.toBeInTheDocument(); + expect( screen.getByRole( 'radio', { name: 'Draft' } ) ).toBeChecked(); + } ); + + it( 'sends the change through the field', () => { + const onChange = vi.fn(); + render( + + ); + fireEvent.click( screen.getByRole( 'radio', { name: 'Published' } ) ); + expect( onChange ).toHaveBeenCalledWith( { status: 'publish' } ); + } ); + + it( 'is disabled for a user who cannot publish', () => { + render( + + ); + for ( const radio of screen.getAllByRole( 'radio' ) ) { + expect( radio ).toHaveAttribute( 'aria-disabled', 'true' ); + } + } ); +} ); + +describe( 'StatusView', () => { + it( 'still labels a trashed post', () => { + render( ); + expect( screen.getByText( 'Trash' ) ).toBeInTheDocument(); + } ); +} ); From 371853c139198f01f0a1b59e43b57c7a75aed177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 27 Nov 2026 11:53:37 +0100 Subject: [PATCH 2/3] Quick edit, Editor: Leave the trash option to the status field The status field's control no longer offers the trash, so the quick edit modals and the inspector don't need to filter it out of the elements. Co-Authored-By: Claude Opus 5.5 --- .../components/post-list/quick-edit-modal.tsx | 20 ++----------------- .../sidebar/dataform-post-summary.jsx | 8 -------- routes/post-list/quick-edit-modal.tsx | 9 --------- 3 files changed, 2 insertions(+), 35 deletions(-) diff --git a/packages/edit-site/src/components/post-list/quick-edit-modal.tsx b/packages/edit-site/src/components/post-list/quick-edit-modal.tsx index 42ff553f3371e9..9ef61bc158fa1a 100644 --- a/packages/edit-site/src/components/post-list/quick-edit-modal.tsx +++ b/packages/edit-site/src/components/post-list/quick-edit-modal.tsx @@ -3,7 +3,7 @@ import { useDispatch, useSelect } from '@wordpress/data'; import { store as coreDataStore } from '@wordpress/core-data'; import type { Post } from '@wordpress/core-data'; import { DataForm } from '@wordpress/dataviews'; -import type { Field, Form } from '@wordpress/dataviews'; +import type { Form } from '@wordpress/dataviews'; import { Button, Modal, @@ -73,23 +73,7 @@ export function QuickEditModal( { const { editEntityRecord, saveEditedEntityRecord } = useDispatch( coreDataStore ); - const _fields = usePostFields( { postType } ); - const fields = useMemo( - () => - _fields?.map( ( field: Field< Post > ) => { - if ( field.id === 'status' ) { - return { - ...field, - elements: field.elements?.filter( - ( element ) => element.value !== 'trash' - ), - }; - } - - return field; - } ), - [ _fields ] - ); + const fields = usePostFields( { postType } ); const form = useMemo( (): Form => { if ( ! quickEditForm ) { diff --git a/packages/editor/src/components/sidebar/dataform-post-summary.jsx b/packages/editor/src/components/sidebar/dataform-post-summary.jsx index 2a8a00f454f4a9..f97d60423c5a28 100644 --- a/packages/editor/src/components/sidebar/dataform-post-summary.jsx +++ b/packages/editor/src/components/sidebar/dataform-post-summary.jsx @@ -296,14 +296,6 @@ export default function DataFormPostSummary( { onActionPerformed } ) { ENTITIES[ postType ]?.[ namespace ]?.isVisible ); } - if ( field.id === 'status' ) { - return { - ...field, - elements: field.elements.filter( - ( element ) => element.value !== 'trash' - ), - }; - } if ( field.id === 'template' ) { // `usePostTemplatePanelMode` is reused in the Post Template panel to match // the existing behavior. If the panel rendered nothing we should exclude the diff --git a/routes/post-list/quick-edit-modal.tsx b/routes/post-list/quick-edit-modal.tsx index 2cae95e49a2fb2..78450250a3727d 100644 --- a/routes/post-list/quick-edit-modal.tsx +++ b/routes/post-list/quick-edit-modal.tsx @@ -111,15 +111,6 @@ export function QuickEditModal( { const fields = useMemo( () => _fields?.map( ( field: any ) => { - if ( field.id === 'status' ) { - return { - ...field, - elements: field.elements.filter( - ( element: { value: string } ) => - element.value !== 'trash' - ), - }; - } if ( field.id === 'featured_media' && field.Edit ) { return { ...field, From 53d0d6fd33e620cf9bdc4f0e4f22929cba68fa89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Maneiro?= <583546+oandregal@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:04:48 +0100 Subject: [PATCH 3/3] Core fields: Add a changelog entry for the status options Co-Authored-By: Claude Opus 5.5 --- packages/core-fields/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core-fields/CHANGELOG.md b/packages/core-fields/CHANGELOG.md index 4e3681513bace8..7a316a4fa19497 100644 --- a/packages/core-fields/CHANGELOG.md +++ b/packages/core-fields/CHANGELOG.md @@ -8,6 +8,7 @@ ### Enhancements +- Status field: Leave the trash out of the status options, so forms no longer have to filter it out ([#87552](https://github.com/WordPress/gutenberg/pull/87552)). - Template field: Disable the field for the front page and the posts page, whose template comes from the reading settings ([#87541](https://github.com/WordPress/gutenberg/pull/87541)). - Author fields: Show initials when the author's profile image is unavailable ([#85208](https://github.com/WordPress/gutenberg/pull/85208)).