-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation: Refactor mobile overlay breakpoints to JS #57520
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php |
@include break-small { | ||
display: none; | ||
} | ||
:not(.is-collapsed) > & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The >
selector is necessary because the class gets added to the nav element, but it does make the CSS a bit more complex.
Size Change: +675 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the concept is good here. We need to optimise the code and I've left suggestions on how we could do this 🤞
$is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu']; | ||
|
||
$responsive_container_classes = array( | ||
'wp-block-navigation__responsive-container', | ||
$is_hidden_by_default ? 'hidden-by-default' : '', | ||
implode( ' ', $colors['overlay_css_classes'] ), | ||
); | ||
$open_button_classes = array( | ||
'wp-block-navigation__responsive-container-open', | ||
$is_hidden_by_default ? 'always-shown' : '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this code is super confusing I'll be glad to see the back of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking much better now.
On testing I found that everything worked in the editor, but on the front of the site the Nav block set to Always
simply behaved as per the one set to Mobile.
Screen.Capture.on.2024-01-04.at.14-27-49.mp4
$nav_element_directives .= 'data-wp-init="callbacks.initNav"'; | ||
$nav_element_directives .= 'data-wp-class--is-collapsed="context.isCollapsed"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't these end up joined without spaces between the two directives?
@@ -37,3 +37,5 @@ export const SELECT_NAVIGATION_MENUS_ARGS = [ | |||
'wp_navigation', | |||
PRELOADED_NAVIGATION_MENUS_QUERY, | |||
]; | |||
|
|||
export const NAVIGATION_MOBILE_BREAKPOINT = 600; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we try and establish a consistent terminology here of "collapsed" as you have elsewhere?
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Co-authored-by: Dave Smith <getdavemail@gmail.com>
Thanks for the review @getdave. I think this is ready for another review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my testing this now seems to match up with behaviour on trunk
which is the desired outcome.
Left a few suggestions and also suggested getting more 👀 on the directives stuff as it's not my area of expertise.
lib/compat/wordpress-6.5/class-wp-navigation-block-renderer.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving based on #57520 (review)
Co-authored-by: Dave Smith <getdavemail@gmail.com>
I asked @luisherranz for a review off GitHub and he was happy with the approach :) |
✅ I updated the PHP Sync Tracking Issue for WP 6.5 to note this PR no longer requires a backport for WP 6.5. Why? Because the code was moved into the block-library package in #57979 and thus should be automatically handled by the packages sync process. cc @scruffian for confirmation. |
Confirming that is also my understanding :) |
This reverts commit 1b75cf6.
…" (#59149) Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: huubl <huubl@git.wordpress.org> Co-authored-by: cbirdsong <cbirdsong@git.wordpress.org> Co-authored-by: tomxygen <tomxygen@git.wordpress.org>
…" (#59149) Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: huubl <huubl@git.wordpress.org> Co-authored-by: cbirdsong <cbirdsong@git.wordpress.org> Co-authored-by: tomxygen <tomxygen@git.wordpress.org>
…" (#59149) Co-authored-by: c4rl0sbr4v0 <cbravobernal@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: DAreRodz <darerodz@git.wordpress.org> Co-authored-by: huubl <huubl@git.wordpress.org> Co-authored-by: cbirdsong <cbirdsong@git.wordpress.org> Co-authored-by: tomxygen <tomxygen@git.wordpress.org>
What?
This moves the logic for collapsing the navigation block to its overlay mode into Javascript.
Why?
This is needed as part of the work in #56781. I'm doing it in a different PR to keep that other PR smaller.
How?
Created a new class called 'is-collapsed' which handles the state of the whole block.
Testing Instructions