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 generic classnames to children of Navigation #33918

Merged
merged 7 commits into from
Aug 12, 2021

Conversation

tellthemachines
Copy link
Contributor

@tellthemachines tellthemachines commented Aug 6, 2021

Description

Fixes #33048. To make it easier to style children of the Navigation block consistently, we should have generic classnames that apply to all of them. This PR adds those classnames to Navigation Link and Home Link blocks, and conditionally to Page List when it is a child of Navigation.

To make the changes easier to review, this PR doesn't touch any CSS; we can consolidate that separately after the new classnames are sorted out.

Question: should we add the same classnames to any other blocks that can be used inside Navigation, such as Social Icons or Spacer?

How has this been tested?

Create a Navigation block containing the following blocks:

  • Navigation Link
  • Home link
  • Page List

Check that

  • wp-block-navigation-item is added to all the menu items
  • wp-block-navigation-item__content is added to their content.

Screenshots

Types of changes

New feature (non-breaking change which adds functionality)

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).

@tellthemachines tellthemachines added [Block] Navigation Affects the Navigation Block [Block] Navigation Link Affects the Navigation Link Block [Block] Page List Affects the Page List Block labels Aug 6, 2021
@github-actions
Copy link

github-actions bot commented Aug 6, 2021

Size Change: +469 B (0%)

Total Size: 1.07 MB

Filename Size Change
build/block-editor/index.min.js 127 kB -3 B (0%)
build/block-editor/style-rtl.css 13.9 kB +6 B (0%)
build/block-editor/style.css 13.9 kB +10 B (0%)
build/block-library/index.min.js 147 kB +50 B (0%)
build/block-library/reset-rtl.css 527 B +13 B (+3%)
build/block-library/reset.css 527 B +13 B (+3%)
build/components/index.min.js 216 kB -90 B (0%)
build/edit-post/classic-rtl.css 492 B +13 B (+3%)
build/edit-post/classic.css 494 B +13 B (+3%)
build/edit-post/index.min.js 30 kB +33 B (0%)
build/edit-site/index.min.js 26.4 kB +369 B (+1%)
build/edit-widgets/index.min.js 16.6 kB +44 B (0%)
build/editor/index.min.js 38.3 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 1.12 kB
build/admin-manifest/index.min.js 1.46 kB
build/annotations/index.min.js 2.93 kB
build/api-fetch/index.min.js 2.44 kB
build/autop/index.min.js 2.28 kB
build/blob/index.min.js 673 B
build/block-directory/index.min.js 6.62 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 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 474 B
build/block-library/blocks/button/editor.css 474 B
build/block-library/blocks/button/style-rtl.css 605 B
build/block-library/blocks/button/style.css 604 B
build/block-library/blocks/buttons/editor-rtl.css 315 B
build/block-library/blocks/buttons/editor.css 315 B
build/block-library/blocks/buttons/style-rtl.css 370 B
build/block-library/blocks/buttons/style.css 370 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 189 B
build/block-library/blocks/columns/editor.css 188 B
build/block-library/blocks/columns/style-rtl.css 474 B
build/block-library/blocks/columns/style.css 475 B
build/block-library/blocks/cover/editor-rtl.css 666 B
build/block-library/blocks/cover/editor.css 670 B
build/block-library/blocks/cover/style-rtl.css 1.23 kB
build/block-library/blocks/cover/style.css 1.23 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 400 B
build/block-library/blocks/embed/style.css 400 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 711 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 707 B
build/block-library/blocks/gallery/editor.css 706 B
build/block-library/blocks/gallery/style-rtl.css 1.05 kB
build/block-library/blocks/gallery/style.css 1.05 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 93 B
build/block-library/blocks/group/theme.css 93 B
build/block-library/blocks/heading/editor-rtl.css 152 B
build/block-library/blocks/heading/editor.css 152 B
build/block-library/blocks/heading/style-rtl.css 76 B
build/block-library/blocks/heading/style.css 76 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 283 B
build/block-library/blocks/html/editor.css 284 B
build/block-library/blocks/image/editor-rtl.css 728 B
build/block-library/blocks/image/editor.css 728 B
build/block-library/blocks/image/style-rtl.css 482 B
build/block-library/blocks/image/style.css 487 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 63 B
build/block-library/blocks/list/style.css 63 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 488 B
build/block-library/blocks/media-text/style.css 485 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 474 B
build/block-library/blocks/navigation-link/editor.css 474 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/editor-rtl.css 1.67 kB
build/block-library/blocks/navigation/editor.css 1.68 kB
build/block-library/blocks/navigation/style-rtl.css 1.65 kB
build/block-library/blocks/navigation/style.css 1.64 kB
build/block-library/blocks/navigation/view.min.js 2.84 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 310 B
build/block-library/blocks/page-list/editor.css 310 B
build/block-library/blocks/page-list/style-rtl.css 242 B
build/block-library/blocks/page-list/style.css 242 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 248 B
build/block-library/blocks/paragraph/style.css 248 B
build/block-library/blocks/post-author/editor-rtl.css 210 B
build/block-library/blocks/post-author/editor.css 210 B
build/block-library/blocks/post-author/style-rtl.css 182 B
build/block-library/blocks/post-author/style.css 181 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B
build/block-library/blocks/post-comments-form/style.css 140 B
build/block-library/blocks/post-comments/style-rtl.css 360 B
build/block-library/blocks/post-comments/style.css 359 B
build/block-library/blocks/post-content/editor-rtl.css 138 B
build/block-library/blocks/post-content/editor.css 138 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 412 B
build/block-library/blocks/post-featured-image/editor.css 412 B
build/block-library/blocks/post-featured-image/style-rtl.css 143 B
build/block-library/blocks/post-featured-image/style.css 143 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 378 B
build/block-library/blocks/post-template/style.css 379 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 361 B
build/block-library/blocks/pullquote/style.css 360 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 270 B
build/block-library/blocks/query-pagination/editor.css 262 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B
build/block-library/blocks/query-pagination/style.css 168 B
build/block-library/blocks/query-title/editor-rtl.css 85 B
build/block-library/blocks/query-title/editor.css 85 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 169 B
build/block-library/blocks/quote/style.css 169 B
build/block-library/blocks/quote/theme-rtl.css 220 B
build/block-library/blocks/quote/theme.css 222 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 209 B
build/block-library/blocks/search/editor.css 209 B
build/block-library/blocks/search/style-rtl.css 368 B
build/block-library/blocks/search/style.css 372 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 250 B
build/block-library/blocks/separator/style.css 250 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 462 B
build/block-library/blocks/site-logo/editor.css 464 B
build/block-library/blocks/site-logo/style-rtl.css 153 B
build/block-library/blocks/site-logo/style.css 153 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 165 B
build/block-library/blocks/social-link/editor.css 165 B
build/block-library/blocks/social-links/editor-rtl.css 812 B
build/block-library/blocks/social-links/editor.css 811 B
build/block-library/blocks/social-links/style-rtl.css 1.33 kB
build/block-library/blocks/social-links/style.css 1.33 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 636 B
build/block-library/blocks/template-part/editor.css 635 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/term-description/editor-rtl.css 90 B
build/block-library/blocks/term-description/editor.css 90 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 1.29 kB
build/block-library/common.css 1.29 kB
build/block-library/editor-rtl.css 9.87 kB
build/block-library/editor.css 9.85 kB
build/block-library/style-rtl.css 10.2 kB
build/block-library/style.css 10.2 kB
build/block-library/theme-rtl.css 688 B
build/block-library/theme.css 692 B
build/block-serialization-default-parser/index.min.js 1.3 kB
build/block-serialization-spec-parser/index.min.js 3.06 kB
build/blocks/index.min.js 47.2 kB
build/components/style-rtl.css 15.8 kB
build/components/style.css 15.8 kB
build/compose/index.min.js 10.3 kB
build/core-data/index.min.js 12.6 kB
build/customize-widgets/index.min.js 10.8 kB
build/customize-widgets/style-rtl.css 1.5 kB
build/customize-widgets/style.css 1.49 kB
build/data-controls/index.min.js 831 B
build/data/index.min.js 7.22 kB
build/date/index.min.js 31.8 kB
build/deprecated/index.min.js 737 B
build/dom-ready/index.min.js 576 B
build/dom/index.min.js 4.78 kB
build/edit-navigation/index.min.js 13.9 kB
build/edit-navigation/style-rtl.css 3.1 kB
build/edit-navigation/style.css 3.1 kB
build/edit-post/style-rtl.css 7.18 kB
build/edit-post/style.css 7.17 kB
build/edit-site/style-rtl.css 5.01 kB
build/edit-site/style.css 5.01 kB
build/edit-widgets/style-rtl.css 4.01 kB
build/edit-widgets/style.css 4.02 kB
build/editor/style-rtl.css 3.92 kB
build/editor/style.css 3.91 kB
build/element/index.min.js 3.44 kB
build/escape-html/index.min.js 739 B
build/format-library/index.min.js 5.72 kB
build/format-library/style-rtl.css 668 B
build/format-library/style.css 669 B
build/hooks/index.min.js 1.76 kB
build/html-entities/index.min.js 628 B
build/i18n/index.min.js 3.73 kB
build/is-shallow-equal/index.min.js 710 B
build/keyboard-shortcuts/index.min.js 1.74 kB
build/keycodes/index.min.js 1.49 kB
build/list-reusable-blocks/index.min.js 2.07 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 3.08 kB
build/notices/index.min.js 1.07 kB
build/nux/index.min.js 2.31 kB
build/nux/style-rtl.css 747 B
build/nux/style.css 743 B
build/plugins/index.min.js 1.99 kB
build/primitives/index.min.js 1.06 kB
build/priority-queue/index.min.js 791 B
build/react-i18n/index.min.js 922 B
build/redux-routine/index.min.js 2.82 kB
build/reusable-blocks/index.min.js 2.56 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.64 kB
build/shortcode/index.min.js 1.68 kB
build/token-list/index.min.js 847 B
build/url/index.min.js 1.95 kB
build/viewport/index.min.js 1.28 kB
build/warning/index.min.js 1.16 kB
build/widgets/index.min.js 6.48 kB
build/widgets/style-rtl.css 1.04 kB
build/widgets/style.css 1.04 kB
build/wordcount/index.min.js 1.24 kB

compressed-size-action

@jasmussen
Copy link
Contributor

This is so beautiful. It also feels like it fully moves the responsibility of handling the spacing, positioning and margins of navigation contents to the navigation block itself, rather than on every block that will sit inside. This feels like a very solid move in the right direction.

This PR adds those classnames to Navigation Link and Home Link blocks, and conditionally to Page List when it is a child of Navigation.

Getting page list in as a part of this would be so amazing, and would likely fix #31879. In my testing, this is now working on the frontend, but I don't yet see the classes inside the editor.

To make the changes easier to review, this PR doesn't touch any CSS; we can consolidate that separately after the new classnames are sorted out.

I'd be more than happy to help sort that out after this PR!

Question: should we add the same classnames to any other blocks that can be used inside Navigation, such as Social Icons or Spacer?

Good question. Is this something we could do at a later point? Just looking at spacing things out, it could be useful:

Screenshot 2021-08-06 at 08 10 02

However since the markup currently puts menu items inside a menu item container, my instinct would be to wait and see:

Screenshot 2021-08-06 at 08 10 13

Nice work!

@tellthemachines
Copy link
Contributor Author

In my testing, this is now working on the frontend, but I don't yet see the classes inside the editor.

Fixed it! Should now be working everywhere 😅

Is this something we could do at a later point?

