WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.52k stars 4.21k forks source link

Cannot align inner blocks in flex layout when allowSwitching is set to true #67016

Open metropoliscreative opened 2 days ago

metropoliscreative commented 2 days ago

Description

When a block has layout support and the allowSwitching subproperty is set to true, the vertical alignment setting should be displayed in the block toolbar when the layout is set to flex. The alignment setting is not shown unless allowSwitching is set to false (the default) and flex is the default layout type.

Step-by-step reproduction instructions

Create a block with layout support and allowSwitching set to true

Screenshots, screen recording, code snippet

This is the code that prevents the alignment button from being added to the block toolbar when allowSwitching is set to true: https://github.com/WordPress/gutenberg/blob/e7f0dc53ab3d8bbd53bd19129e00ed34aad67326/packages/block-editor/src/layouts/flex.js#L97-L99

Environment info

WordPress 6.7, Gutenberg plugin not active

Please confirm that you have searched existing issues in the repo.

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Please confirm which theme type you used for testing.

Mayank-Tripathi32 commented 2 days ago

@metropoliscreative Could you share a recorded video of the issue? Also, could you clarify the intended behavior here and the reasoning behind it?

Thanks

metropoliscreative commented 2 days ago

First video shows a sample block with layout support and the default layout type set to flex. The block toolbar contains both justification and alignment controls.

block.json supports:

"supports": {
    "layout": {
        "allowSwitching": false,
        "default": {
            "type": "flex"
        }
    }
}

https://github.com/user-attachments/assets/ce98f8cf-7727-4974-af0e-565c79f80c30

The next video shows the same block with allowSwitching enabled. When the Flex layout is selected for the block there is a justification control but no alignment control.

block.json supports:

"supports": {
    "layout": {
        "allowSwitching": true
    }
}

https://github.com/user-attachments/assets/fb8a872f-9c43-47a1-b10d-24963a03ad7b

could you clarify the intended behavior here and the reasoning behind it?

I would expect the block to receive alignment control along with justification control when the layout type is set to flex, even if switching the layout type is enabled for the block.

Infinite-Null commented 2 days ago

Hi @metropoliscreative,

Thank you for bringing this up. I’ve looked into it and was able to reproduce the issue as follows:

For the configuration:

"supports": {
    "layout": {
        "allowSwitching": true
    }
},

Here is the resulting behavior (No settings in block toolbar):

Image

For the configuration:

"supports": {
    "layout": {
        "allowSwitching": false,
        "default": {
            "type": "flex"
        }
    }
}

Here is the resulting behavior:

Image

To improve accessibility and provide a better user experience, I believe adding settings for this functionality within the block toolbar would be a great enhancement.