diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php b/lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php index 1a0945b175422..77d731b9d4544 100644 --- a/lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php +++ b/lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php @@ -1,6 +1,6 @@ 'a', + 'h1' => 'h1', + 'h2' => 'h2', + 'h3' => 'h3', + 'h4' => 'h4', + 'h5' => 'h5', + 'h6' => 'h6', + 'button' => '.wp-element-button, .wp-block-button, button', // We have the .wp-block-button class so that this will target older buttons that have been serialized. + ); /** * Returns the metadata for each block. * diff --git a/packages/block-editor/src/elements/index.js b/packages/block-editor/src/elements/index.js new file mode 100644 index 0000000000000..b6847f0a8c2cb --- /dev/null +++ b/packages/block-editor/src/elements/index.js @@ -0,0 +1 @@ +export const __experimentalElementButtonClassName = 'wp-element-button'; diff --git a/packages/block-editor/src/index.js b/packages/block-editor/src/index.js index 078895c2c5a02..594c78859b25c 100644 --- a/packages/block-editor/src/index.js +++ b/packages/block-editor/src/index.js @@ -13,6 +13,7 @@ export { useCachedTruthy, } from './hooks'; export * from './components'; +export * from './elements'; export * from './utils'; export { storeConfig, store } from './store'; export { SETTINGS_DEFAULTS } from './store/defaults'; diff --git a/packages/block-library/src/button/deprecated.js b/packages/block-library/src/button/deprecated.js index 3e86f0a398161..78540d68c4570 100644 --- a/packages/block-library/src/button/deprecated.js +++ b/packages/block-library/src/button/deprecated.js @@ -119,6 +119,150 @@ const blockAttributes = { }, }; +const v11 = { + attributes: { + url: { + type: 'string', + source: 'attribute', + selector: 'a', + attribute: 'href', + }, + title: { + type: 'string', + source: 'attribute', + selector: 'a', + attribute: 'title', + }, + text: { + type: 'string', + source: 'html', + selector: 'a', + }, + linkTarget: { + type: 'string', + source: 'attribute', + selector: 'a', + attribute: 'target', + }, + rel: { + type: 'string', + source: 'attribute', + selector: 'a', + attribute: 'rel', + }, + placeholder: { + type: 'string', + }, + backgroundColor: { + type: 'string', + }, + textColor: { + type: 'string', + }, + gradient: { + type: 'string', + }, + width: { + type: 'number', + }, + }, + supports: { + anchor: true, + align: true, + alignWide: false, + color: { + __experimentalSkipSerialization: true, + gradients: true, + __experimentalDefaultControls: { + background: true, + text: true, + }, + }, + typography: { + fontSize: true, + __experimentalFontFamily: true, + __experimentalDefaultControls: { + fontSize: true, + }, + }, + reusable: false, + spacing: { + __experimentalSkipSerialization: true, + padding: [ 'horizontal', 'vertical' ], + __experimentalDefaultControls: { + padding: true, + }, + }, + __experimentalBorder: { + radius: true, + __experimentalSkipSerialization: true, + __experimentalDefaultControls: { + radius: true, + }, + }, + __experimentalSelector: '.wp-block-button__link', + }, + save( { attributes, className } ) { + const { + fontSize, + linkTarget, + rel, + style, + text, + title, + url, + width, + } = attributes; + + if ( ! text ) { + return null; + } + + const borderProps = getBorderClassesAndStyles( attributes ); + const colorProps = getColorClassesAndStyles( attributes ); + const spacingProps = getSpacingClassesAndStyles( attributes ); + const buttonClasses = classnames( + 'wp-block-button__link', + colorProps.className, + borderProps.className, + { + // For backwards compatibility add style that isn't provided via + // block support. + 'no-border-radius': style?.border?.radius === 0, + } + ); + const buttonStyle = { + ...borderProps.style, + ...colorProps.style, + ...spacingProps.style, + }; + + // The use of a `title` attribute here is soft-deprecated, but still applied + // if it had already been assigned, for the sake of backward-compatibility. + // A title will no longer be assigned for new or updated button block links. + + const wrapperClasses = classnames( className, { + [ `has-custom-width wp-block-button__width-${ width }` ]: width, + [ `has-custom-font-size` ]: fontSize || style?.typography?.fontSize, + } ); + + return ( +
+ +
+ ); + }, +}; + const v10 = { attributes: { url: { @@ -258,6 +402,7 @@ const v10 = { }; const deprecated = [ + v11, v10, { supports: { diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index 585fd1ec0101a..286897068f174 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -25,6 +25,7 @@ import { __experimentalUseColorProps as useColorProps, __experimentalGetSpacingClassesAndStyles as useSpacingProps, __experimentalLinkControl as LinkControl, + __experimentalElementButtonClassName, } from '@wordpress/block-editor'; import { displayShortcut, isKeyboardEvent } from '@wordpress/keycodes'; import { link, linkOff } from '@wordpress/icons'; @@ -176,7 +177,8 @@ function ButtonEdit( props ) { // For backwards compatibility add style that isn't // provided via block support. 'no-border-radius': style?.border?.radius === 0, - } + }, + __experimentalElementButtonClassName ) } style={ { ...borderProps.style, diff --git a/packages/block-library/src/button/save.js b/packages/block-library/src/button/save.js index 1910044f9529a..1dbe0108e3052 100644 --- a/packages/block-library/src/button/save.js +++ b/packages/block-library/src/button/save.js @@ -12,6 +12,7 @@ import { __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles, __experimentalGetColorClassesAndStyles as getColorClassesAndStyles, __experimentalGetSpacingClassesAndStyles as getSpacingClassesAndStyles, + __experimentalElementButtonClassName, } from '@wordpress/block-editor'; export default function save( { attributes, className } ) { @@ -41,7 +42,8 @@ export default function save( { attributes, className } ) { // For backwards compatibility add style that isn't provided via // block support. 'no-border-radius': style?.border?.radius === 0, - } + }, + __experimentalElementButtonClassName ); const buttonStyle = { ...borderProps.style, diff --git a/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap b/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap index 77c8ca306d822..3321bcdf6740c 100644 --- a/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap +++ b/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap @@ -21,7 +21,7 @@ exports[`Buttons block justify content sets Justify items right option 1`] = ` exports[`Buttons block when a button is shown adjusts the border radius 1`] = ` "
-
Hello
+
Hello
" `; diff --git a/packages/block-library/src/buttons/test/edit.native.js b/packages/block-library/src/buttons/test/edit.native.js index 10ab8c5df51b7..140169ead77ef 100644 --- a/packages/block-library/src/buttons/test/edit.native.js +++ b/packages/block-library/src/buttons/test/edit.native.js @@ -32,7 +32,7 @@ describe( 'Buttons block', () => { it( 'adjusts the border radius', async () => { const initialHtml = `
-
Hello
+
Hello
`; const { getByA11yLabel } = await initializeEditor( { diff --git a/packages/block-library/src/search/edit.js b/packages/block-library/src/search/edit.js index ad64b556556a6..90c7fbeb9501d 100644 --- a/packages/block-library/src/search/edit.js +++ b/packages/block-library/src/search/edit.js @@ -14,6 +14,7 @@ import { __experimentalUseBorderProps as useBorderProps, __experimentalUseColorProps as useColorProps, store as blockEditorStore, + __experimentalElementButtonClassName, } from '@wordpress/block-editor'; import { useDispatch, useSelect } from '@wordpress/data'; import { useEffect } from '@wordpress/element'; @@ -241,7 +242,8 @@ export default function SearchEdit( { 'wp-block-search__button', colorProps.className, isButtonPositionInside ? undefined : borderProps.className, - buttonUseIcon ? 'has-icon' : undefined + buttonUseIcon ? 'has-icon' : undefined, + __experimentalElementButtonClassName ); const buttonStyles = { ...colorProps.style, diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index d0f3a54feca35..49163b80a283b 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -101,6 +101,9 @@ function render_block_core_search( $attributes ) { '; } + // Include the button element class. + $button_classes .= ' ' . WP_Theme_JSON_GUTENBERG::__EXPERIMENTAL_ELEMENT_BUTTON_CLASS_NAME; + $button_markup = sprintf( '', esc_attr( $button_classes ), diff --git a/packages/e2e-tests/specs/editor/blocks/__snapshots__/buttons.test.js.snap b/packages/e2e-tests/specs/editor/blocks/__snapshots__/buttons.test.js.snap index 20444c7b7e276..58feb9236d7dd 100644 --- a/packages/e2e-tests/specs/editor/blocks/__snapshots__/buttons.test.js.snap +++ b/packages/e2e-tests/specs/editor/blocks/__snapshots__/buttons.test.js.snap @@ -3,7 +3,7 @@ exports[`Buttons can jump to the link editor using the keyboard shortcut 1`] = ` "
-
WordPress
+
WordPress
" `; @@ -11,7 +11,7 @@ exports[`Buttons can jump to the link editor using the keyboard shortcut 1`] = ` exports[`Buttons dismisses link editor when escape is pressed 1`] = ` "
-
WordPress
+
WordPress
" `; @@ -19,7 +19,7 @@ exports[`Buttons dismisses link editor when escape is pressed 1`] = ` exports[`Buttons has focus on button content (slash inserter) 1`] = ` "
-
Content
+
Content
" `; @@ -27,7 +27,7 @@ exports[`Buttons has focus on button content (slash inserter) 1`] = ` exports[`Buttons has focus on button content 1`] = ` "
-
Content
+
Content
" `; diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap index d07caf7b01771..aa75e5d5ef89c 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/inserting-blocks.test.js.snap @@ -108,7 +108,7 @@ exports[`Inserting blocks inserts a block in proper place after having clicked \ exports[`Inserting blocks inserts blocks at root level when using the root appender while selection is in an inner block 1`] = ` "
-
1.1
+
1.1
diff --git a/test/integration/fixtures/blocks/core__button__border_radius__deprecated-2.serialized.html b/test/integration/fixtures/blocks/core__button__border_radius__deprecated-2.serialized.html index 89314d5688c9e..d348549371516 100644 --- a/test/integration/fixtures/blocks/core__button__border_radius__deprecated-2.serialized.html +++ b/test/integration/fixtures/blocks/core__button__border_radius__deprecated-2.serialized.html @@ -1,3 +1,3 @@ -
Where We Are
+
Where We Are
diff --git a/test/integration/fixtures/blocks/core__button__border_radius__deprecated.serialized.html b/test/integration/fixtures/blocks/core__button__border_radius__deprecated.serialized.html index 2f0b0fe6f6e77..48f9a29133730 100644 --- a/test/integration/fixtures/blocks/core__button__border_radius__deprecated.serialized.html +++ b/test/integration/fixtures/blocks/core__button__border_radius__deprecated.serialized.html @@ -1,5 +1,5 @@ -
My button
+
My button
diff --git a/test/integration/fixtures/blocks/core__button__center__deprecated.serialized.html b/test/integration/fixtures/blocks/core__button__center__deprecated.serialized.html index 3d88c7ec1a551..a923cbd5100dc 100644 --- a/test/integration/fixtures/blocks/core__button__center__deprecated.serialized.html +++ b/test/integration/fixtures/blocks/core__button__center__deprecated.serialized.html @@ -1,3 +1,3 @@ -
Help build Gutenberg
+
Help build Gutenberg
diff --git a/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html b/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html index cabc3d37ae9c9..e4c7b89c79461 100644 --- a/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html +++ b/test/integration/fixtures/blocks/core__button__deprecated-v10.serialized.html @@ -1,3 +1,3 @@ -
My button
+
My button
diff --git a/test/integration/fixtures/blocks/core__button__squared.html b/test/integration/fixtures/blocks/core__button__squared.html index fa615a348d0ff..3cec174707c99 100644 --- a/test/integration/fixtures/blocks/core__button__squared.html +++ b/test/integration/fixtures/blocks/core__button__squared.html @@ -1,3 +1,3 @@ -
My button
+
My button
diff --git a/test/integration/fixtures/blocks/core__button__squared.parsed.json b/test/integration/fixtures/blocks/core__button__squared.parsed.json index 34bbf214ae6c6..df1176ec8601a 100644 --- a/test/integration/fixtures/blocks/core__button__squared.parsed.json +++ b/test/integration/fixtures/blocks/core__button__squared.parsed.json @@ -13,9 +13,9 @@ } }, "innerBlocks": [], - "innerHTML": "\n
My button
\n", + "innerHTML": "\n
My button
\n", "innerContent": [ - "\n
My button
\n" + "\n
My button
\n" ] } ] diff --git a/test/integration/fixtures/blocks/core__button__squared.serialized.html b/test/integration/fixtures/blocks/core__button__squared.serialized.html index ec83bb66b4971..22c7e08c8f5b3 100644 --- a/test/integration/fixtures/blocks/core__button__squared.serialized.html +++ b/test/integration/fixtures/blocks/core__button__squared.serialized.html @@ -1,3 +1,3 @@ -
My button
+
My button
diff --git a/test/integration/fixtures/blocks/core__buttons.html b/test/integration/fixtures/blocks/core__buttons.html index 5b114e3c7b6f7..282f38c7ddb11 100644 --- a/test/integration/fixtures/blocks/core__buttons.html +++ b/test/integration/fixtures/blocks/core__buttons.html @@ -1,11 +1,11 @@
-
My button 1
+
My button 1
-
My button 2
+
My button 2
- \ No newline at end of file + diff --git a/test/integration/fixtures/blocks/core__buttons.parsed.json b/test/integration/fixtures/blocks/core__buttons.parsed.json index 03df2f840a4d2..d15ccdcd2012d 100644 --- a/test/integration/fixtures/blocks/core__buttons.parsed.json +++ b/test/integration/fixtures/blocks/core__buttons.parsed.json @@ -13,18 +13,18 @@ "blockName": "core/button", "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\t
My button 1
\n\t", + "innerHTML": "\n\t
My button 1
\n\t", "innerContent": [ - "\n\t
My button 1
\n\t" + "\n\t
My button 1
\n\t" ] }, { "blockName": "core/button", "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\t
My button 2
\n\t", + "innerHTML": "\n\t
My button 2
\n\t", "innerContent": [ - "\n\t
My button 2
\n\t" + "\n\t
My button 2
\n\t" ] } ], diff --git a/test/integration/fixtures/blocks/core__buttons.serialized.html b/test/integration/fixtures/blocks/core__buttons.serialized.html index 31157113d05d4..7da8f97de51eb 100644 --- a/test/integration/fixtures/blocks/core__buttons.serialized.html +++ b/test/integration/fixtures/blocks/core__buttons.serialized.html @@ -1,9 +1,9 @@
-
My button 1
+
My button 1
-
My button 2
+
My button 2
diff --git a/test/integration/fixtures/blocks/core__buttons__deprecated-1.serialized.html b/test/integration/fixtures/blocks/core__buttons__deprecated-1.serialized.html index 136441794fe35..d95591d647b85 100644 --- a/test/integration/fixtures/blocks/core__buttons__deprecated-1.serialized.html +++ b/test/integration/fixtures/blocks/core__buttons__deprecated-1.serialized.html @@ -1,9 +1,9 @@
-
My button 1
+
My button 1
-
My button 2
+
My button 2
diff --git a/test/integration/fixtures/blocks/core__buttons__deprecated-2.serialized.html b/test/integration/fixtures/blocks/core__buttons__deprecated-2.serialized.html index dc4ecfa51732f..f97496d7eaf02 100644 --- a/test/integration/fixtures/blocks/core__buttons__deprecated-2.serialized.html +++ b/test/integration/fixtures/blocks/core__buttons__deprecated-2.serialized.html @@ -1,9 +1,9 @@
-
My button 1
+
My button 1
-
My button 2
+
My button 2
diff --git a/test/integration/fixtures/blocks/core__post-terms.json b/test/integration/fixtures/blocks/core__post-terms.json index f3b9bd3b4828f..6cddf3d6043d9 100644 --- a/test/integration/fixtures/blocks/core__post-terms.json +++ b/test/integration/fixtures/blocks/core__post-terms.json @@ -3,8 +3,8 @@ "name": "core/post-terms", "isValid": true, "attributes": { - "prefix": "", "separator": ", ", + "prefix": "", "suffix": "" }, "innerBlocks": [] diff --git a/test/integration/fixtures/blocks/core_buttons__simple__deprecated.serialized.html b/test/integration/fixtures/blocks/core_buttons__simple__deprecated.serialized.html index baf0a0226c066..4091c0d533e54 100644 --- a/test/integration/fixtures/blocks/core_buttons__simple__deprecated.serialized.html +++ b/test/integration/fixtures/blocks/core_buttons__simple__deprecated.serialized.html @@ -1,9 +1,9 @@
-
My button 1
+
My button 1
-
My button 2
+
My button 2