Yeah, we can always go back and add classes to other blocks. If we were removing existing classes it would break back-compat, but this way it's fine.

@jasmussen
Copy link
Contributor

I like this a lot:

Screenshot 2021-08-09 at 08 34 18

It feels like the right direction for me. Should we land this PR as-is? Then I can follow up separately on adding the new classes as the canonical styling classes, perhaps add some deprecation comments about the old classes.

If yes, then it seems like the next thing is landing this one. @gwwar since you touched adjacent concepts for the Home Link, if you have bandwidth, can you take a look? Thank you.

@tellthemachines
Copy link
Contributor Author

I'd like to add a common submenu class before merging, because that will help fix a bug I just noticed with the Page list submenus on a dark background:

Screen Shot 2021-08-09 at 4 49 08 pm

It shouldn't take too long, working on it now.

@tellthemachines
Copy link
Contributor Author

Ok, I added wp-block-navigation__submenu-container to the containers and wp-block-navigation__submenu-icon to the icons, so this PR is now ready for code review.

I'm thinking, once we've cleaned up the CSS, we needn't keep the old classnames for any of the Navigation-related blocks, because Navigation is still experimental. We'll have to keep them for the Page List block though, as it's already in Core and also it can be used standalone. We should still keep the top-level classname for each individual block, e.g. wp-block-navigation-link, but we can remove the nested ones.

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

This seems like a really good improvement.

As @jasmussen says, it passes responsibility to the Nav block for sorting out the layout of its expected child blocks.

Results

This tested well for me except I noticed that the Page List <ul> doesn't have the classes. I assume it would as you would want to space it away from the other "items". I assume this is done because in actual fact you want to space the "items" that are within the Page List block rather than the block itself?

✅ Frontend

Screen Shot 2021-08-09 at 17 05 30

✅ Editor

Screen Shot 2021-08-09 at 17 03 57

Concern

Nit: I was slightly concerned by the addition of is_navigation_child. Are we in danger of coupling Page List too tightly to Navigation? Would there be a way of allowing Nav block to adjust the markup of Page List rather than the other way around?

@tellthemachines
Copy link
Contributor Author

tellthemachines commented Aug 10, 2021

This tested well for me except I noticed that the Page List <ul> doesn't have the classes. I assume it would as you would want to space it away from the other "items". I assume this is done because in actual fact you want to space the "items" that are within the Page List block rather than the block itself?

Yeah, the styling has to be added to the <li> children of Page list, as it is to the Navigation Link items. We could potentially have a common class between the Page List <ul> and the Navigation Link wrapper <ul> (the one withwp-block-navigation__container) but then we might as well add the same class to all top-level blocks that are allowed in Navigation. We talked about that above and @jasmussen thought it could be left for later.

Nit: I was slightly concerned by the addition of is_navigation_child. Are we in danger of coupling Page List too tightly to Navigation? Would there be a way of allowing Nav block to adjust the markup of Page List rather than the other way around?

Hmm, that's a very good question 😄

I don't think Page List is tightly coupled to Navigation in the sense that it can be used as a standalone block, and as standalone, there's no visible evidence of its relationship with Navigation.

What could a mechanism to adjust children's markup in the Nav block look like? Currently the only block that needs these common classes and can also be used outside of Nav is Page List, but there will be more in the future, and they all need different classes added in different places, so potentially that would mean a lot of extra logic in the Nav block. What are the advantages of doing it? And what are the downsides of a block containing logic that relates to its parent?

(I'm asking all these questions because I really don't know how to answer your original question 😅)

I think problems with Navigation can be hard to think through because they're often unique to this block, so we can't look to other blocks for ideas. In many ways, it doesn't want to behave like a block at all: it has so many constraints about what can and can't go into it, as well as blocks that can only be used inside it. So it makes sense that a lot of the solutions we find will also be specific to this block, and not applicable elsewhere.

@jasmussen
Copy link
Contributor

jasmussen commented Aug 10, 2021

I don't think Page List is tightly coupled to Navigation in the sense that it can be used as a standalone block, and as standalone, there's no visible evidence of its relationship with Navigation.

The Page List is useful as a standalone block, I know @mkaz has pondered a "Show subpages only" toggle to it.

It's also great in the Navigation block as it keeps things in sync. The server side nature of it, though, has meant it wasn't able to easily receive color properties in the recent separate overlay color PR. I don't imagine it would be necessary to write an additional Page List block to accommodate this, but if it were, it could be tied directly to it to the point that it wasn't allowed outside.

Alternatively, could we tie the classname output of "is_navigation_child" to only be output when the Page List is a child of the navigation block? I can't speak to the feasibility or whether it's good practice, just rubber-ducking really, because as suggested above, I do sort of share the same concern.

This tested well for me except I noticed that the Page List <ul> doesn't have the classes. I assume it would as you would want to space it away from the other "items". I assume this is done because in actual fact you want to space the "items" that are within the Page List block rather than the block itself?

I'm not certain I'm understanding you completely, but I read this as speaking to the structure differential between page list items and direct nav items, like so:

Nav
	Nav item
	Nav item
	Page List
		Page List item
		Page List item
	/Page List
/Nav

At the moment, the CSS of the navigation block is designed so that visually the above looks as if it's just a flat list of 4 menu items, mostly ignoring the Page List container itself. It's possible that's not necessarily the best way, I'll try and revisit that when I get a chance to refactor the CSS pending these class changes.

Tangential to that, I discovered that there's a frontend/backend markup differential as well, best described on the original PR: #32367 (comment)

@tellthemachines
Copy link
Contributor Author

Alternatively, could we tie the classname output of "is_navigation_child" to only be output when the Page List is a child of the navigation block?

This already happens! is_navigation_child is used inside Page List to determine whether to output the extra classes and the dropdown indicator. That's what I meant by "there's no visible evidence of its relationship with Navigation" when it's used standalone 🙂

The only coupling is in the actual logic, because Page List needs to know who its parent is, and make decisions based on that. But I think that's less messy than having Navigation take responsibility for all its children's output (unless there's a neat way to do this that I'm not seeing, which is why I was asking all the questions above 😅 )

@getdave
Copy link
Contributor

getdave commented Aug 11, 2021

But I think that's less messy than having Navigation take responsibility for all its children's output (unless there's a neat way to do this that I'm not seeing, which is why I was asking all the questions above 😅 )

I was just thinking Navigation could look at it's inner blocks and then add the classNames to them as required. I think Columns manages it's own inner blocks a fair amount:

updateAlignment( verticalAlignment ) {

As className is an attribute can we not update the attributes on all innerBlocks to include the nav-specific classname?

The only other way I was thinking was via the classname filter.

@tellthemachines
Copy link
Contributor Author

I was just thinking Navigation could look at it's inner blocks and then add the classNames to them as required. I think Columns manages it's own inner blocks a fair amount:

Hmm, Columns block is setting the attributes of its inner blocks, and then each Column still has to work out what to do with them. An easier way to do something like that here, given we're using the same classnames on all child blocks, would be to pass them down via block context.

The advantage of that is we could declare all the classnames in a single place instead of hardcoding them in each child block, but it comes at the expense of added complexity in the child blocks, because we'll have to check that each classname exists in context before adding it to the markup. For some of the blocks (Nav link, Home link) this is overkill because they are always children of Nav, so hardcoding the classnames in is simpler.

We could only do it for Page List, and hardcode the classes in the other blocks, but that sort of defeats the point.

The other thing I'm thinking is that with $is_navigation_child, we're able to conditionally render the submenu icon only when the Page List is a child of Nav, whereas currently we're rendering it all the time, but hiding it with display:none when the block is standalone. So in a way it's actually less coupled if we continue using $is_navigation_child 😅

The context thing might be useful if we ever have a block that can inherit classnames from more than one parent, but this is something we can always change in the future if needed, as it won't affect the output markup in any way.

We wouldn't be able to use the classname filter here, because it only sets classes at the block wrapper level, and we need to set classes in several places inside the block.

@getdave
Copy link
Contributor

getdave commented Aug 12, 2021

Sounds like my idea is just making things overly complex. Let's run with the prop on the Page List for now and we can always refactor later if necessary.

Sorry for derailing things here but I think it's been a useful exploration of the alternatives 🙇‍♂️

Copy link
Contributor

@getdave getdave left a comment

Choose a reason for hiding this comment

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

Based on discussion and previously testing I'd say we're good to go.

@jasmussen
Copy link
Contributor

As a followup I've started work in #34171 to leverage these classes. If you have bandwidth I'd love just a small sanity check on the work in progress to see if I haven't missed anything. So far it's working perfectly, though there are a few page list edgecases I'd like to tweak.

An additional question: right now the Page List and Home Link blocks are changed to output the generic classname when used inside. That's fine — but would it be possible for the navigation block to handle that classname assignment? I think I've asked a mostly identical question on the Site Logo block PR 🙈

@tellthemachines
Copy link
Contributor Author

right now the Page List and Home Link blocks are changed to output the generic classname when used inside. That's fine — but would it be possible for the navigation block to handle that classname assignment?

What we can do (and would work well with the Site Logo PR too) is pass the classname to the child blocks via Navigation block context. The advantage of that is the classname is declared by the parent.

However, we'll still need logic in the child blocks to detect if the context exists and, if so, apply the classnames in the correct places. There's no way of having the Navigation block alter its children's markup, if that's what you mean.

@jasmussen
Copy link
Contributor

Thanks for clarifying. Sounds like that might be an improvement, but I'll defer to you. It's mostly a thought out of ensuring 3rd party menu item blocks can get the right positioning rules like everything else. But let me think a bit more about that.

@tellthemachines
Copy link
Contributor Author

It's mostly a thought out of ensuring 3rd party menu item blocks can get the right positioning rules like everything else.

That's a very good point I hadn't considered 😄

Currently the Nav block only accepts a list of a few core blocks as children. I'm not sure it's possible to add to that list through a filter or something, but if it were, that would also raise the semantics issue: currently we wrap menu items in a list element, and for that purpose we decide what a menu item is. That list isn't filterable and probably shouldn't be as it's an implementation detail. Do we have any examples of 3rd party blocks specifically meant for Navigation?

For mega menus, things might change as we'll be allowing all sorts of blocks - but I reckon that for anything that isn't a simple list of menu items (with possible sub-lists), we can build the layout with just CSS. The biggest problem we were having here, that the generic classnames solve, is that there are several blocks essentially adding the same type of content (menu items and submenus) to Navigation, and we need them all to look the same. With different types of content, this won't be so much of an issue.

@jasmussen
Copy link
Contributor

Currently the Nav block only accepts a list of a few core blocks as children. I'm not sure it's possible to add to that list through a filter or something, but if it were, that would also raise the semantics issue: currently we wrap menu items in a list element, and for that purpose we decide what a menu item is. That list isn't filterable and probably shouldn't be as it's an implementation detail. Do we have any examples of 3rd party blocks specifically meant for Navigation?

Dug up an older pull request that enables adding additional items to the menu, this one: #31584. It seems that particular approach might not be gaining traction, but the principle appears to have been enabling inserting something like a WooCommerce category link, which would then suggest woo categories in the dropdown. Though per your description above it seems like we'd be able to handle the classnames even in that use case.

@tellthemachines
Copy link
Contributor Author

Dug up an older pull request that enables adding additional items to the menu, this one: #31584.

Oh, I see. That PR would only be adding new variations to the core Navigation Link block, not new blocks altogether. It would still be a core block, so it would have all the default classnames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Link Affects the Navigation Link Block [Block] Navigation Affects the Navigation Block [Block] Page List Affects the Page List Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation: use generic css class names for navigation items
3 participants