Skip to content

Commit

Permalink
Details block: use summary content as default label (#67217)
Browse files Browse the repository at this point in the history
Co-authored-by: dougwollison <[email protected]>
Co-authored-by: talldan <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent a7c373f commit 92254bf
Showing 1 changed file with 23 additions and 1 deletion.
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

0 comments on commit 92254bf

Please sign in to comment.