Skip to content

Separator block made with text expansion doesn't use default block variation #75259

@mrwweb

Description

@mrwweb

Description

It is possible to register a default block variation to customize the settings of any block, including the Separator.

This works when inserting the separator in most ways, but not when creating a separator by typing --- + ENTER.

I would expect all new blocks to use the default block variation settings regardless of how they are created.

Step-by-step reproduction instructions

  1. Register a default block variation for the Separator (see code below)
  2. Insert Separator block using block inserter.
  3. Observe correct variation is used with div instead of hr
  4. Type --- and ENTER to make a Separator block.
  5. Observe that the Separator block is still using the hr element, contrary to the default block variation
namespace Gutenberg\Bug\Report;

add_filter( 'get_block_type_variations', __NAMESPACE__ . '\block_variations', 10, 2 );
/**
 * Register block variations in PHP for the block editor
 *
 * @param array $variations array of arrays for each block's variations
 * @param object $block block meta for each block, useful for checking $block->name to target a specific block
 * @return array $variations updated array containing variations to register
 */
function block_variations( $variations, $block ) {
	$block_name = $block->name;
	switch ( $block_name ) {
		// use non-semantic separator by default
		case 'core/separator':
			$variations[] = [
				'name' => 'separator',
				'isDefault' => true,
				'attributes' => [
					'tagName' => 'div',
				],
			];
			break;
	}

	return $variations;
}

Screenshots, screen recording, code snippet

No response

Environment info

  • WP 6.9.1
  • Custom Theme
  • No Gutenberg plugin

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Labels

[Block] SeparatorAffects the Separator Block[Feature] Block TransformsBlock transforms from one block to another[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions