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
- Register a default block variation for the Separator (see code below)
- Insert Separator block using block inserter.
- Observe correct variation is used with
div instead of hr
- Type
--- and ENTER to make a Separator block.
- 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.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
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
divinstead ofhr---andENTERto make a Separator block.hrelement, contrary to the default block variationScreenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.