-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Nav Block: adds basic items justification controls #18909
Conversation
Thank you for the clarification. Alignment controls don't seem to add a ton of value given how the horizontal width of the block can grow. But justification controls do make sense. You might create a 2 column layout with a logo in the left column, a nav block in the right column, and then wanting to justify the items inside the nav block to stack towards the right. In that vein, 👍 👍 on the feature. I wonder where in the toolbar the alignments should sit, they are almost never at the end. It should at least sit before colors, should it also sit before block navigator? I'd tend to think so. The overall pattern hasn't been fully established, but usually it goes like this
So starting with block level first and moving towards inline and "other". |
@jasmussen Thank you for the 👍 on the feature. I've updated the toolbar order. Good spot! |
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.
Haven't actually tested the code yet, but I noticed some minor things that could be improved.
I don't see the if we are not going to add two toolbars and just adds only one, could extend the current navigation adding these justify options? I've copied/pasted what you wrote straight in the navigation block. packages/block-editor/src/components/block-alignment-toolbar/index.js const BLOCK_ALIGNMENTS_CONTROLS = {
// ...,
justifyLeft: {
icon: 'editor-alignleft',
title: __( 'Justify items left' ),
},
justifyCenter: {
icon: 'editor-aligncenter',
title: __( 'Justify items center' ),
},
justifyRight: {
icon: 'editor-alignright',
title: __( 'Justify items right' ),
},
}; packages/block-library/src/navigation/index.js export const settings = {
// ...,
supports: {
align: [ 'justifyLeft', 'justifyCenter', 'justifyRight' ],
// ...,
},
// ...,
}; After that, it's a matter of defining the CSS on both sides. Sorry if this suggestion changes considerably this approach, but I think it worth because it's simpler since re-using blocks. |
Provided here #18909 (comment)
@retrofox Thanks for your comments. Allow me to address them.
The alignment toolbar is not in the
In this block yes there are two things that control placement on the hoz axis:
I think this might be a use case specific to Nav. I'm not sure.
No because of the reasons outlined in the PR description, namely:
My feeling at this stage is that I'm keen not to over abstract justification controls into a reusable toolbar too soon. I don't yet know of any other use cases where this functionality would be required. Moreover, this feature needs to be land in the Nav Block asap. Going off down a reusable route will introduce additional complexity. I'd be happy to handle that in a follow-up PR but my instinct is that it's premature to address it here. As always, I'm open to being told I'm wrong! 😄 |
@jasmussen @mtias We now have the new icons in place. |
Previously the nav inner elements didn’t occupy the full space of their container. As a result whilst the elements were justified it didn’t appear so because the containing element was only as wide as the width of the items.
@mtias This caught me out. Apologies. I was stress testing with a large nav with lots of items. This caused me to miss the issue. The issue was the nav inner containing elements didn’t occupy the full space of their container. As a result whilst the elements were justified it didn’t appear so because the containing element was only as wide as the width of the items. This is fixed. |
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 tested and it worked very well!
@draganescu Thanks for your review 👍 @ZebulanStanphill Please could you review your review as it's now blocking merge? Much appreciated. |
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.
Everything seems to be working as expected. 👍
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.
Nice work @getdave!
I saw the new "Justify" settings for the first time today and was completely confused. It feels like we're making a distinction between "justifying" and "aligning" for reasons that most people will never understand. I've never seen the word "justify" used like this before, and would not know what it meant. "Align" would be way more obvious to me. The use of new icons is also introducing more overhead. These icons don't help me understand that I can align my navigation items to the left or right. To me, they look more indent. |
@shaunandrews I think part of the issue is that there is already a block alignment toolbar, but it doesn't really contain any actual alignments except for |
Closes #18557.
Closes #18898.
Enables the ability to justify the items within the Nav Block to the:
flex-start
)flex-end
)This is not the same as alignment controls which actually shift the entire Block. This approach was avoided because:
left
orright
alignment was applied the whole Block became "full width".full-wide
and with the items aligned to the left/right.The approach in this PR works around that by adding a custom justification control which controls the alignment of individual items (taken as a whole) rather than the Block as a unit.
Questions
space-around
,space-between
...etc? I'm tempted to say we save that for a future PR and just get the basics merged.How has this been tested?
Before testing/reviewing please read the background discussion in the Issue to understand the motivation behind the justification approach.
This has been manually tested.
Deprecation Testing
This PR doesn't need to add a deprecation because we don't change the output of the Block until the user selects a justification option (ie: the default is don't change anything).
You can test this by
master
.#2
.Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: