Text expansion creates separator blocks differently than inserter, but reproducibility is uncertain.
The issue reports that separator blocks created via text expansion don't respect default variations, while those inserted normally do. However, maintainers couldn't reproduce, suggesting the problem might be environment-specific. The fix would need to ensure consistent variation handling across all block creation methods.
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.
div instead of hr--- and ENTER to make a Separator block.hr element, contrary to the default block variationnamespace 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;
}
No response
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!