Skip to content

Conversation

@yogeshbhutkar
Copy link
Contributor

@yogeshbhutkar yogeshbhutkar commented Jan 24, 2025

What, Why and How?

Fixes: #68864

This PR addresses a bug in which the default vertical alignment value does not render as selected in the Vertical Alignment Toolbar when the orientation is set to vertical. The issue arises because the layout.verticalAlignment property is expected to store the alignment key (e.g., top, center, bottom, stretch, etc.) but instead holds the resolved CSS value (e.g., flex-start).

Testing Instructions

  1. Create a Row Block.
  2. Verify from the Block Toolbar that the default alignment value is Align middle.
  3. Convert the same Block to a Column block.
  4. Confirm that the default alignment value for is now appropriately set to Top.

Screencast

Screen.Recording.2025-01-24.at.12.17.01.PM.mov

Screenshots

Before After
before after

@github-actions
Copy link

github-actions bot commented Jan 24, 2025

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: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

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

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Package] Block editor /packages/block-editor [Feature] Layout Layout block support, its UI controls, and style output. labels Jan 25, 2025
@yogeshbhutkar yogeshbhutkar force-pushed the fix-68864/incorrect-default-value branch from 7e9a4f1 to 9911076 Compare January 28, 2025 04:55
@yogeshbhutkar yogeshbhutkar force-pushed the fix-68864/incorrect-default-value branch 2 times, most recently from 38ce8a9 to 5e01c20 Compare May 26, 2025 05:09
@yogeshbhutkar
Copy link
Contributor Author

I noticed that this bug is still unresolved on trunk. Here's more context on the proposed changes to help this PR move forward.

Within flex.js, we're trying to pass the value of verticalAlignment to BlockVerticalAlignmentControl.

value={ verticalAlignment }

The value of verticalAlignment is determined here:

const defaultVerticalAlignment =
orientation === 'horizontal'
? verticalAlignmentMap.center
: verticalAlignmentMap.top;

When the orientation is vertical (i.e., Stack), verticalAlignmentMap.top becomes flex-start.

However, BlockVerticalAlignmentUI does not expect to receive flex-start, there's no corresponding value for flex-start, instead it expects the value top.

This can be seen in the UI as well, when a row block is transformed to stack, the default value is not shown as selected in the UI.

Actual Expected
bug expected

We cannot update verticalAlignmentMap.top as it's also being used elsewhere to add the corresponding justify-content rule, therefore, this PR creates a new constant for the default values.

Hi @t-hamano,
If you have some time, could you please review this PR?

Copy link
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.

@yogeshbhutkar Thanks for the PR!

To understand the problem exactly, let me confirm one thing.

This problem does not occur in horizontal layout, i.e. Row block, and "Align middle" is selected as the default value correctly. The reason for this is that the default vertical alignment in the horizontal layout is "center", and the key name and value in the verticalAlignmentMap object were the same, so fortunately, no problems occurred.

I my understanding correct?

@yogeshbhutkar yogeshbhutkar force-pushed the fix-68864/incorrect-default-value branch from 50a74f4 to 1eeed49 Compare May 30, 2025 04:06
@yogeshbhutkar
Copy link
Contributor Author

This problem does not occur in horizontal layout, i.e. Row block, and "Align middle" is selected as the default value correctly. The reason for this is that the default vertical alignment in the horizontal layout is "center", and the key name and value in the verticalAlignmentMap object were the same, so fortunately, no problems occurred.

I my understanding correct?

Yes, exactly.

Copy link
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.

The changes make sense to me 👍

@t-hamano t-hamano merged commit c6b0f2b into WordPress:trunk May 30, 2025
60 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.0 milestone May 30, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…gnment Control` component (WordPress#68866)

* Flex Layout: Fix incorrect default alignment values for `Vertical Alignment Control` component

* chore: fix casing of `defaultAlignments`

Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Layout Layout block support, its UI controls, and style output. [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flex Layout: Incorrect default alignment value used in Vertical Alignment Control Component

2 participants