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

Responsive Navigation #30047

Merged
merged 35 commits into from
May 12, 2021
Merged

Responsive Navigation #30047

merged 35 commits into from
May 12, 2021

Conversation

vcanales
Copy link
Member

@vcanales vcanales commented Mar 19, 2021

Description

This PR introduces a mobile responsive Navigation Block. It add the markup necessary to display the Navigation Menu as a floating modal when the resolution of the site is below our mobile breakpoint.

Functionality in this PR depends on #29537 in order to add a library which enables toggling the visibility of the Menu, as well as creating an accessible experience. Here I am working under the assumption that this will be a possibility in the near future.

Next steps, and known issues

  • Get accessibility working — it did not work out of the box. No guesses yet as to why this was the case.
  • Proper UI.
  • Toggling responsiveness on and off.
  • Wrap the Navigation container in the modal markup only if responsiveness has been turned on.
  • Custom styling — I haven't thought that far ahead at this point, but I'm assuming that at the very least we'd like to support the current overlay version, and a slide down menu.

Testing steps

  • Checkout this branch.
  • Create a navigation menu.
  • Make your browser screen smaller, below 480px.
  • A button labeled "Open Menu" should appear.
  • After clicking that button, elements should be shown vertically on smaller resolutions
  • A button should appear in the top right corner of the screen, which allows closing the modal/overlay.

Small demo

responsivenavdraft.mov

@vcanales vcanales added the [Block] Navigation Affects the Navigation Block label Mar 19, 2021
@vcanales vcanales requested a review from jasmussen March 19, 2021 21:01
webpack.config.js Outdated Show resolved Hide resolved
packages/block-library/src/navigation/index.php Outdated Show resolved Hide resolved
packages/block-library/src/navigation/frontend.js Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Mar 19, 2021

Size Change: +5.6 kB (0%)

Total Size: 1.32 MB

