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

Try using flex layout on the Navigation block #36169

Merged
merged 6 commits into from
Nov 5, 2021

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Nov 3, 2021

Description

Closes #34872

This is quite a large changeset, mainly because of getting layout to work with the responsive wrapper. In order for all the navigation inner blocks to inherit the flex layout from the block wrapper, I had to set all the intermediate elements to display: contents, and in order for that to work with the responsive menu overlay, I had to move most of the overlay styles to the block wrapper.

One thing I haven't quite solved is how to force all the inner blocks to display as a column inside the overlay menu, because display: contents means the inner blocks just inherit whatever is set by the layout controls.

The other thing I haven't solved is how to get a nested Spacer block to inherit the orientation from the Navigation block, given that orientation is no longer a block attribute.

There may be a few other rough edges here and there 😄

This is a bit of an experiment to see if we can/want to do this, so any and all feedback and ideas welcome!

How has this been tested?

Add a Navigation block; change its justification and orientation properties and check that all works as expected.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions
Copy link

github-actions bot commented Nov 3, 2021

Size Change: -992 B (0%)

Total Size: 1.08 MB

Filename Size Change
build/block-editor/index.min.js 136 kB +16 B (0%)
build/block-library/blocks/navigation/style-rtl.css 1.5 kB -213 B (-12%) 👏
build/block-library/blocks/navigation/style.css 1.49 kB -210 B (-12%) 👏
build/block-library/blocks/page-list/style-rtl.css 117 B -81 B (-41%) 🎉
build/block-library/blocks/page-list/style.css 117 B -81 B (-41%) 🎉
build/block-library/index.min.js 159 kB +15 B (0%)
build/block-library/style-rtl.css 10.3 kB -217 B (-2%)
build/block-library/style.css 10.3 kB -221 B (-2%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 931 B
build/admin-manifest/index.min.js 1.09 kB
build/annotations/index.min.js 2.7 kB
build/api-fetch/index.min.js 2.17 kB
build/autop/index.min.js 2.08 kB
build/blob/index.min.js 459 B
build/block-directory/index.min.js 6.2 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/style-rtl.css 14.1 kB
build/block-editor/style.css 14.1 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 58 B
build/block-library/blocks/audio/editor.css 58 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 470 B
build/block-library/blocks/button/editor.css 470 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 90 B
build/block-library/blocks/code/style.css 90 B
build/block-library/blocks/code/theme-rtl.css 131 B
build/block-library/blocks/code/theme.css 131 B
build/block-library/blocks/columns/editor-rtl.css 206 B
build/block-library/blocks/columns/editor.css 205 B
build/block-library/blocks/columns/style-rtl.css 503 B
build/block-library/blocks/columns/style.css 502 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.17 kB
build/block-library/blocks/cover/style.css 1.17 kB
build/block-library/blocks/embed/editor-rtl.css 488 B
build/block-library/blocks/embed/editor.css 488 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 322 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 977 B
build/block-library/blocks/gallery/editor.css 982 B
build/block-library/blocks/gallery/style-rtl.css 1.6 kB
build/block-library/blocks/gallery/style.css 1.59 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/home-link/style-rtl.css 247 B
build/block-library/blocks/home-link/style.css 247 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 502 B
build/block-library/blocks/image/style.css 505 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B
build/block-library/blocks/latest-posts/editor.css 137 B
build/block-library/blocks/latest-posts/style-rtl.css 528 B
build/block-library/blocks/latest-posts/style.css 527 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 642 B
build/block-library/blocks/navigation-link/editor.css 642 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/style-rtl.css 195 B
build/block-library/blocks/navigation-submenu/style.css 195 B
build/block-library/blocks/navigation-submenu/view.min.js 343 B
build/block-library/blocks/navigation/editor-rtl.css 1.93 kB
build/block-library/blocks/navigation/editor.css 1.93 kB
build/block-library/blocks/navigation/view.min.js 2.74 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 377 B
build/block-library/blocks/page-list/editor.css 377 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 347 B
build/block-library/blocks/post-comments-form/style.css 347 B
build/block-library/blocks/post-comments/style-rtl.css 492 B
build/block-library/blocks/post-comments/style.css 493 B
build/block-library/blocks/post-content/style-rtl.css 56 B
build/block-library/blocks/post-content/style.css 56 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 396 B
build/block-library/blocks/post-featured-image/editor.css 397 B
build/block-library/blocks/post-featured-image/style-rtl.css 156 B
build/block-library/blocks/post-featured-image/style.css 156 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 391 B
build/block-library/blocks/post-template/style.css 392 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 60 B
build/block-library/blocks/post-title/style.css 60 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 378 B
build/block-library/blocks/pullquote/style.css 378 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 262 B
build/block-library/blocks/query-pagination/editor.css 255 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 187 B
build/block-library/blocks/quote/style.css 187 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 245 B
build/block-library/blocks/separator/style.css 245 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 770 B
build/block-library/blocks/site-logo/editor.css 770 B
build/block-library/blocks/site-logo/style-rtl.css 165 B
build/block-library/blocks/site-logo/style.css 165 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 824 B
build/block-library/blocks/social-links/editor.css 823 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB
build/block-library/blocks/social-links/style.css 1.32 kB
build/block-library/blocks/spacer/editor-rtl.css 307 B
build/block-library/blocks/spacer/editor.css 307 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 146 B
build/block-library/blocks/tag-cloud/style.css 146 B
build/block-library/blocks/template-part/editor-rtl.css 560 B
build/block-library/blocks/template-part/editor.css 559 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 815 B
build/block-library/common.css 812 B
build/block-library/editor-rtl.css 9.88 kB
build/block-library/editor.css 9.88 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/theme-rtl.css 668 B
build/block-library/theme.css 673 B
build/block-serialization-default-parser/index.min.js 1.09 kB
build/block-serialization-spec-parser/index.min.js 2.79 kB
build/blocks/index.min.js 46 kB
build/components/index.min.js 213 kB
build/components/style-rtl.css 15.3 kB
build/components/style.css 15.3 kB
build/compose/index.min.js 10.9 kB
build/core-data/index.min.js 12.8 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 614 B
build/data/index.min.js 7.15 kB
build/date/index.min.js 31.5 kB
build/deprecated/index.min.js 428 B
build/dom-ready/index.min.js 304 B
build/dom/index.min.js 4.44 kB
build/edit-navigation/index.min.js 15.9 kB
build/edit-navigation/style-rtl.css 3.73 kB
build/edit-navigation/style.css 3.73 kB
build/edit-post/classic-rtl.css 492 B
build/edit-post/classic.css 494 B
build/edit-post/index.min.js 29.4 kB
build/edit-post/style-rtl.css 7.1 kB
build/edit-post/style.css 7.1 kB
build/edit-site/index.min.js 28 kB
build/edit-site/style-rtl.css 5.3 kB
build/edit-site/style.css 5.3 kB
build/edit-widgets/index.min.js 16.4 kB
build/edit-widgets/style-rtl.css 4.15 kB
build/edit-widgets/style.css 4.16 kB
build/editor/index.min.js 37.5 kB
build/editor/style-rtl.css 3.78 kB
build/editor/style.css 3.77 kB
build/element/index.min.js 3.21 kB
build/escape-html/index.min.js 517 B
build/format-library/index.min.js 6.38 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.55 kB
build/html-entities/index.min.js 424 B
build/i18n/index.min.js 3.6 kB
build/is-shallow-equal/index.min.js 501 B
build/keyboard-shortcuts/index.min.js 1.72 kB
build/keycodes/index.min.js 1.3 kB
build/list-reusable-blocks/index.min.js 1.85 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.91 kB
build/notices/index.min.js 845 B
build/nux/index.min.js 2.03 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.83 kB
build/primitives/index.min.js 921 B
build/priority-queue/index.min.js 582 B
build/react-i18n/index.min.js 671 B
build/redux-routine/index.min.js 2.63 kB
build/reusable-blocks/index.min.js 2.19 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 10.8 kB
build/server-side-render/index.min.js 1.52 kB
build/shortcode/index.min.js 1.48 kB
build/token-list/index.min.js 562 B
build/url/index.min.js 1.82 kB
build/viewport/index.min.js 1.02 kB
build/warning/index.min.js 248 B
build/widgets/index.min.js 7.11 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.04 kB

compressed-size-action

@jasmussen
Copy link
Contributor

This is wild, I had not expected you to address that feedback in this PR! Thank you, the one-row of two toggle groups looks much better:

buttons flex

I suspect there might be tweaks to do as we get further on the component system and #27331, which primarily works with two columns. I suspect we might even want to take inspiration from the work here to affect the layout panel for all flex blocks, perhaps including the Row block. All that is unrelated and not blocking, and this feels like a good baseline to start with. Impressive work! 👍 👍

@talldan
Copy link
Contributor

talldan commented Nov 3, 2021

This is great. I think it would be good to seriously consider progressing with this for 5.9, and then seeing whether it's possible to address any remaining bugs during the beta phase.

If it doesn't work out, the change can alway be reverted back.

The other thing I haven't solved is how to get a nested Spacer block to inherit the orientation from the Navigation block, given that orientation is no longer a block attribute.

This isn't something unique to nav block. Also an issue in the 'row' block variation, so I think you could consider it as something not introduced here. Would be good to solve for 5.9, but I feel it could be tackled as a separate effort.

@noisysocks noisysocks added [Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement. labels Nov 4, 2021
@tellthemachines
Copy link
Contributor Author

@jasmussen this PR adds layout to the Navigation block. There are lots of CSS changes I'd appreciate your feedback on!

In the meantime, I've fixed justification for the overlay menu.

The other thing I haven't solved is how to get a nested Spacer block to inherit the orientation from the Navigation block, given that orientation is no longer a block attribute.

This isn't something unique to nav block. Also an issue in the 'row' block variation, so I think you could consider it as something not introduced here. Would be good to solve for 5.9, but I feel it could be tackled as a separate effort.

Oh, I hadn't noticed it happening in Row. It makes sense to find a common approach for all these cases, then. Is there an issue for it already?

@talldan
Copy link
Contributor

talldan commented Nov 4, 2021

Oh, I hadn't noticed it happening in Row. It makes sense to find a common approach for all these cases, then. Is there an issue for it already?

I had a look and I don't think so.

@tellthemachines
Copy link
Contributor Author

I created #36197 so we can look at the Spacer issue.

@jasmussen
Copy link
Contributor

I was clearly confused when I first tested this one, sorry. I read it as applying to the Buttons block and was excited about bringing the orientation controls to the Row block in the future.

Now I took the Navigation block for a spin, thanks for your patience. Here's the new panel, working as intended:
nav

Lovely work, and an important refactor.

The next challenge at hand is managing the prominence and hierarchy of the inspector. Valuable customization options that are likely to be the most interesting to someone customizing their navigation, are being pushed downwards still more:
Screenshot 2021-11-04 at 07 56 04

These are ultimately separate issues to solve, but nevertheless something to be mindful of returning to. For the Layout panel, we might be reverting the "Allow to wrap" control, as it did not bring as much value as we had hoped, that would help. For the naming panel, it seems like it could echo the Template Part block and put these controls in the "Advanced" panel:

Screenshot 2021-11-04 at 08 01 22

The reason I bring it up is that additional visual customization options for the block will arrive in the future, so it's a challenge we will need to consider in the near future.

I found a few issues compared to trunk. First off, the overlay when opened inside the editor is offset:

Screenshot 2021-11-04 at 08 09 37

And the justifications inside the overlay menu do not work on the frontend. Some of the behaviors of that overlay menu are a bit gnarly and could use a refactor in the future, but as it exists, the overlay is designed to be a simple toggle with no further content customizations inside, meaning if you justify the menu right, the content of the menu is also justified right. See #36105 for some more gnarly details.

I'll dive into the CSS in a moment, and I'll see if I can push some fixes as well. One other thing I noted, is an issue also present in trunk, so unrelated, but storing as I noticed it here: the transforms section of the URL dialog is empty when used inside submenus. We can probably just hide that section entirely for submenus:
Screenshot 2021-11-04 at 08 10 02

@@ -441,28 +442,28 @@ $color-control-label-height: 20px;
}
}

