Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Details block: use summary content as default label #67217

Merged
Merged
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
24 changes: 23 additions & 1 deletion packages/block-library/src/details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { details as icon } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down Expand Up @@ -34,6 +34,28 @@ export const settings = {
},
],
},
__experimentalLabel( attributes, { context } ) {
const { summary } = attributes;

const customName = attributes?.metadata?.name;
const hasSummary = summary?.trim().length > 0;

// In the list view, use the block's summary as the label.
// If the summary is empty, fall back to the default label.
if ( context === 'list-view' && ( customName || hasSummary ) ) {
return customName || summary;
}

if ( context === 'accessibility' ) {
return ! hasSummary
? __( 'Details. Empty.' )
: sprintf(
/* translators: accessibility text; summary title. */
__( 'Details. %s' ),
summary
);
}
},
save,
edit,
transforms,
Expand Down
Loading