Skip to content

Commit

Permalink
Group block: Automatically select variation if there is only one (Wor…
Browse files Browse the repository at this point in the history
…dPress#61871)

When a `core/group` block has only one variation available, skip the placeholder step and select the variation.

Co-authored-by: costasovo <[email protected]>
Co-authored-by: ockham <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2024
1 parent 49b9692 commit 1998f1f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/block-library/src/group/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ function GroupPlaceHolder( { name, onSelect } ) {
const blockProps = useBlockProps( {
className: 'wp-block-group__placeholder',
} );

useEffect( () => {
if ( variations && variations.length === 1 ) {
onSelect( variations[ 0 ] );
}
}, [ onSelect, variations ] );

return (
<div { ...blockProps }>
<Placeholder
Expand Down

0 comments on commit 1998f1f

Please sign in to comment.