.has-fixed-toolbar .wp-block-navigation__responsive-container.is-menu-open {
.has-fixed-toolbar .wp-block-navigation.is-responsive-menu-open {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the new simpler classnames. Hopefully it's just a missing update that's causing the justifications to not work on the frontend, pretty sure there are explicit justification rules that target this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you test the latest changes to this branch? Overlay menu justification wasn't working in the first iteration, but I've fixed it since. If you're testing locally, you might have to delete your local PR branch and check it out again, because I rebased it yesterday.

@@ -327,107 +314,29 @@
.is-responsive {
display: none;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

So much beautiful red here 👌

// Justification.
// These target the named container class to work even with the additional mobile menu containers.
.items-justified-center {
.wp-block-page-list,
Copy link
Contributor

Choose a reason for hiding this comment

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

These rules might be ones we need to restore, at least the responsive container parts as they affect the contents of the overlay.

Essentially, if you justify your navigation block to be centered, so should the content of the overlay be centered. The tricky piece comes with the dual variations, horizontal and vertical for the block itself, regardless of that orientation, the content of the overlay should always be vertically aligned to the top, so we can't just inherit the rules, and we have to have separate rules for the vertical and horizontal orientations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Justification inside the overlay should be working now. In any case, these styles no longer apply when using layout because items-justified-center etc. classnames aren't added to the markup.

The tricky piece comes with the dual variations

😅 yup, it was tricky all right. In order to make it work, I added a custom property --justification-setting to the layout-generated styles that get added to the block container. That property is then used to set justification inside the overlay regardless of whether the block is oriented vertically or horizontally. In my local it works well and content is always vertically aligned to the top, but as I mentioned above you may need to pull down this branch again to test the latest version.

align-items: flex-start;
justify-content: flex-start;
// Give it a z-index just higher than the adminbar.
z-index: 100000;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why we needed to change this z index.

Copy link
Contributor

Choose a reason for hiding this comment

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


// Always vertically align to the top.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is what I referred to previously, the content of the overlay modal should always be vertically aligned to the top, regardless of whatever parent orientation we have.

// Always vertically align to the top.
justify-content: flex-start;
.wp-block-navigation__responsive-container-content {
display: contents;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what this does. I understand that it makes the wrapping element invisible, but is that to simplify the inheritance rules? Keeping in mind that align-items and justify-content sort of flip when the orientation of the block itself does, unfortunately we can't just inherit those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, so display: contents works when the nav is not in responsive mode. When in responsive mode, it's overridden by the custom styles that display the overlay contents as a column, and alignment/justification are handled by the --justification-setting custom property.

justify-content: flex-start;
// Give it a z-index just higher than the adminbar.
z-index: 100000;
padding: $grid-unit-40*2 $grid-unit-30 $grid-unit-30;
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally I'd appreciate the move to variables. But since this is the style.scss file meant for the frontend as well, I don't think it's appropriate. The variables are mainly meant for block UI.

@jasmussen
Copy link
Contributor

It looks like some of the inherited layout classes (.wp-container-[id]) need some overrides:
importants

The max width and margins can be handled with these !importants which feel appropriate enough given they are meant to override other !importants:

.wp-block-navigation.is-responsive-menu-open {
	...
	margin-left: 0 !important;
	margin-right: 0 !important;
	max-width: none !important;
	margin-top: 0;
}

@jasmussen
Copy link
Contributor

The explicit submenu/overlay color options appear to have broken. They don't appear to be set at all:
color options

CC: @georgeh as I recall you working on this feature.

@jasmussen
Copy link
Contributor

The alignments inheritance is really difficult to get right. Your effort here is quite impressive, but I think we might need to rewind some of the CSS refactor, as the inheritance doesn't appear to be working as intended:
submenus

Would it be possible to do this refactor in smaller steps?

@talldan
Copy link
Contributor

talldan commented Nov 4, 2021

For the naming panel, it seems like it could echo the Template Part block and put these controls in the "Advanced" panel:

@jasmussen I get that this doesn't look great, but it saddens me that you've decided to ignore the feedback of your fellow collaborators. I really tried to find a compromise on this issue - #35981 (comment).

I feel like my feedback was ignored, and now it looks like you've decided to get around this by asking another contributor to implement the changes you want.

As mentioned on that issue, the navigation block differs from template parts. Template parts are always given a meaningful name on creation. Since #36024, the navigation block can have 'Untitled' menus where the user isn't given an opportunity to name them, so naming isn't only an advanced action.

I am very open to finding ways to improve the appearance. Making the panel less prominent. But I'd really prefer not to relegate it completely to the Advanced section. Can we come to a compromise here that makes us both happy?

@jasmussen
Copy link
Contributor

I want to be clear that I'm not asking anyone to implement changes here they do not support, it's separate from this PR. I bring it up in context of the layout panel introduced compounding the same issue: pushing downwards valuable appearance options for the menu. I genuinely think it's problematic to give prominence to a data store in a way that no other block does: if it truly is important to save, name and manage the states of blocks, then inversely we should bump the prominence of the same interface in the Template Part block.

It's fine that things are in flux and being explored. I've intentionally not blocked any PR from happening, so that PRs can land and be acted upon.

@talldan
Copy link
Contributor

talldan commented Nov 4, 2021

Since it's the feature freeze, my instinct was that the saving is the feature, and that the position of the naming field is safe to move even after that date. If not things can be revisited in the plugin and in 6.0. Would moving the panel down be an option?

I think this is a hazy area, it's probably down to the release lead, but as a small change it might be ok to include after feature freeze. I'd prefer to be on the safe side and address it before that point so that it doesn't get stuck in a position that you really disagree with.

Moving it down sounds good, I'll work on that tomorrow, and if you have any other ideas for temporary improvements to the panel itself I can look at those too.

@mtias
Copy link
Member

mtias commented Nov 4, 2021

I'm catching up a bit with the recent activity here.

As mentioned on that issue, the navigation block differs from template parts. Template parts are always given a meaningful name on creation.

I think this is the problem we need to address, everything else just spirals out from it.

  • It's important saving menus is as transparent to users as we can conjure.
  • Untitled menus is a poor experience; a user should not have to name things.
  • We should aim to auto-generate a name based on the template part a navigation is used. If a menu is added to a template root, we should use that, or just a numbered one.
    • Example: navigation-header, navigation-header-with-banner, navigation-1, navigation-archive, etc.
  • In practice, we'd be achieving the same conceptual flow as Navigation: Add an API to retrieve content-only inner blocks #30674 by rooting it into the template parts.
  • Adding a specific name can then become a more advanced operation. Orphaned menus because a template was removed, etc, is something we should look at separately.

It's crucial to me that saving something separately doesn't incur in extra over head for users because we'd want to leverage these mechanisms in more places — for example, the "overlay" we see on collapsed blocks is something we could conceptualize as a template part, but we wouldn't want users to name them or be exposed to that abstraction layer.

@tellthemachines
Copy link
Contributor Author

The explicit submenu/overlay color options appear to have broken. They don't appear to be set at all:

I can reproduce this on trunk too, so I think it's an underlying issue. The overlay is just inheriting the container backround color, so whatever background is set on the nav will appear on the overlay too.

The alignments inheritance is really difficult to get right. Your effort here is quite impressive, but I think we might need to rewind some of the CSS refactor, as the inheritance doesn't appear to be working as intended

I'm having trouble understanding that gif; there's a lot going on there 😅 (Apart from the overlay not stretching full width; I'm looking into that now). Could you give me some steps to reproduce/expected behaviour? The content alignment seems to be working well for me locally in both the editor and the front end.

Would it be possible to do this refactor in smaller steps?

I'm afraid that won't work. Layout breaks a lot of existing functionality for the nav block, so we need to make sure it's all done in one go to avoid regressions 😬

@tellthemachines
Copy link
Contributor Author

It looks like some of the inherited layout classes (.wp-container-[id]) need some overrides:

Ok I fixed this by reverting some of the styling changes. Initially I had attached the overlay styles to the block container, but this is no longer necessary because we don't need all the wrappers to display: contents when the nav is in overlay mode. So I put things back as they were 😄

I think that's all the issues addressed! This should be ready for another round of review. It would be great to get it in in the next few hours, otherwise it won't make 5.9.

@jasmussen
Copy link
Contributor

jasmussen commented Nov 5, 2021

This has made great progress! The overlay alignments do appear to work as intended.

There are a few things, and I'm currently looking at whether I can push fixes for it. The submenu colors do work in trunk, just not with the new Page List block:

Screenshot 2021-11-05 at 06 58 49

but here they don't appear to take:

Now they do appear to take 🤔 at least partially:

Screenshot 2021-11-05 at 07 11 27

I'm separately looking at some refinements to the direction submenus open in (#36215), but here that appears to not work fully as intended. When a menu is justified right, submenus should open leftwards, rather than rightwards:
Screenshot 2021-11-05 at 07 01 38

It might just be one of the rules that isn't reaching its goal anymore. I'll see if I can do anything.

Edit: the spacing/gap between items also appears to be off.

@jasmussen
Copy link
Contributor

Cool beans, the block spacing issue was due to TT1 blocks not opting into that option, so actually the previous note on spacing being up was a bug that this PR fixes:

Screenshot 2021-11-05 at 07 13 45

@jasmussen
Copy link
Contributor

It seems like the menu-opening-directions is a cause of the justification classes now missing. These are the rules that govern the direction the submenu opens:

https://github.com/WordPress/gutenberg/pull/36169/files#diff-d66a4ed73d0d50a799547b78db235a4bad3428a0decb8895752032cd849d01f0L285

Because they leverage the CSS classes applied for justifications, and those classes are missing, the rules now don't take. Can we add those classes back?

@jasmussen
Copy link
Contributor

I don't know why the submenu colors are applied to 2nd level nested items, but not the 1st level nested items, you can see the background color applied in this markup on the right:
Screenshot 2021-11-05 at 07 21 09

So as a quick summary for merging and fixing. The good stuff:

  • This is a nice overall refactor that brings navigation in line with buttons and other flex containers.
  • Because it's a big change to the CSS as well, it'd be good to land before the graduation day.

The missing pieces:

  • Dedicated submenu background colors appar to work somewhat in the editor, but only 2 levels deep on the frontend.
  • Justifications for which direction submenus open appears to need the now-missing justification classes. I can't think of a good way to fix this without them.

It might be okay to land this PR as is, with the missing pieces receiving quick followups. But if there are some quick fixes we can make, it'd be nice.

Note that the submenu background colors appear to be broken for the Page List also in trunk, so that's separate.

@tellthemachines
Copy link
Contributor Author

Thanks for the feedback and testing @jasmussen ! Let's look at what still needs to be addressed:

Dedicated submenu background colors appar to work somewhat in the editor, but only 2 levels deep on the frontend.

This is reproducible on trunk, and as far as I can tell it happens because the inline styles that provide the colors aren't being applied to the Submenu block at all. So in a submenu nested 2 deep, the first child item will be a submenu, so no color, and the second child item will presumably be a nav link block, so it gets the color. It shouldn't be too hard to fix but better do it separately.

Justifications for which direction submenus open appears to need the now-missing justification classes. I can't think of a good way to fix this without them.

This is a thornier issue because with layout those classes are no longer applied. The whole idea of layout is to make it unnecessary to add specific classes (and block-specific styles for those classes) to blocks. So our options here are:

  • Give up on using layout for Navigation and keep using classes and specific styling, which is not ideal because the UX will be forever inconsistent with other blocks, or
  • Work around this absence of classes somehow. Off the top of my head, we could:
    • Change dropdowns so they always fall below, instead of to the left/right (this would also be more small screen friendly than the current setup)
    • Try positioning them with JS (this could have variably dodgy results 😅)
    • Add another custom property in the styles output by layout with a value that reflects the current justification, that we can then hook onto to set the left/right values on the submenus (possibly leveraging this type of hackery)

I also noticed the open on click functionality for submenus seems to be broken on trunk, so that's one more thing to follow up on separately.

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

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

I'm ok with the idea of fixing the remaining issues during the beta period. It seems like this is 90% there, and it'd be a shame for it not to make it.

I'll give the PR a rebase.

@tellthemachines How confident are you about fixing those problems?

},
isEligible: ( { itemsJustification, orientation } ) =>
!! itemsJustification || !! orientation,
migrate: migrateWithLayout,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm cautious about this because of the discussion here - #35663.

I'm yet to write a migration and don't really fully understand them. A question I'd have is why v4 needs migrateFontFamily, but v5 doesn't? The definition of the two deprecations for font family looks identical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I more or less followed the logic used in #35819, as I realised in that PR that if the legacy justification mechanism isn't migrated, it's impossible to justify an old block using the new layout controls, because they're always overridden by the legacy styles. This may not apply exactly to nav as it's still experimental, but I added it in to be on the safe side.

I think this is something we can safely look at later though.

@jasmussen
Copy link
Contributor

If we have confidence in the ability to fix the remaining issues as bugs, that's good.

Give up on using layout for Navigation and keep using classes and specific styling, which is not ideal because the UX will be forever inconsistent with other blocks, or

I suspect #36241 may be the better long term solution. That would make submenu direction independant of justifications.

However in the near term, TwentyTwentyTwo is relying heavily on a right-justified navigation menu, as well as submenus, so I suspect we'll want to keep those classes at least in the near term. It's a behavior that's been refined for a while and is generally working well, so I'd be hesitant to remove it entirely. Even now, there's a great deal of nuance in how submenus open, and a lot of edgecases which are easy to forget, so I suspect a lot of that will have to be polished up if we do land this, and I'd appreciate help in doing so. #36215 for example is likely going to need to be rewritten for the changed structure.

@tellthemachines tellthemachines merged commit 051cd54 into trunk Nov 5, 2021
@tellthemachines tellthemachines deleted the try/navigation-flex-layout branch November 5, 2021 11:31
@github-actions github-actions bot added this to the Gutenberg 11.9 milestone Nov 5, 2021
@@ -535,8 +435,7 @@
@include break-small() {
&:not(.hidden-by-default) {
&:not(.is-menu-open) {
display: flex;
flex-direction: row;
display: contents;
Copy link
Member

@iandunn iandunn Nov 6, 2021

Choose a reason for hiding this comment

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

Is the Safari/a11y bug relevant here (and other places contents is used)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh, good point! I'll look into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can confirm display: contents wipes out list semantics. Looking at a fix now. Thanks for bringing it up!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And here's a fix : #36292

Copy link
Member

Choose a reason for hiding this comment

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

No problem, kudos for digging into that and figuring out an alternative 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate buttons & navigation to flex layout
6 participants