From 52dec40e3c8d989ee82e2ddb2139e7b8597733db Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Tue, 17 Feb 2026 22:26:06 +0530 Subject: [PATCH 1/5] Post Title : Migrate to Text-Align Block Support --- docs/reference-guides/core-blocks.md | 4 +- .../block-library/src/post-title/block.json | 4 +- .../src/post-title/deprecated.js | 87 ++++++++++++++++++- packages/block-library/src/post-title/edit.js | 20 +---- .../core__post-title__deprecated-v2.html | 5 ++ .../core__post-title__deprecated-v2.json | 50 +++++++++++ ...ore__post-title__deprecated-v2.parsed.json | 46 ++++++++++ ..._post-title__deprecated-v2.serialized.html | 5 ++ 8 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 test/integration/fixtures/blocks/core__post-title__deprecated-v2.html create mode 100644 test/integration/fixtures/blocks/core__post-title__deprecated-v2.json create mode 100644 test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json create mode 100644 test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index 0e9057fedd9601..d1c5ad01fb538c 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -779,8 +779,8 @@ Displays the title of a post, page, or any other content-type. ([Source](https:/ - **Name:** core/post-title - **Category:** theme -- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~ -- **Attributes:** isLink, level, levelOptions, linkTarget, rel, textAlign +- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), interactivity (clientNavigation), spacing (margin, padding), typography (fontSize, lineHeight, textAlign), ~~html~~ +- **Attributes:** isLink, level, levelOptions, linkTarget, rel ## Preformatted diff --git a/packages/block-library/src/post-title/block.json b/packages/block-library/src/post-title/block.json index 1fb7efcf82db55..1be4f981257147 100644 --- a/packages/block-library/src/post-title/block.json +++ b/packages/block-library/src/post-title/block.json @@ -8,9 +8,6 @@ "textdomain": "default", "usesContext": [ "postId", "postType", "queryId" ], "attributes": { - "textAlign": { - "type": "string" - }, "level": { "type": "number", "default": 2 @@ -58,6 +55,7 @@ "typography": { "fontSize": true, "lineHeight": true, + "textAlign": true, "__experimentalFontFamily": true, "__experimentalFontWeight": true, "__experimentalFontStyle": true, diff --git a/packages/block-library/src/post-title/deprecated.js b/packages/block-library/src/post-title/deprecated.js index e53606027c7bbf..97c165b33e948a 100644 --- a/packages/block-library/src/post-title/deprecated.js +++ b/packages/block-library/src/post-title/deprecated.js @@ -2,6 +2,91 @@ * Internal dependencies */ import migrateFontFamily from '../utils/migrate-font-family'; +import migrateTextAlign from '../utils/migrate-text-align'; + +const v2 = { + attributes: { + textAlign: { + type: 'string', + }, + level: { + type: 'number', + default: 2, + }, + levelOptions: { + type: 'array', + }, + isLink: { + type: 'boolean', + default: false, + }, + rel: { + type: 'string', + attribute: 'rel', + default: '', + }, + linkTarget: { + type: 'string', + default: '_self', + }, + }, + supports: { + anchor: true, + align: [ 'wide', 'full' ], + html: false, + color: { + gradients: true, + link: true, + __experimentalDefaultControls: { + background: true, + text: true, + link: true, + }, + }, + spacing: { + padding: true, + margin: true, + }, + typography: { + fontSize: true, + lineHeight: true, + __experimentalFontFamily: true, + __experimentalTextTransform: true, + __experimentalTextDecoration: true, + __experimentalFontStyle: true, + __experimentalFontWeight: true, + __experimentalLetterSpacing: true, + __experimentalDefaultControls: { + fontSize: true, + }, + }, + interactivity: { + clientNavigation: true, + }, + __experimentalBorder: { + radius: true, + color: true, + width: true, + style: true, + __experimentalDefaultControls: { + radius: true, + color: true, + width: true, + style: true, + }, + }, + }, + migrate: migrateTextAlign, + isEligible( attributes ) { + return ( + !! attributes.textAlign || + !! attributes.className?.match( + /\bhas-text-align-(left|center|right)\b/ + ) + ); + }, + save: () => null, +}; const v1 = { attributes: { @@ -62,4 +147,4 @@ const v1 = { * * See block-deprecation.md */ -export default [ v1 ]; +export default [ v2, v1 ]; diff --git a/packages/block-library/src/post-title/edit.js b/packages/block-library/src/post-title/edit.js index 53fd38423f6673..80dc8b5e2ed28c 100644 --- a/packages/block-library/src/post-title/edit.js +++ b/packages/block-library/src/post-title/edit.js @@ -1,13 +1,7 @@ -/** - * External dependencies - */ -import clsx from 'clsx'; - /** * WordPress dependencies */ import { - AlignmentControl, BlockControls, InspectorControls, useBlockProps, @@ -34,7 +28,7 @@ import { createInterpolateElement } from '@wordpress/element'; import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; export default function PostTitleEdit( { - attributes: { level, levelOptions, textAlign, isLink, rel, linkTarget }, + attributes: { level, levelOptions, isLink, rel, linkTarget }, setAttributes, context: { postType, postId, queryId }, insertBlocksAfter, @@ -72,11 +66,7 @@ export default function PostTitleEdit( { const onSplitAtEnd = () => { insertBlocksAfter( createBlock( getDefaultBlockName() ) ); }; - const blockProps = useBlockProps( { - className: clsx( { - [ `has-text-align-${ textAlign }` ]: textAlign, - } ), - } ); + const blockProps = useBlockProps(); const blockEditingMode = useBlockEditingMode(); const dropdownMenuProps = useToolsPanelDropdownMenuProps(); @@ -147,12 +137,6 @@ export default function PostTitleEdit( { setAttributes( { level: newLevel } ) } /> - { - setAttributes( { textAlign: nextAlign } ); - } } - /> + + + + diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json new file mode 100644 index 00000000000000..dc9c587f91fbbb --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json @@ -0,0 +1,50 @@ +[ + { + "name": "core/post-title", + "isValid": true, + "attributes": { + "level": 1, + "isLink": false, + "rel": "", + "linkTarget": "_self", + "style": { + "typography": { + "textAlign": "left" + } + } + }, + "innerBlocks": [] + }, + { + "name": "core/post-title", + "isValid": true, + "attributes": { + "level": 1, + "isLink": false, + "rel": "", + "linkTarget": "_self", + "style": { + "typography": { + "textAlign": "center" + } + } + }, + "innerBlocks": [] + }, + { + "name": "core/post-title", + "isValid": true, + "attributes": { + "level": 1, + "isLink": false, + "rel": "", + "linkTarget": "_self", + "style": { + "typography": { + "textAlign": "right" + } + } + }, + "innerBlocks": [] + } +] diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json new file mode 100644 index 00000000000000..66c7a91bdbe740 --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json @@ -0,0 +1,46 @@ +[ + { + "blockName": "core/post-title", + "attrs": { + "textAlign": "left", + "level": 1 + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] + }, + { + "blockName": "core/post-title", + "attrs": { + "textAlign": "center", + "level": 1 + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] + }, + { + "blockName": "core/post-title", + "attrs": { + "textAlign": "right", + "level": 1 + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + } +] diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html new file mode 100644 index 00000000000000..d7ff0a0b8646e7 --- /dev/null +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html @@ -0,0 +1,5 @@ + + + + + From ffff760c367517a52f873c77248a439e0f9fb9a6 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Thu, 19 Feb 2026 21:11:28 +0530 Subject: [PATCH 2/5] Removed unurelevant attributes in test --- .../fixtures/blocks/core__post-title__deprecated-v2.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html index ffa8aea735e1d9..2532db96d2d33f 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html @@ -1,5 +1,5 @@ - + - + - + From 70fe761f074edffec6528778d8a87f3e261ee968 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Thu, 19 Feb 2026 21:42:54 +0530 Subject: [PATCH 3/5] Removed unurelevant attributes in test --- .../fixtures/blocks/core__post-title__deprecated-v2.json | 3 --- .../blocks/core__post-title__deprecated-v2.parsed.json | 9 +++------ .../core__post-title__deprecated-v2.serialized.html | 6 +++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json index dc9c587f91fbbb..67f96f14def24e 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json @@ -3,7 +3,6 @@ "name": "core/post-title", "isValid": true, "attributes": { - "level": 1, "isLink": false, "rel": "", "linkTarget": "_self", @@ -19,7 +18,6 @@ "name": "core/post-title", "isValid": true, "attributes": { - "level": 1, "isLink": false, "rel": "", "linkTarget": "_self", @@ -35,7 +33,6 @@ "name": "core/post-title", "isValid": true, "attributes": { - "level": 1, "isLink": false, "rel": "", "linkTarget": "_self", diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json index 66c7a91bdbe740..4e3529f01225ee 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json @@ -2,8 +2,7 @@ { "blockName": "core/post-title", "attrs": { - "textAlign": "left", - "level": 1 + "textAlign": "left" }, "innerBlocks": [], "innerHTML": "", @@ -19,8 +18,7 @@ { "blockName": "core/post-title", "attrs": { - "textAlign": "center", - "level": 1 + "textAlign": "center" }, "innerBlocks": [], "innerHTML": "", @@ -36,8 +34,7 @@ { "blockName": "core/post-title", "attrs": { - "textAlign": "right", - "level": 1 + "textAlign": "right" }, "innerBlocks": [], "innerHTML": "", diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html index d7ff0a0b8646e7..7b9736cbd6d8db 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.serialized.html @@ -1,5 +1,5 @@ - + - + - + From 2ed6854e6f2b24eb3fa6b8994f59db5b59bbc11e Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sun, 22 Feb 2026 09:58:43 +0530 Subject: [PATCH 4/5] Updated test data --- .../fixtures/blocks/core__post-title__deprecated-v2.html | 2 +- .../fixtures/blocks/core__post-title__deprecated-v2.json | 3 +++ .../blocks/core__post-title__deprecated-v2.parsed.json | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html index 2532db96d2d33f..6c8babc4c0ee96 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.html @@ -2,4 +2,4 @@ - + \ No newline at end of file diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json index 67f96f14def24e..eb20e62245d6cf 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.json @@ -3,6 +3,7 @@ "name": "core/post-title", "isValid": true, "attributes": { + "level": 2, "isLink": false, "rel": "", "linkTarget": "_self", @@ -18,6 +19,7 @@ "name": "core/post-title", "isValid": true, "attributes": { + "level": 2, "isLink": false, "rel": "", "linkTarget": "_self", @@ -33,6 +35,7 @@ "name": "core/post-title", "isValid": true, "attributes": { + "level": 2, "isLink": false, "rel": "", "linkTarget": "_self", diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json index 4e3529f01225ee..44321af92dede1 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json @@ -12,8 +12,8 @@ "blockName": null, "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\n", - "innerContent": [ "\n\n" ] + "innerHTML": "\r\n\r\n", + "innerContent": [ "\r\n\r\n" ] }, { "blockName": "core/post-title", @@ -28,8 +28,8 @@ "blockName": null, "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\n", - "innerContent": [ "\n\n" ] + "innerHTML": "\r\n\r\n", + "innerContent": [ "\r\n\r\n" ] }, { "blockName": "core/post-title", From 92b6ecc449474fdf80d077edbae6a19992c1db66 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Sun, 22 Feb 2026 10:07:07 +0530 Subject: [PATCH 5/5] Updated test data --- .../blocks/core__post-title__deprecated-v2.parsed.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json index 44321af92dede1..4e3529f01225ee 100644 --- a/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json +++ b/test/integration/fixtures/blocks/core__post-title__deprecated-v2.parsed.json @@ -12,8 +12,8 @@ "blockName": null, "attrs": {}, "innerBlocks": [], - "innerHTML": "\r\n\r\n", - "innerContent": [ "\r\n\r\n" ] + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] }, { "blockName": "core/post-title", @@ -28,8 +28,8 @@ "blockName": null, "attrs": {}, "innerBlocks": [], - "innerHTML": "\r\n\r\n", - "innerContent": [ "\r\n\r\n" ] + "innerHTML": "\n\n", + "innerContent": [ "\n\n" ] }, { "blockName": "core/post-title",