Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/fields/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- Excerpt field: render nothing when the excerpt is empty. ([#82423](https://github.com/WordPress/gutenberg/pull/82423))

### Bug Fixes

- Hide the date, author and password fields when the post's `_links` lack the `wp:action-publish` / `wp:action-assign-author` relations, matching the classic sidebar. ([#82844](https://github.com/WordPress/gutenberg/pull/82844))
Expand Down
16 changes: 5 additions & 11 deletions packages/fields/src/fields/excerpt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ const excerptField: Field< BasePost > = {
</ExternalLink>
),
render: ( { item } ) => {
let excerpt;
if ( typeof item.excerpt === 'string' ) {
excerpt = !! item.excerpt
? decodeEntities( item.excerpt )
: __( 'Add an excerpt' );
} else {
excerpt = decodeEntities( item.excerpt?.raw || '' );
}
return (
const excerpt =
typeof item.excerpt === 'string' ? item.excerpt : item.excerpt?.raw;
return excerpt ? (
<WCText align="left" numberOfLines={ 3 } truncate>
{ excerpt }
{ decodeEntities( excerpt ) }
</WCText>
);
) : null;
},
Edit: {
control: 'textarea',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,13 @@ test.describe( 'Post Summary', () => {
await admin.createNewPost();
const summary = await openPostSummary( { editor, page } );

await expect(
summary.getByText( 'Add an excerpt', { exact: true } )
).toBeVisible();
const editButton = summary.getByRole( 'button', {
name: 'Edit Excerpt',
} );
// An empty excerpt renders only the label next to the edit button.
await expect( editButton.locator( '..' ) ).toHaveText( 'Excerpt' );

await summary
.getByRole( 'button', { name: 'Edit Excerpt' } )
.click();
await editButton.click();
await page
.getByRole( 'textbox', { name: 'Excerpt' } )
.fill( 'A DataForm excerpt.' );
Expand Down
Loading