-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add justification to block toolbar in addition to sidebar #62924
Conversation
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 Unlinked AccountsThe 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.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
👋 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. |
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 👍 |
|
||
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> | ||
); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Thanks for the PR! |
There was a problem hiding this 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:
I think we probably need code like this:
const { allowSwitching, allowJustification = true } =
layoutBlockSupport;
if ( allowSwitching || ! allowJustification ) {
return null;
}
Thank you for the feedback @t-hamano I've updated the implementation to include checks for both Please let me know if this adjustment aligns with the expected functionality, or if there are any other modifications or improvements you would recommend. |
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? |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
…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]>
…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]>
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
Testing Instructions for Keyboard
Screenshots or screencast