diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 34db859f71d1d..29033e278c348 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -820,7 +820,7 @@ Create a break between ideas or sections with a horizontal separator. ([Source]( - **Name:** core/separator - **Category:** design - **Supports:** align (center, full, wide), anchor, color (background, gradients, ~~enableContrastChecker~~, ~~text~~), interactivity (clientNavigation), spacing (margin) -- **Attributes:** opacity +- **Attributes:** opacity, tagName ## Shortcode diff --git a/packages/block-library/src/separator/block.json b/packages/block-library/src/separator/block.json index 484627aaa1612..926d978b7e4d5 100644 --- a/packages/block-library/src/separator/block.json +++ b/packages/block-library/src/separator/block.json @@ -11,6 +11,11 @@ "opacity": { "type": "string", "default": "alpha-channel" + }, + "tagName": { + "type": "string", + "enum": [ "hr", "div" ], + "default": "hr" } }, "supports": { diff --git a/packages/block-library/src/separator/edit.js b/packages/block-library/src/separator/edit.js index 0d0af336713c1..c4b832c66158d 100644 --- a/packages/block-library/src/separator/edit.js +++ b/packages/block-library/src/separator/edit.js @@ -6,20 +6,28 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { HorizontalRule } from '@wordpress/components'; +import { HorizontalRule, SelectControl } from '@wordpress/components'; import { useBlockProps, getColorClassName, __experimentalUseColorProps as useColorProps, + InspectorControls, } from '@wordpress/block-editor'; +import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ import useDeprecatedOpacity from './use-deprecated-opacity'; +const htmlElementMessages = { + div: __( + 'The
element should only be used if the separator is a design element that should not be announced.' + ), +}; + export default function SeparatorEdit( { attributes, setAttributes } ) { - const { backgroundColor, opacity, style } = attributes; + const { backgroundColor, opacity, style, tagName } = attributes; const colorProps = useColorProps( attributes ); const currentColor = colorProps?.style?.backgroundColor; const hasCustomColor = !! style?.color?.background; @@ -44,10 +52,27 @@ export default function SeparatorEdit( { attributes, setAttributes } ) { color: currentColor, backgroundColor: currentColor, }; + const Wrapper = tagName === 'hr' ? HorizontalRule : tagName; return ( <> - + )' ), value: 'hr' }, + { label: '
', value: 'div' }, + ] } + value={ tagName } + onChange={ ( value ) => + setAttributes( { tagName: value } ) + } + help={ htmlElementMessages[ tagName ] } + /> + + ; + return ; }