Filename Size Change
build/a11y/index.js 1.12 kB +1 B (0%)
build/api-fetch/index.js 2.42 kB +1 B (0%)
build/block-directory/index.js 6.6 kB +3 B (0%)
build/block-editor/index.js 116 kB +315 B (0%)
build/block-editor/style-rtl.css 13 kB +5 B (0%)
build/block-editor/style.css 13 kB +5 B (0%)
build/block-library/blocks/button/style-rtl.css 601 B +86 B (+17%) ⚠️
build/block-library/blocks/button/style.css 600 B +85 B (+17%) ⚠️
build/block-library/blocks/buttons/style-rtl.css 375 B +7 B (+2%)
build/block-library/blocks/buttons/style.css 375 B +7 B (+2%)
build/block-library/blocks/cover/editor-rtl.css 643 B +40 B (+7%) 🔍
build/block-library/blocks/cover/editor.css 645 B +41 B (+7%) 🔍
build/block-library/blocks/image/style-rtl.css 481 B +5 B (+1%)
build/block-library/blocks/image/style.css 485 B +7 B (+1%)
build/block-library/blocks/navigation/editor-rtl.css 1.52 kB +205 B (+16%) ⚠️
build/block-library/blocks/navigation/editor.css 1.52 kB +205 B (+16%) ⚠️
build/block-library/blocks/navigation/style-rtl.css 1.71 kB +440 B (+35%) 🚨
build/block-library/blocks/navigation/style.css 1.71 kB +443 B (+35%) 🚨
build/block-library/blocks/page-list/style-rtl.css 204 B +37 B (+22%) 🚨
build/block-library/blocks/page-list/style.css 204 B +37 B (+22%) 🚨
build/block-library/blocks/post-featured-image/style-rtl.css 119 B +19 B (+19%) ⚠️
build/block-library/blocks/post-featured-image/style.css 119 B +19 B (+19%) ⚠️
build/block-library/editor-rtl.css 9.84 kB +214 B (+2%)
build/block-library/editor.css 9.83 kB +215 B (+2%)
build/block-library/index.js 143 kB +1.05 kB (+1%)
build/block-library/style-rtl.css 10.1 kB +690 B (+7%) 🔍
build/block-library/style.css 10.2 kB +686 B (+7%) 🔍
build/block-serialization-default-parser/index.js 1.3 kB +1 B (0%)
build/blocks/index.js 47.1 kB +32 B (0%)
build/components/index.js 188 kB +496 B (0%)
build/compose/index.js 9.92 kB +1 B (0%)
build/customize-widgets/index.js 5.99 kB +198 B (+3%)
build/data/index.js 7.22 kB +2 B (0%)
build/date/index.js 31.8 kB +3 B (0%)
build/dom/index.js 4.62 kB -1 B (0%)
build/edit-navigation/index.js 13.5 kB -77 B (-1%)
build/edit-navigation/style-rtl.css 2.83 kB +17 B (+1%)
build/edit-navigation/style.css 2.83 kB +18 B (+1%)
build/edit-post/index.js 333 kB +89 B (0%)
build/edit-site/index.js 26.1 kB +4 B (0%)
build/edit-widgets/index.js 12.6 kB +14 B (0%)
build/editor/index.js 60.5 kB +1 B (0%)
build/element/index.js 3.44 kB -2 B (0%)
build/format-library/index.js 5.67 kB -11 B (0%)
build/i18n/index.js 3.73 kB +2 B (0%)
build/keyboard-shortcuts/index.js 1.65 kB -2 B (0%)
build/list-reusable-blocks/index.js 2.06 kB +1 B (0%)
build/nux/index.js 2.3 kB -3 B (0%)
build/primitives/index.js 1.03 kB -5 B (0%)
build/redux-routine/index.js 2.82 kB -1 B (0%)
build/reusable-blocks/index.js 2.56 kB +1 B (0%)
build/rich-text/index.js 11.8 kB -52 B (0%)
build/server-side-render/index.js 1.64 kB +1 B (0%)
build/shortcode/index.js 1.69 kB +1 B (0%)
build/token-list/index.js 848 B +1 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/annotations/index.js 2.93 kB 0 B
build/autop/index.js 2.28 kB 0 B
build/blob/index.js 673 B 0 B
build/block-directory/style-rtl.css 993 B 0 B
build/block-directory/style.css 995 B 0 B
build/block-library/blocks/archives/editor-rtl.css 61 B 0 B
build/block-library/blocks/archives/editor.css 60 B 0 B
build/block-library/blocks/audio/editor-rtl.css 58 B 0 B
build/block-library/blocks/audio/editor.css 58 B 0 B
build/block-library/blocks/audio/style-rtl.css 112 B 0 B
build/block-library/blocks/audio/style.css 112 B 0 B
build/block-library/blocks/block/editor-rtl.css 161 B 0 B
build/block-library/blocks/block/editor.css 161 B 0 B
build/block-library/blocks/button/editor-rtl.css 475 B 0 B
build/block-library/blocks/button/editor.css 474 B 0 B
build/block-library/blocks/buttons/editor-rtl.css 315 B 0 B
build/block-library/blocks/buttons/editor.css 315 B 0 B
build/block-library/blocks/calendar/style-rtl.css 208 B 0 B
build/block-library/blocks/calendar/style.css 208 B 0 B
build/block-library/blocks/categories/editor-rtl.css 84 B 0 B
build/block-library/blocks/categories/editor.css 83 B 0 B
build/block-library/blocks/categories/style-rtl.css 79 B 0 B
build/block-library/blocks/categories/style.css 79 B 0 B
build/block-library/blocks/code/style-rtl.css 90 B 0 B
build/block-library/blocks/code/style.css 90 B 0 B
build/block-library/blocks/columns/editor-rtl.css 190 B 0 B
build/block-library/blocks/columns/editor.css 190 B 0 B
build/block-library/blocks/columns/style-rtl.css 422 B 0 B
build/block-library/blocks/columns/style.css 422 B 0 B
build/block-library/blocks/cover/style-rtl.css 1.22 kB 0 B
build/block-library/blocks/cover/style.css 1.22 kB 0 B
build/block-library/blocks/embed/editor-rtl.css 486 B 0 B
build/block-library/blocks/embed/editor.css 486 B 0 B
build/block-library/blocks/embed/style-rtl.css 401 B 0 B
build/block-library/blocks/embed/style.css 400 B 0 B
build/block-library/blocks/file/editor-rtl.css 301 B 0 B
build/block-library/blocks/file/editor.css 300 B 0 B
build/block-library/blocks/file/frontend.js 773 B 0 B
build/block-library/blocks/file/style-rtl.css 255 B 0 B
build/block-library/blocks/file/style.css 255 B 0 B
build/block-library/blocks/freeform/editor-rtl.css 2.45 kB 0 B
build/block-library/blocks/freeform/editor.css 2.45 kB 0 B
build/block-library/blocks/gallery/editor-rtl.css 704 B 0 B
build/block-library/blocks/gallery/editor.css 705 B 0 B
build/block-library/blocks/gallery/style-rtl.css 1.06 kB 0 B
build/block-library/blocks/gallery/style.css 1.05 kB 0 B
build/block-library/blocks/group/editor-rtl.css 160 B 0 B
build/block-library/blocks/group/editor.css 160 B 0 B
build/block-library/blocks/group/style-rtl.css 57 B 0 B
build/block-library/blocks/group/style.css 57 B 0 B
build/block-library/blocks/heading/editor-rtl.css 129 B 0 B
build/block-library/blocks/heading/editor.css 129 B 0 B
build/block-library/blocks/heading/style-rtl.css 76 B 0 B
build/block-library/blocks/heading/style.css 76 B 0 B
build/block-library/blocks/home-link/style-rtl.css 259 B 0 B
build/block-library/blocks/home-link/style.css 259 B 0 B
build/block-library/blocks/html/editor-rtl.css 281 B 0 B
build/block-library/blocks/html/editor.css 281 B 0 B
build/block-library/blocks/image/editor-rtl.css 717 B 0 B
build/block-library/blocks/image/editor.css 716 B 0 B
build/block-library/blocks/latest-comments/style-rtl.css 281 B 0 B
build/block-library/blocks/latest-comments/style.css 282 B 0 B
build/block-library/blocks/latest-posts/editor-rtl.css 137 B 0 B
build/block-library/blocks/latest-posts/editor.css 137 B 0 B
build/block-library/blocks/latest-posts/style-rtl.css 523 B 0 B
build/block-library/blocks/latest-posts/style.css 522 B 0 B
build/block-library/blocks/legacy-widget/editor-rtl.css 557 B 0 B
build/block-library/blocks/legacy-widget/editor.css 557 B 0 B
build/block-library/blocks/list/style-rtl.css 63 B 0 B
build/block-library/blocks/list/style.css 63 B 0 B
build/block-library/blocks/media-text/editor-rtl.css 176 B 0 B
build/block-library/blocks/media-text/editor.css 176 B 0 B
build/block-library/blocks/media-text/style-rtl.css 492 B 0 B
build/block-library/blocks/media-text/style.css 489 B 0 B
build/block-library/blocks/more/editor-rtl.css 434 B 0 B
build/block-library/blocks/more/editor.css 434 B 0 B
build/block-library/blocks/navigation-link/editor-rtl.css 617 B 0 B
build/block-library/blocks/navigation-link/editor.css 619 B 0 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B 0 B
build/block-library/blocks/navigation-link/style.css 94 B 0 B
build/block-library/blocks/nextpage/editor-rtl.css 395 B 0 B
build/block-library/blocks/nextpage/editor.css 395 B 0 B
build/block-library/blocks/page-list/editor-rtl.css 239 B 0 B
build/block-library/blocks/page-list/editor.css 240 B 0 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B 0 B
build/block-library/blocks/paragraph/editor.css 157 B 0 B
build/block-library/blocks/paragraph/style-rtl.css 247 B 0 B
build/block-library/blocks/paragraph/style.css 248 B 0 B
build/block-library/blocks/post-author/editor-rtl.css 209 B 0 B
build/block-library/blocks/post-author/editor.css 209 B 0 B
build/block-library/blocks/post-author/style-rtl.css 183 B 0 B
build/block-library/blocks/post-author/style.css 184 B 0 B
build/block-library/blocks/post-comments-form/style-rtl.css 140 B 0 B
build/block-library/blocks/post-comments-form/style.css 140 B 0 B
build/block-library/blocks/post-comments/style-rtl.css 360 B 0 B
build/block-library/blocks/post-comments/style.css 359 B 0 B
build/block-library/blocks/post-content/editor-rtl.css 139 B 0 B
build/block-library/blocks/post-content/editor.css 139 B 0 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B 0 B
build/block-library/blocks/post-excerpt/editor.css 73 B 0 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B 0 B
build/block-library/blocks/post-excerpt/style.css 69 B 0 B
build/block-library/blocks/post-featured-image/editor-rtl.css 338 B 0 B
build/block-library/blocks/post-featured-image/editor.css 338 B 0 B
build/block-library/blocks/post-title/style-rtl.css 60 B 0 B
build/block-library/blocks/post-title/style.css 60 B 0 B
build/block-library/blocks/preformatted/style-rtl.css 103 B 0 B
build/block-library/blocks/preformatted/style.css 103 B 0 B
build/block-library/blocks/pullquote/editor-rtl.css 183 B 0 B
build/block-library/blocks/pullquote/editor.css 183 B 0 B
build/block-library/blocks/pullquote/style-rtl.css 318 B 0 B
build/block-library/blocks/pullquote/style.css 318 B 0 B
build/block-library/blocks/query-loop/editor-rtl.css 83 B 0 B
build/block-library/blocks/query-loop/editor.css 82 B 0 B
build/block-library/blocks/query-loop/style-rtl.css 315 B 0 B
build/block-library/blocks/query-loop/style.css 317 B 0 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B 0 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B 0 B
build/block-library/blocks/query-pagination/editor-rtl.css 270 B 0 B
build/block-library/blocks/query-pagination/editor.css 262 B 0 B
build/block-library/blocks/query-pagination/style-rtl.css 168 B 0 B
build/block-library/blocks/query-pagination/style.css 168 B 0 B
build/block-library/blocks/query-title/editor-rtl.css 86 B 0 B
build/block-library/blocks/query-title/editor.css 86 B 0 B
build/block-library/blocks/query/editor-rtl.css 131 B 0 B
build/block-library/blocks/query/editor.css 132 B 0 B
build/block-library/blocks/quote/style-rtl.css 169 B 0 B
build/block-library/blocks/quote/style.css 169 B 0 B
build/block-library/blocks/rss/editor-rtl.css 201 B 0 B
build/block-library/blocks/rss/editor.css 202 B 0 B
build/block-library/blocks/rss/style-rtl.css 290 B 0 B
build/block-library/blocks/rss/style.css 290 B 0 B
build/block-library/blocks/search/editor-rtl.css 189 B 0 B
build/block-library/blocks/search/editor.css 189 B 0 B
build/block-library/blocks/search/style-rtl.css 359 B 0 B
build/block-library/blocks/search/style.css 362 B 0 B
build/block-library/blocks/separator/editor-rtl.css 99 B 0 B
build/block-library/blocks/separator/editor.css 99 B 0 B
build/block-library/blocks/separator/style-rtl.css 251 B 0 B
build/block-library/blocks/separator/style.css 251 B 0 B
build/block-library/blocks/shortcode/editor-rtl.css 512 B 0 B
build/block-library/blocks/shortcode/editor.css 512 B 0 B
build/block-library/blocks/site-logo/editor-rtl.css 440 B 0 B
build/block-library/blocks/site-logo/editor.css 441 B 0 B
build/block-library/blocks/site-logo/style-rtl.css 154 B 0 B
build/block-library/blocks/site-logo/style.css 154 B 0 B
build/block-library/blocks/social-link/editor-rtl.css 164 B 0 B
build/block-library/blocks/social-link/editor.css 165 B 0 B
build/block-library/blocks/social-links/editor-rtl.css 796 B 0 B
build/block-library/blocks/social-links/editor.css 795 B 0 B
build/block-library/blocks/social-links/style-rtl.css 1.32 kB 0 B
build/block-library/blocks/social-links/style.css 1.33 kB 0 B
build/block-library/blocks/spacer/editor-rtl.css 308 B 0 B
build/block-library/blocks/spacer/editor.css 308 B 0 B
build/block-library/blocks/spacer/style-rtl.css 48 B 0 B
build/block-library/blocks/spacer/style.css 48 B 0 B
build/block-library/blocks/table/editor-rtl.css 478 B 0 B
build/block-library/blocks/table/editor.css 478 B 0 B
build/block-library/blocks/table/style-rtl.css 485 B 0 B
build/block-library/blocks/table/style.css 485 B 0 B
build/block-library/blocks/tag-cloud/editor-rtl.css 118 B 0 B
build/block-library/blocks/tag-cloud/editor.css 118 B 0 B
build/block-library/blocks/tag-cloud/style-rtl.css 94 B 0 B
build/block-library/blocks/tag-cloud/style.css 94 B 0 B
build/block-library/blocks/template-part/editor-rtl.css 551 B 0 B
build/block-library/blocks/template-part/editor.css 550 B 0 B
build/block-library/blocks/term-description/editor-rtl.css 90 B 0 B
build/block-library/blocks/term-description/editor.css 90 B 0 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B 0 B
build/block-library/blocks/text-columns/editor.css 95 B 0 B
build/block-library/blocks/text-columns/style-rtl.css 166 B 0 B
build/block-library/blocks/text-columns/style.css 166 B 0 B
build/block-library/blocks/verse/style-rtl.css 87 B 0 B
build/block-library/blocks/verse/style.css 87 B 0 B
build/block-library/blocks/video/editor-rtl.css 569 B 0 B
build/block-library/blocks/video/editor.css 570 B 0 B
build/block-library/blocks/video/style-rtl.css 169 B 0 B
build/block-library/blocks/video/style.css 169 B 0 B
build/block-library/common-rtl.css 1.26 kB 0 B
build/block-library/common.css 1.26 kB 0 B
build/block-library/reset-rtl.css 506 B 0 B
build/block-library/reset.css 507 B 0 B
build/block-library/theme-rtl.css 692 B 0 B
build/block-library/theme.css 693 B 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/components/style-rtl.css 16.2 kB 0 B
build/components/style.css 16.2 kB 0 B
build/core-data/index.js 12.1 kB 0 B
build/customize-widgets/style-rtl.css 698 B 0 B
build/customize-widgets/style.css 699 B 0 B
build/data-controls/index.js 830 B 0 B
build/deprecated/index.js 738 B 0 B
build/dom-ready/index.js 576 B 0 B
build/edit-post/classic-rtl.css 454 B 0 B
build/edit-post/classic.css 454 B 0 B
build/edit-post/style-rtl.css 6.79 kB 0 B
build/edit-post/style.css 6.78 kB 0 B
build/edit-site/style-rtl.css 4.79 kB 0 B
build/edit-site/style.css 4.78 kB 0 B
build/edit-widgets/style-rtl.css 3.02 kB 0 B
build/edit-widgets/style.css 3.03 kB 0 B
build/editor/style-rtl.css 3.95 kB 0 B
build/editor/style.css 3.95 kB 0 B
build/escape-html/index.js 739 B 0 B
build/format-library/style-rtl.css 637 B 0 B
build/format-library/style.css 639 B 0 B
build/hooks/index.js 1.76 kB 0 B
build/html-entities/index.js 628 B 0 B
build/is-shallow-equal/index.js 710 B 0 B
build/keycodes/index.js 1.43 kB 0 B
build/list-reusable-blocks/style-rtl.css 629 B 0 B
build/list-reusable-blocks/style.css 628 B 0 B
build/media-utils/index.js 3.08 kB 0 B
build/navigation/index.js 2.85 kB 0 B
build/notices/index.js 1.07 kB 0 B
build/nux/style-rtl.css 718 B 0 B
build/nux/style.css 716 B 0 B
build/plugins/index.js 2 kB 0 B
build/priority-queue/index.js 791 B 0 B
build/react-i18n/index.js 924 B 0 B
build/reusable-blocks/style-rtl.css 225 B 0 B
build/reusable-blocks/style.css 225 B 0 B
build/url/index.js 1.95 kB 0 B
build/viewport/index.js 1.28 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/widgets/index.js 1.68 kB 0 B
build/wordcount/index.js 1.24 kB 0 B

