gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Navigation Overlay customisation via Template Parts

Open jasmussen opened this issue 4 years ago • 72 comments

Closes https://github.com/WordPress/gutenberg/issues/39142 and https://github.com/WordPress/gutenberg/issues/38201

Update

Following discussion in this Issue the aim is now to make it possible to define the overlay as a separate template part.

This will allow users to create a totally custom overlay and associate that with a given Navigation block via the template part's unique identifier.

As template parts are a blank canvas, it will be possible to have a different Navigation block within the template part itself which will solve the requirement whereby some users wish to have a different menu on "mobile".

Styling of this template will be achieved via https://github.com/WordPress/gutenberg/issues/40318.

This Issue is an "epic" and will need to be further broken down into it's constituent parts.

User Requirements

These are the high level requirements for the feature.

  • As a user...
    • I should be able to customise the visual styling of the overlay that appears for a given Navigation block.
    • I should see the Navigation block within my overlay is – by default – automatically kept in sync with menu used in the parent Navigation block.
    • I should be able to display different items in my overlay Navigation than those shown in the parent Navigation.
    • I should be able to style the Navigation block used in my overlay differently than the parent Navigation block.
    • I should not be able to make my overlay inaccessible to any user.
    • I should not be able to “break” the interactive functionality of the overlay using the editor.
    • I should be able to style my overlay via Global Styles.
  • As a theme creator...
    • I should be able to style my overlay via Theme JSON.
    • I should be able to provide a default navigation overlay template that will override the default one supplied by core.

Glossary

  • "Parent Navigation" - the navigation block which controls/triggers the overlay.

Issue update: Dec 23 To enable full customization of the contents of the Navigation overlay menu, it could become a separate block, with its own possible inner blocks, paddings, and global styles properties. To enable that, we could have the overlay button invoke a "focus mode" editing of the overlay block: Editing navigation in isolation

An additional affordance, for example for when the overlay only invokes on mobile, could be to add an Edit button in the Display panel of the inspector:

Navigation

The Overlay could be surfaced in the List View in the same style as position: sticky; group blocks in #30121:

List view i2

However it would not be a requirement for this issue, and if helpful to the development effort, there is no need to optimize for more than a single navigation menu with a single overlay that are directly tied together with no ability to replace one overlay with another.

There are technical questions to consider (please see this conversation), it would be good to consider these in light of template parts as well, since ideally the experience of entering and existing focused mode can feel similar.

The overlay block should be stylable in Global Styles (a la "core/navigation-overlay": {), so custom paddings and styles can be applied. This should also address #44182.

Figma.


Initial proposal (Issue updated Nov 7.)

As of #43576, it is now easier to position the little navigation overlay menu icon (burger menu) so that the close icon from the overlay will perfectly overlap it. To do that, you:

  • Ensure the navigation sits inside a wide container block, which itself is inside a container that inherits layout
  • Ensure that the navigation menu sits aligned to the top/right of this container and has no additional padding or margin
  • The theme opts into root paddings (https://github.com/WordPress/gutenberg/pull/42085), by adding "useRootPaddingAwareAlignments": true in theme.json under settings, and paddings to go with that either in global styles or under styles > spacing.

The result is that the menu icon will sit in the exact place where the close icon will sit:

currently

This is working well. However, it works mainly well for themes that look good with the menu icon in the extreme top right corners. Other designs would benefit from a little vertical padding above the menu item, to optically balance, for example, a site title with the burger icon. Like so:

allow padding customization in overlay

At the moment, all 4 paddings for the overlay menu are set to be the same as any root padding applied to your site. It would be nice to be able to customize these paddings further, by simply surfacing this padding control for the overlay menu, so for example the top padding could be set just a bit higher, to match any custom header padding, making things line up.

For starters, this could be implemented in theme.json only, and a padding control for the overlay could be added to the block at a later point.

jasmussen avatar Sep 05 '22 10:09 jasmussen

CC: @WordPress/gutenberg-design @MaggieCabrera — is this feasible in short order, you think?

jasmussen avatar Sep 05 '22 10:09 jasmussen

How would you target the overlay with just theme.json, do you think? right now we have control over the padding of the whole block, not the overlay. I don't think it's easy enough to do in time for 6.1 I'm afraid.

MaggieCabrera avatar Sep 05 '22 11:09 MaggieCabrera

Thanks for looking. Good question, my initial instinct would be something like this:

			"core/navigation": {
				"typography": {
					"fontSize": "var(--wp--preset--font-size--medium)",
					"lineHeight": "var(--wp--preset--font-size--large)"
				}, 
				"overlay": {
					"spacing": {
						"padding": {
							"top": "80px",
							"right": "40px",
							"bottom": "80px",
							"left": "40px"
						}
					}
				}
			},

However if the overlay itself becomes a separate block, that would change this. 🤔

jasmussen avatar Sep 05 '22 12:09 jasmussen

yeah, I wonder about that as well, @getdave @scruffian @draganescu is that what's going to happen with the overlay in the future?

MaggieCabrera avatar Sep 05 '22 13:09 MaggieCabrera

Perhaps it would be something that we either

  • Select to "edit in isolation" like we edit template parts.
  • Edit in place, but hide until selected (like WooCommerce empty and filled carts).

I think the solution could be used in other places like for the "no results" block.

carolinan avatar Sep 06 '22 06:09 carolinan

I like the idea that we can edit in isolation, and I previously explored a mockup to that effect:

Editing navigation in isolation

I think that mockup may be posted on one of the open issues. The hope with this issue, however, was finding a solution that could live in theme.json for the near future, and then be opened up for UI editing later on.

jasmussen avatar Sep 06 '22 06:09 jasmussen

The issue I see with introducing an "overlay" property in the navigation block is that it would be specific to that block. At present all the properties we have are valid for all blocks. IMO the simplest approach here is simply to make the overlay a different block.

scruffian avatar Sep 06 '22 07:09 scruffian

This issue has been updated to tackle the idea of making the overlay menu a separate block that can be edited in focus mode. If you're subscribed, it could use both technical and design feedback!

jasmussen avatar Oct 06 '22 10:10 jasmussen

I think it should be a template part, not a separate block.

mtias avatar Oct 07 '22 10:10 mtias

I agree w/ @mtias because I think it's a good idea:

  • we keep how the block works now as a default
  • if the theme or the user creates a navigation-overlay template part the block automatically uses that

Whill this template part be able to include the block that references it? 😁

draganescu avatar Oct 07 '22 11:10 draganescu

The point of it being a separate block is so it has different customization options: the overlay usually doesn't share the same spacing options or typography settings as the desktop navigation does. How can we accomplish that with template parts?

MaggieCabrera avatar Oct 10 '22 08:10 MaggieCabrera

A template part seems like a more flexible way to go. I see use cases where the navigation overlay needs to contain other elements than menus. it could be

  • a login/logout button
  • a search field

Or maybe multiple menus. Maybe the desktop site has more than one menu, and instead creating a third specific mobile menu you want the mobile menu to combine the two desktop menus in order to reduce maintenance burden for editors.

Retrofitterdk avatar Oct 10 '22 09:10 Retrofitterdk

@MaggieCabrera with https://github.com/WordPress/gutenberg/issues/40318

mtias avatar Oct 10 '22 10:10 mtias

With the addition of https://github.com/WordPress/gutenberg/issues/40318 the template part route seems like a good choice. The obvious downside would be that we'll need to find a way to making it obvious/easy for the user to know that they need to do this in order to create a different overlay.

getdave avatar Oct 11 '22 08:10 getdave

Let's move this to the dev category! @getdave feel free to update the title to reflect the template part mechanics. 🙏

jasmussen avatar Oct 14 '22 07:10 jasmussen

@jasmussen I've gone ahead and updated the title and the description to reflect the "template part" route.

However, I don't see this as being ready for dev in the sense that we don't have a clear UX for how the interactions for creating and associating template parts with a given Navigation block will work. There are lots of edge cases to be explored and I believe this will be quicker and more effective to explore in Figma than in code.

This project will have a good degree of complexity involved and in order to be as efficient as possible it would be very helpful if we could (collectively) explore this model in more detail before we proceed.

Do you agree?

getdave avatar Oct 14 '22 08:10 getdave

Sure, can you list out a couple of flows that you'd like to see outlined better? The current mockups assume as little UI as possible, as a goal to strive for: you toggle the "Mobile" or "Always" part of the segmented control, and boom: now you have a separately editable overlay with no other action needing to be taken. Do we need user-steps in between?

jasmussen avatar Oct 14 '22 08:10 jasmussen

Should the navigation overlay appear in the template parts list? Does it need a new semantic area so that you can have multiple overlays for different navigation menus?

jameskoster avatar Oct 18 '22 14:10 jameskoster

It should appear in the template parts list; I don't think it should be a semantic area.

mtias avatar Oct 18 '22 14:10 mtias

Just to connect a dot in case it affects implementation, this may not be the only template part that core will provide, and themes be able to override. See: https://github.com/WordPress/gutenberg/issues/44362

jameskoster avatar Oct 18 '22 15:10 jameskoster