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

Style Navigation block differently for "mobile menu" #39142

Open
getdave opened this issue Mar 1, 2022 · 10 comments
Open

Style Navigation block differently for "mobile menu" #39142

getdave opened this issue Mar 1, 2022 · 10 comments
Labels
[Block] Navigation Affects the Navigation Block CSS Styling Related to editor and front end styles, CSS-specific issues. [Type] Enhancement A suggestion for improvement.

Comments

@getdave
Copy link
Contributor

getdave commented Mar 1, 2022

What problem does this address?

Currently any styles you apply to the Navigation block will also apply when it is in "mobile" mode. This is sometimes not desirable as the "mobile" menu may require different visual properties.

For example, if you align the navigation items to the right then the items in the mobile menu are also right aligned.

Screen.Capture.on.2022-03-01.at.16-35-20.mov

What is your proposed solution?

We could explore adding dedicated UI controls which only apply to the navigation when it is in mobile mode. That said, it might get complex if styles are not mutually exclusive so the mobile styles would have to take precedence.

Alternatively we could wait for a more robust responsive styling solution to land in Gutenberg which might allow blocks to define a standard means to style elements different based on viewport.

@getdave getdave added [Block] Navigation Affects the Navigation Block CSS Styling Related to editor and front end styles, CSS-specific issues. labels Mar 1, 2022
@jasmussen
Copy link
Contributor

It's good to have a dedicated issue for this one, thank you, I definitely agree.

I touched a bit on the following concept in this comment as well, but the way I see it, the contents of your mobile overlay is a blank canvas, and you should be able to put any block there, including columns and non navigation blocks.

One idea here is to leverage the same concept of saving inner blocks to a custom post type, as the navigation block does for its menu items. That is, have an entirely separate CPT for the contents of the modal. Here's an early mockup:

Editing navigation in isolation

One subgoal to accomplish here would be to ensure that the X to close the modal could sit exactly where the = menu item sits, so it feels like the same button. A root level padding solution (#35607) that is inherited by the modal (but user overridable) would be a good start for that.

Another idea that might help is, if the navigation block is used inside a Header template part, the entire template part is kept (duplicated) inside the modal overlay, with logo and open/close button. 
This would also let the burger icon transform into a close icon, which could be a nice touch.

@getdave
Copy link
Contributor Author

getdave commented Mar 2, 2022

Thanks for your excellent insight as always @jasmussen.

...the contents of your mobile overlay is a blank canvas, and you should be able to put any block there, including columns and non navigation blocks.

I think the idea of a wrapper into which you can place multiple Navigation blocks is a good idea. After all if the menus are drastically different them they shouldn't be the same <nav> anyway.

From a technical POV that's a challenge because it's going to require a separate "mobile overlay" block which has the ability to be populated differently in the editor canvas depending on the value of an inspector control toggle.

As a user I need to be able to switch between populating the "desktop" and "mobile" variations of the block. I have a video which explains how you can use x2 separate Navigation blocks and use CSS to show and hide them. It would be similar to this concept, except we'd need a design/UX solution for how users would interact with the block within the editor - that's the big challenge. How would you see that working?

@jasmussen
Copy link
Contributor

It would be similar to this concept, except we'd need a design/UX solution for how users would interact with the block within the editor - that's the big challenge. How would you see that working?

Yes, that's definitely similar.

My instinct is always to start with as little as possible, the shortcomings always have a way of presenting themselves when you do that, so you can address them one by one.

In this case, I would lean towards the mockup above: if you toggle the mobile menu to "always" and click the burger icon in the canvas, the very act of clicking that item would open up the modal with a new blank canvas, with any saving or creation of a dedicated overlay slot happening transparently in the background.

Some questions immediately present themselves:

  • Should we copy the navigation block you built before toggling "Always" into the overlay? Perhaps yes.
  • Should you be able to have a dedicated overlay also when the "Mobile" option is toggled? Maybe, but could also wait?
  • Is it enough to click the burger icon in the canvas to load the contents of the overlay in template isolation mode? Or should there also be a dedicated button in the inspector, "Edit overlay"?
  • Do I need to be able to swap out the contents of one overlay with another if one such exists, just like the nav block itself? Sure maybe.

All of those feel solvable, even if it is legitimately a big and challenging project. From an UX perspective, the biggest challenge I see with the approach is how this is compatible with editing the contents of the navigation block in isolation (i.e. #37950) since the UI may end up being very similar. My hope is that in practice it'll be fine: when it's collapsed to a burger button, it loads the overlay, when it's not, it loads the innerblocks of the parent nav instead.

@scruffian
Copy link
Contributor

We'd like to be able to style the overlay differently to the regular block, using theme.json. Unless we create a lot of extra properties in theme.json for the Navigation block, we're going to find it difficult to support all these different properties. However what if we made the overlay its own block? Then we can simply use the standard theme.json properties on that block...

@jasmussen
Copy link
Contributor

You suggested here that the overlay could be a block. Here we are discussing something adjacent, total customization of the contents of an overlay. In both cases we'd need theme.json integration — are the two tasks complementary?

@scruffian
Copy link
Contributor

Yeah I think they are basically the same thing!

@getdave
Copy link
Contributor Author

getdave commented Mar 15, 2022

I've been thinking about this as well and come to the same idea.

We could have some kind of wrapping block that allows you to toggle when the overlay is displayed (like the Nav block does today).

Then you could nest Nav blocks within that block. It could provide context to customise the behaviour.

@luisherranz
Copy link
Member

I think this could be elegantly solved without any ad-hoc implementation if:

  1. We add the ability to configure different layers/states using blocks.

  2. We allow any block to become a section capable of overwriting the global styles of their children.

@phil-sola
Copy link

This definitely needs reviving - the mobile menu is horrible out of the box and for a non-developer who may not know how to write CSS to style it any differently, that could be pretty offputting. I love the initial mockup and thought process from @jasmussen regarding a blank canvas to build out the overlay using blocks including columns, buttons, navigations.

Some really fantastic mobile overlay designs could be created directly in the block editor for everyone without needing to be a skilled developer to hack away at the current implementation.

@getdave
Copy link
Contributor Author

getdave commented Mar 31, 2023

@phil-sola I've previously recommended this as one of the features contributors should look to focus on.

@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Sep 14, 2023
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 CSS Styling Related to editor and front end styles, CSS-specific issues. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

6 participants