compressed-size-action

@jasmussen
Copy link
Contributor

I'll give this a good review Monday, and I'll help push polish and tweaks and we'll make this shine.

But already from the demo video, this is looking incredible. Thank you!

@jasmussen
Copy link
Contributor

Took this one for a spin, this is what I see:

now

This is awesome! I'll see if I can push some things.

@jasmussen
Copy link
Contributor

One thing I noticed:

Screenshot 2021-03-22 at 11 04 50

There are two empty <p></p> tags being output on the frontend. This is most likely from wpautop wreaking havoc. Is there anything we can do here to remove those? I'll CSS them out with a todo note for now, but it's definitely something to fix. @gziolo if you have time, any thoughts?

@jasmussen
Copy link
Contributor

I rebased. Then I got the justifications to work again, editor and frontend.

From digging in, it appears that MicroModal in order to function as intended, adds quite a few wrapper elements. This is understandable, I added classes to each so that they are easier and cleaner to target:

wp-block-navigation__responsive-container
	wp-block-navigation__responsive-close
		wp-block-navigation__responsive-dialog
			wp-block-navigation__responsive-container-close
			wp-block-navigation__responsive-container-content

Note that every wrapping element we can remove, we should. Less is more. But for now I'm assuming they are necessary, so working with them as is.

