Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add justification to block toolbar in addition to sidebar #62924

Merged

Conversation

shreya0204
Copy link
Contributor

@shreya0204 shreya0204 commented Jun 27, 2024

What?

Added justification options to the block toolbar for "type constrained" blocks.

Fixes: #60838

Why?

The justification settings for other blocks, such as text blocks, are found in the toolbar. Many users overlook the settings when they are only in the sidebar, expecting them to be in the toolbar. Adding the justification options to the toolbar improves consistency and user experience.

How?

Added Justification toolBarControls of the constrained layout type blocks.

Testing Instructions

  • Add any "type constrained" block, such as Group or Content.
  • Check the toolbar to see if the justification option is available there.
  • Verify that the justification options are functional and behave as expected.

Testing Instructions for Keyboard

Screenshots or screencast

Screenshot 2024-06-27 at 5 54 32 PM Screenshot 2024-06-27 at 5 54 58 PM

Copy link

github-actions bot commented Jun 27, 2024

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @Nyiriland.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: Nyiriland.

Co-authored-by: shreya0204 <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: tellthemachines <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: jasmussen <[email protected]>

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

Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @shreya0204! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 27, 2024
@amitraj2203 amitraj2203 added [Type] Enhancement A suggestion for improvement. [Block] Group Affects the Group Block (and row, stack and grid variants) [Block] Post Content Affects the Post Content Block [Feature] Layout Layout block support, its UI controls, and style output. labels Jun 27, 2024
@jameskoster jameskoster requested a review from a team June 28, 2024 08:59
@jameskoster
Copy link
Contributor

I was looking for this option just yesterday, so I'm very happy to see this PR! In terms of design everything looks good to me, and the option seems to be working as advertised 👍

@jasmussen jasmussen requested review from a team and SantosGuillamot and removed request for a team July 1, 2024 09:09
Comment on lines 326 to 364

const justificationOptions = [
{
value: 'left',
icon: justifyLeft,
label: __( 'Justify items left' ),
},
{
value: 'center',
icon: justifyCenter,
label: __( 'Justify items center' ),
},
{
value: 'right',
icon: justifyRight,
label: __( 'Justify items right' ),
},
];

return (
<ToggleGroupControl
__nextHasNoMarginBottom
label={ __( 'Justification' ) }
value={ justifyContent }
onChange={ onJustificationChange }
className="block-editor-hooks__flex-layout-justification-controls"
>
{ justificationOptions.map( ( { value, icon, label } ) => {
return (
<ToggleGroupControlOptionIcon
key={ value }
value={ value }
icon={ icon }
label={ label }
/>
);
} ) }
</ToggleGroupControl>
);
Copy link
Member

Choose a reason for hiding this comment

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

I believe this is dead code as isToolbar will always be true. Can you simplify DefaultLayoutJustifyContentControl and remove the isToolbar prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing this out @noisysocks . I have removed the isToolbar props and simplified the component.

@jasmussen
Copy link
Contributor

Thanks for the 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.

Thanks for the PR!

I think we need to check that allowJustification is enabled in addition to allowSwitching.

For example, suppose we make the following change to the Group block to disable allowJustification:

diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json
index db7d09c55d..ef578cff97 100644
--- a/packages/block-library/src/group/block.json
+++ b/packages/block-library/src/group/block.json
@@ -86,7 +86,8 @@
                        }
                },
                "layout": {
-                       "allowSizingOnChildren": true
+                       "allowSizingOnChildren": true,
+                       "allowJustification": false
                },
                "interactivity": {
                        "clientNavigation": true

In this case, even though the justification control will not be displayed in the sidebar, the UI will unintentionally be displayed in the toolbar:

allow-justification

I think we probably need code like this:

const { allowSwitching, allowJustification = true } =
	layoutBlockSupport;
if ( allowSwitching || ! allowJustification ) {
	return null;
}

@shreya0204
Copy link
Contributor Author

Thank you for the feedback @t-hamano

I've updated the implementation to include checks for both allowSwitching and allowJustification as you suggested.

Please let me know if this adjustment aligns with the expected functionality, or if there are any other modifications or improvements you would recommend.

@t-hamano
Copy link
Contributor

t-hamano commented Jul 5, 2024

Thanks for the update!

I feel this PR is okay to ship because it improves UI consistency, but I am a bit skeptical about whether this UI is really necessary in the Group variations (constrained layout) in the first place. Maybe there is another approach to remove this UI from the block sidebar.

What do you think, @tellthemachines?

@tellthemachines
Copy link
Contributor

I am a bit skeptical about whether this UI is really necessary in the Group variations (constrained layout) in the first place.

Given that flex blocks also have the justification controls in both sidebar and block toolbar, I think it's fine to have them in both places here. If that did change, I'd expect it to change across all the layout types.

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.

LGTM 🚀

@t-hamano t-hamano merged commit 8784fe9 into WordPress:trunk Jul 9, 2024
61 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.8 milestone Jul 9, 2024
huubl pushed a commit to huubl/gutenberg that referenced this pull request Jul 10, 2024
…62924)

* refactor: add justification to block toolbar

* refactor: remove dead code

* refactor: add early return checks

* refactor: remove legacy attribute

Co-authored-by: shreya0204 <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: tellthemachines <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: jasmussen <[email protected]>
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
…62924)

* refactor: add justification to block toolbar

* refactor: remove dead code

* refactor: add early return checks

* refactor: remove legacy attribute

Co-authored-by: shreya0204 <[email protected]>
Co-authored-by: noisysocks <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: tellthemachines <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Group Affects the Group Block (and row, stack and grid variants) [Block] Post Content Affects the Post Content Block [Feature] Layout Layout block support, its UI controls, and style output. First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content Block: add justification to block toolbar in addition to sidebar
7 participants