Skip to content

Post Date: Migrate to textAlign block support#75856

Merged
t-hamano merged 4 commits intoWordPress:trunkfrom
huzaifaalmesbah:update/post-date-text-align-block-support
Mar 17, 2026
Merged

Post Date: Migrate to textAlign block support#75856
t-hamano merged 4 commits intoWordPress:trunkfrom
huzaifaalmesbah:update/post-date-text-align-block-support

Conversation

@huzaifaalmesbah
Copy link
Copy Markdown
Member

What?

Part of #60763

Migrates the Post Date block to use the textAlign block support instead of a custom textAlign attribute. As a consequence, it also enables global styles support for textAlign on the Post Date block.

Why?

The Post Date block currently implements its own text alignment logic with a custom textAlign attribute and a manual AlignmentControl in the toolbar, duplicating code that should be handled by the centralized textAlign block support.

This migration reduces code duplication and consolidates alignment handling across blocks.

How?

Replaces the custom logic with the block supports, adds deprecation and fixes transforms.

Testing Instructions

  1. Create a new Post Date block and test text alignment (left, center, right).
  2. Verify alignment works correctly in both the editor and the frontend.
  3. Open a post with existing Post Date blocks that have alignment set.
  4. Verify they migrate correctly (no console errors, no visual changes).
  5. Confirm the block is valid after migration by checking there are no block validation warnings in the console.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 24, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: huzaifaalmesbah <[email protected]>
Co-authored-by: t-hamano <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@im3dabasia im3dabasia added the [Type] Enhancement A suggestion for improvement. label Feb 24, 2026
@@ -129,13 +122,6 @@ export default function PostDateEdit( {
{ ( blockEditingMode === 'default' ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ ( blockEditingMode === 'default' || ! isDescendentOfQueryLoop ) &&
	activeBlockVariationName !== 'post-date-modified' &&
	( ! isDescendentOfQueryLoop || ! activeBlockVariationName ) && (
		<BlockControls group="block">
			<ToolbarGroup>
			</ToolbarGroup>
		</BlockControls>
	) }

All of the conditional checks here should be able to be consolidated.

Comment on lines +1 to +5
<!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"date"}}}}} /-->

<!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"date"}}}}} /-->

<!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"date"}}}}} /-->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be the expected result. The text alignment seems to be discarded.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The v2 deprecation migration was unintentionally overwriting v4's correctly migrated textAlign attribute back to the top level, because both were triggering sequentially on the original block attributes.

I fixed this by updating v2's isEligible check to explicitly exclude blocks that have textAlign, allowing v4 to handle them correctly. The fixtures have been regenerated with the proper output!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this by updating v2's isEligible check to explicitly exclude blocks that have textAlign

The v2 deprecation is a necessary step to migrate block attributes to Block Bindings. Adding exclusion rules will cause unintended problems. Please try the following:

  1. Open the code editor and insert the following HTML:
<!-- wp:post-date {"displayType":"modified"} /-->
<!-- wp:post-date {"displayType":"modified", "textAlign":"right"} /-->
  1. Back to the Visual editor, and back to the Code editor again.
  2. Unintended migration is occurring in a block that has textAlign.

<!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"modified"}}}},"className":"wp-block-post-date__modified-date"} /-->

<!-- wp:post-date {"datetime":"2026-03-16T10:14:11.214Z","style":{"typography":{"textAlign":"right"}}} /-->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution is probably to add migrate: migrateTextAlign to v1, v2, and v3 as well. See #74383 (comment)

@t-hamano t-hamano added the [Block] Post Date Affects the Post Date Block label Mar 10, 2026
Copy link
Copy Markdown
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@t-hamano t-hamano merged commit 922d9d8 into WordPress:trunk Mar 17, 2026
40 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.8 milestone Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Post Date Affects the Post Date Block [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants