Replies: 7 comments 20 replies
-
So, to see if I understand correctly, the problem we want to solve is when we are swapping from the desktop menu to the mobile one, or are we solving something else? Because another request that I've heard plenty of was a way to tag some blocks as mobile or desktop only since it's widespread that some elements are needed on only one of the versions of the menu. |
Beta Was this translation helpful? Give feedback.
-
What exactly is the limiting factor of the current system? The menu collapses into a hamburger too soon? Or what? Do we still want to keep this overlay behavior or do we want a menu that just makes room for itself? |
Beta Was this translation helpful? Give feedback.
-
As much as I’d like everything to be automated, I think defining a field to override the breakpoint in which the block switches to mobile would be the easiest method without using javascript. |
Beta Was this translation helpful? Give feedback.
-
I have had the additional thought that we need to consider the future of multi-lingual WordPress. This is stage 4 of the Gutenberg Roadmap after collaboration. A Navigation might work well at 700px breakpoint (container or viewport query) in English but be totally broken in another more verbose language. You could make the argument that in which case you'd set an artificially low breakpoint and just allow the English site to collapse to mobile layout "earlier", but that doesn't seem ideal. Something to consider. |
Beta Was this translation helpful? Give feedback.
-
To help the user establish the magic number, we could calculate in the editor the viewport width in which the layout breaks, maybe when they save the post to avoid JS on the front end. This approach could consider other languages, either by having a max width defined by the longest strings or a custom setting by language. The user could edit the value in the advanced settings. We don't have the full breakpoints available, but there is a preview for small screens. |
Beta Was this translation helpful? Give feedback.
-
It is impossibile to anticipate and so automate the "perfect" breakpoint. Also because a template can have multiple navigation blocks, with different position in the page and different number of nav items. Because of that they potentially need different breakpoint as well. Every instance of the block need their custom value to indicate "when" to switch to mobile or desktop layout. For the type of the attributes i think "string" in the code side, and in the UX side my idea is that the user can type:
|
Beta Was this translation helpful? Give feedback.
-
I had a go at creating a solution that relies only on CSS: https://codepen.io/scruffian/pen/ExOzByR This works for the most part, but the problem is that the navigation creates a horizontal scrollbar when it collapses. Maybe someone can find a way around that too... |
Beta Was this translation helpful? Give feedback.
-
This discussion is specifically about the layout behaviours of the Navigation block at different viewports.
Current State
The block currently hardcodes a breakpoint at
782px
at which point the block switches to "mobile" layout. This is only viable for the simplest of navigations - just try creating a Navigation with long labels or many items and it quickly breaks down.It's generally agreed that a better solution is needed.
Requirements
The block editor aspires to the principles of intrinsic design whereby the design system adapts automatically whatever viewport it is displayed within. For this reason contributors aim to avoid media queries where possible and instead rely on more intrinsic solutions such as container queries, flex/grid layout algorithms...etc.
Therefore we should avoid any solution which:
The rationale behind this is that once we add these solutions we would need to support them indefinitely. This means should a better solution become available then implementing it would become much more complex.
Moreover, such approaches require the user/developer to micro-manage the breakpoint which quickly breaks down in the face of changing numbers of menu items and their respective title lengths.
As a result, I propose that any solution we implement should meet the following requirements:
In user story form:
Avenues for exploration
Container Queries
Container Queries are supported by all major browsers and allow a developer to query the size of a container (as opposed to the entire viewport) and alter the CSS accordingly.
The major failing of this approach is that we would still need to query a specific container for a specific size and adjust the layout. That would therefore require a hardcoded value (relative or otherwise) to dictate the size at which the Navigation should adapt to "mobile" layout. This leaves us with the same problem at the current solution - namely that WordPress would need to pick an arbitrary breakpoint.
As a result I don't see this as viable.
JavaScript "Measuring"
The actual requirement is that the Navigation should adapt to "mobile" view based on a heuristic which combines:
I.e: where there is no longer sufficient space on the main flex axis to display all of the Navigation items, switch to mobile layout.
The only solution that would seem to be viable for this would be JavaScript based. Two options spring to mind:
Both options seem complex and would require significant exploration.
Request for Feedback
Contributors to the Navigation block would greatly appreciate feedback and input on the following:
Beta Was this translation helpful? Give feedback.
All reactions