@jasmussen
Copy link
Contributor

On the frontend, the close button is a button:

Screenshot 2021-03-22 at 13 13 42

However the menu icon is a div:

Screenshot 2021-03-22 at 13 13 52

Could the latter also be a button?

@jasmussen
Copy link
Contributor

Alright, I pushed a change so that you can now use the editor. A bit of work remains, and notably #29975 would fix a bunch of issues and benefit this PR in a rebase, but it's approaching a point where we can get a feel for both the editing and frontend interfaces, and start to course correct based on that.

menu

I left two comments about extra empty paragraphs showing up, and the menu icon on the frontend being a button. The former is not that urgent, it's something we can always get to, but the latter would be nice, and I think it has some accessibility boons also.

Overall, I think this is promising, I think that the option to allow the menu even on desktop, not just mobile, would be great.

With a few more CSS refinements to the editing interface (I'll push more stuff as soon as I can), I think we'll be that much closer to evaluating whether it's a good experience or not, to edit menu items inside the mobile full-screen view. One thing already stands out: if we show menu items as a vertical list inside the menu, but a horizontal list by default, does it make sense to show the horizontal movers? The alternative seems very complicated, so it's something to ponder.

@vcanales
Copy link
Member Author

vcanales commented Mar 22, 2021

Thank you for taking a look, and contributing! 🎉

There are two empty <p></p> tags being output on the frontend. This is most likely from wpautop wreaking havoc. Is there anything we can do here to remove those?

I wasn't able to reproduce this. I tried T19, TT1, and TT1 Blocks. I also tried earlier commits — before hiding the tags with CSS — to no avail. Are there any other specific actions that I should follow to see those elements?

Note that every wrapping element we can remove, we should. Less is more. But for now I'm assuming they are necessary, so working with them as is.

Yeah the extra markup is definitely something I'm keeping in mind — part of the learning process for this library will be to figure out which parts of the markup are essential, and which disposable.

Regarding the justification of the menu, I'm seeing something similar to what you demoed:

image

Are we going to move those items at the top somewhere else, such as adding some padding? And, should we keep the orientation of the menu as defined by the user, or will be force vertical on mobile?

@jasmussen
Copy link
Contributor

I wasn't able to reproduce this. I tried T19, TT1, and TT1 Blocks. I also tried earlier commits — before hiding the tags with CSS — to no avail. Are there any other specific actions that I should follow to see those elements?

That's curiuos... they disappeared!

I'll remove the CSS for now.

Yeah the extra markup is definitely something I'm keeping in mind — part of the learning process for this library will be to figure out which parts of the markup are essential, and which disposable.

💯

Are we going to move those items at the top somewhere else, such as adding some padding? And, should we keep the orientation of the menu as defined by the user, or will be force vertical on mobile?

Yes, this aspect I'm still figuring out. I'm not quite sure what's the best path forward. For this PR it probably is to make a somewhat opinionated design.

However the fact that right now, the same design applies for the menu itself, as the content inside the menu, means we don't really have that many layout options inside.

Question: Instead of moving the contents of the navigation block inside the burger menu, could we duplicate it and hide one or the other depending on context? That way I could choose a horizontal nav for desktop, and put a vertical nav inside the menu on mobile.

package.json Outdated Show resolved Hide resolved
webpack.config.js Outdated Show resolved Hide resolved
@jasmussen
Copy link
Contributor

Rebased.

@jasmussen
Copy link
Contributor

The empty P's came back for some reason:

Screenshot 2021-03-23 at 12 24 07

So I'm adding the CSS back for now.

This is my markup:

<!-- wp:paragraph -->
<p>This is the navigation block in a post</p>
<!-- /wp:paragraph -->

<!-- wp:navigation {"orientation":"horizontal","itemsJustification":"left"} -->
<!-- wp:page-list /-->

<!-- wp:navigation-link {"label":"Hey","type":"page","id":2,"url":"http://localhost:8888/?page_id=2","kind":"post-type"} -->
<!-- wp:navigation-link {"label":"Farewell, Arthur C. Clarke. 1917-2008","id":99,"url":"http://localhost:8888/?p=99"} /-->
<!-- /wp:navigation-link -->
<!-- /wp:navigation -->

<!-- wp:paragraph -->
<p>This is after the navigation block.</p>
<!-- /wp:paragraph -->

@jasmussen
Copy link
Contributor

One interesting thing I discovered — in my FSE theme, I already have a Navigation Menu block in my header template, and it picks up the menu feature excellently. But if I also include a navigation item in the page itself, for debugging or whatnot, it's the former menu that opens, regardless of where I click!

Funny edgecase we probably don't have to worry about, but figured I'd mention.

@vcanales
Copy link
Member Author

One interesting thing I discovered — in my FSE theme, I already have a Navigation Menu block in my header template, and it picks up the menu feature excellently. But if I also include a navigation item in the page itself, for debugging or whatnot, it's the former menu that opens, regardless of where I click!

That was happening because I'm using the same ID in the server-side generate markup at the moment — fixed with f22efde.

Question: Instead of moving the contents of the navigation block inside the burger menu, could we duplicate it and hide one or the other depending on context? That way I could choose a horizontal nav for desktop, and put a vertical nav inside the menu on mobile.

We could duplicate it — right now we are not actually moving anything inside the burger menu.

So, instead of printing just this markup, we could print that twice, or print different versions of it.

This is also useful if we want to turn responsiveness off — we can print the <nav /> without all the markup required for the modal.

@jasmussen
Copy link
Contributor

Alright, I've pushed a ton of stuff, and I feel like this one is super close to being ready to go. Outside of the todo items you have — the toggle, etc, I would suggest these two are worth looking more into:

  • where do those empty P tags come from?
  • if we are able to refactor away some of the container elements, that would just generally be great.

But user experiencewise, I think we're super close now:

status

I also made it so that color and style inheritance works:

color

The off-center navigation is caused by a separate bug that will be fixed once we rebase now that #29975 is merged.

So where are we with the above?

Essentially I figured that for this first version, we are going to be super opinionated about what's inside the navigation menu. Which means even if your menu is horizontal when not collapsed, it's going to be full screen and vertical when inside. This works now. I even made the block inert in the editor, when you are looking at the mobile menu contents.

As you can see with the color stuff — at the moment it inherits the color shown by the parent navigation, OR it shows white background with black text. Addressing #29963 separately will benefit this work.

All other styles are inherited and that works well too.

Submenu indentation and styles is also something I mean to fix separately.

We could duplicate it — right now we are not actually moving anything inside the burger menu.

This is also useful if we want to turn responsiveness off — we can print the

without all the markup required for the modal.

Per the opinionated design thoughts above, I think that for the time being we should embrace that the menu simply shows menu items in a prescriptive way. It allows us a great deal of simplicity with regards to making the burger menu be a toggle that just works, and we will always be able to revisit the decision in the future and expand.

That said, the next step for this PR to land is to add that toggle in the first place, and to ideally look at how that markup can be simplified if at all possible. There are some chunks of CSS here that I find slightly hacky, and it'd be great to do without, things that tweak the pointer-events.

But important to note: we should not be copying the menu just in order to make it separately editable — let's keep it simple for now. I.e. if I want to edit my menu, I have to only edit one menu. So copying would have to be something "behind the scenes" so to speak. Does that work for you?

One question emerged from todays session: what do we do about submenus inside the modal menu? Right now they work fine, it's just a vertical menu as shown in the GIF above, so whatever we do should be a followup. But do we want to explode those menus or keep them as hover/focus?

@jasmussen
Copy link
Contributor

Oh, and I'll help with the rebase, it's probably going to be a bit gnarly, but I'll come back to this.

@vcanales
Copy link
Member Author

But important to note: we should not be copying the menu just in order to make it separately editable — let's keep it simple for now. I.e. if I want to edit my menu, I have to only edit one menu.

This is definitely how it's working right now. The menu is not being copied — the one you see within the burger menu is the same as outside. The only JS magic going on is turning the is-menu-open class on and off.

That said, the next step for this PR to land is to add that toggle in the first place, and to ideally look at how that markup can be simplified if at all possible.

I'll be working on that toggle today. Even if we can't simplify the markup required for the modal, we will at the very least be able to print it conditionally — ie. only if responsiveness is on.

@jasmussen
Copy link
Contributor

Rebased. Hurray, it includes the margin fix. Things are coming together.

Copy link
Contributor

@gwwar gwwar left a comment

Choose a reason for hiding this comment

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

This is looking promising @vcanales ✨ . I took this out for some manual testing, and wanted to highlight a few use cases:

  1. Let's make sure the preview for tablet/mobile works as expected:

Screen Shot 2021-03-23 at 12 09 36 PM

  1. We currently can't add any items to a Navigation block when using a device with a small viewport:
mobile.mp4
  1. Triggering the touch event a few times on the 🍔 breaks the block:

Screen Shot 2021-03-23 at 12 12 02 PM

@jasmussen
Copy link
Contributor

Awesome review Kerry, thanks for taking a look. I'll see if I can help with the mobile preview.

We currently can't add any items to a Navigation block when using a device with a small viewport:

This was actually intentional, though since you stumble on it I realize that of course you should be able to edit, and I'll revisit.

The reasoning was that what you see inside the menu is our opinionated "flip a toggle and it works" view, and that you shouldn't be given the impression you can edit it when inside the menu, because in fact it's just a single menu, not a separate one for the menu. But the fact that you then can't edit it on mobile at all, obviously, is not great.

So we can either: let you edit the menu on mobile again. That does mean you get horizontal movers even though we force the menu to be vertical there. We should probably do this for V1.

Or, we can ponder how the editing experience of a menu is best on mobile, that may entail forcing you to use the List View entirely, but that requires a few additional features there, such as adding/removing items in the list view. This should probably be a V2.

@jasmussen
Copy link
Contributor

Gave this for a spin, and this is what I see:

here

Overall, this feels pretty dang solid in this latest iteration, and I think we should land it. Here's my line of thinking:

  • We know we need the feature.
  • As built, this works well as a single-toggle burger menu with fully accessible modal behavior.
  • We have a few followups to make (also this one). That includes making the feature more library agnostic. All of this should be feasible in a reasonable amount of time.
  • Because of those followups, the feature is off by default, but that default can easily be changed when we feel comfortable.
  • The added markup is server side rendered. Combined with off-by-default, this can be seen as a bit of a soft-launch, which should make the feature relatively safe.

Because of all those reasons, because this works well, I'm going to green check this one so we can land it and get going with the followups. I would encourage additional quick sanity checks, if available, but I also think it's time. Nice work Vicente, and thanks for the help Nik!

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Great work @vcanales and @jasmussen 💯 !

Let's 🚢

packages/block-library/src/navigation/index.php Outdated Show resolved Hide resolved
packages/block-library/src/navigation/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/navigation/frontend.js Outdated Show resolved Hide resolved
packages/block-library/src/navigation/index.php Outdated Show resolved Hide resolved
packages/block-library/src/navigation/index.php Outdated Show resolved Hide resolved
}

// Hide empty paragraph tags caused by wpautop.
// @todo, need to not output them in the first place.
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes were recently made to how empty paragraphs are displayed in the editor, so I thought it prudent to unresolve this thread and make sure these rules are really needed.

@mcsf
Copy link
Contributor

mcsf commented May 11, 2021

Great work here! Most of my comments above are nitpicks, but the one about hiding empty paragraphs is worth a second look. :)

@vcanales
Copy link
Member Author

Changes were recently made to how empty paragraphs are displayed in the editor, so I thought it prudent to unresolve this thread and make sure these rules are really needed.

I haven't been able to reproduce this issue on my end, so I'm removing the rules. We'll be taking a look after merging anyway :)

@vcanales
Copy link
Member Author

vcanales commented May 11, 2021

@mcsf Thanks for spotting all those details — there was some stuff leftover from the many changes this has gone through! I've addressed all of it.

Copy link
Contributor

@gwwar gwwar left a comment

Choose a reason for hiding this comment

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

This is very solid @vcanales ✨ Folks will really enjoy this one!

This is non-blocking, but I wanted to note a few areas we might want to tidy either here or in a follow up:

During Mobile Editing we can get confusing double models when previewing the menu + clicking on the global inserter:

modals.mp4

In the post-editor preview for mobile, shows all links instead of the hamburger:

Screen Shot 2021-05-11 at 1 30 28 PM Screen Shot 2021-05-11 at 1 29 55 PM

@vcanales
Copy link
Member Author

Thanks for raising these, @gwwar! These may take a moment to fix, so I've created an issue to track them both, as they're very closely related.

@vcanales vcanales merged commit b9ab1a8 into trunk May 12, 2021
@vcanales vcanales deleted the responsive-navigation branch May 12, 2021 15:49
@github-actions github-actions bot added this to the Gutenberg 10.7 milestone May 12, 2021
@jasmussen
Copy link
Contributor

🔥

@annezazu annezazu added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Sep 28, 2021
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 [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants