-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Navigation: Refactor mobile overlay breakpoints to JS #57520
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
Changes from 3 commits
2514157
e1c7aec
43a92c5
283db3f
b290e59
7bce629
da2006b
9de7b8c
c8f36c1
68d000a
d86c7e4
8813ca7
2a2c3d6
4b8a19e
42b8ae6
651130d
ad75338
b712646
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -361,16 +361,24 @@ private static function get_classes( $attributes ) { | |
| $text_decoration = $attributes['style']['typography']['textDecoration'] ?? null; | ||
| $text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration ); | ||
|
|
||
| // is-collapsed class is added to the navigation block when the menu is collapsed. | ||
| $is_collapsed_class = static::is_always_overlay( $attributes ) ? array( 'is-collapsed' ) : array(); | ||
|
|
||
| $classes = array_merge( | ||
| $colors['css_classes'], | ||
| $font_sizes['css_classes'], | ||
| $is_responsive_menu ? array( 'is-responsive' ) : array(), | ||
| $layout_class ? array( $layout_class ) : array(), | ||
| $text_decoration ? array( $text_decoration_class ) : array() | ||
| $text_decoration ? array( $text_decoration_class ) : array(), | ||
| $is_collapsed_class | ||
| ); | ||
| return implode( ' ', $classes ); | ||
| } | ||
|
|
||
| private static function is_always_overlay( $attributes ) { | ||
| return isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu']; | ||
| } | ||
|
|
||
| /** | ||
| * Get styles for the navigation block. | ||
| * | ||
|
|
@@ -397,16 +405,12 @@ private static function get_responsive_container_markup( $attributes, $inner_blo | |
| $colors = gutenberg_block_core_navigation_build_css_colors( $attributes ); | ||
| $modal_unique_id = wp_unique_id( 'modal-' ); | ||
|
|
||
| $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' : '', | ||
|
Comment on lines
-400
to
-409
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ); | ||
|
|
||
| $should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon']; | ||
|
|
@@ -504,7 +508,7 @@ private static function get_nav_wrapper_attributes( $attributes, $inner_blocks ) | |
| ); | ||
|
|
||
| if ( $is_responsive_menu ) { | ||
| $nav_element_directives = static::get_nav_element_directives( $should_load_view_script ); | ||
| $nav_element_directives = static::get_nav_element_directives( $should_load_view_script, $attributes ); | ||
| $wrapper_attributes .= ' ' . $nav_element_directives; | ||
| } | ||
|
|
||
|
|
@@ -517,7 +521,7 @@ private static function get_nav_wrapper_attributes( $attributes, $inner_blocks ) | |
| * @param bool $should_load_view_script Whether or not the view script should be loaded. | ||
| * @return string the directives for the navigation element. | ||
| */ | ||
| private static function get_nav_element_directives( $should_load_view_script ) { | ||
| private static function get_nav_element_directives( $should_load_view_script, $attributes ) { | ||
| if ( ! $should_load_view_script ) { | ||
| return ''; | ||
| } | ||
|
|
@@ -531,10 +535,16 @@ private static function get_nav_element_directives( $should_load_view_script ) { | |
| ), | ||
| JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | ||
| ); | ||
| return ' | ||
| $nav_element_directives = ' | ||
| data-wp-interactive=\'{"namespace":"core/navigation"}\' | ||
| data-wp-context=\'' . $nav_element_context . '\' | ||
| '; | ||
|
|
||
| if ( ! static::is_always_overlay( $attributes ) ) { | ||
| $nav_element_directives .= 'data-wp-watch="callbacks.initNav"'; | ||
| } | ||
|
|
||
| return $nav_element_directives; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -611,18 +611,16 @@ button.wp-block-navigation-item__content { | |
| } | ||
| } | ||
|
|
||
| @include break-small() { | ||
| &:not(.hidden-by-default) { | ||
| &:not(.is-menu-open) { | ||
| display: block; | ||
| width: 100%; | ||
| position: relative; | ||
| z-index: auto; | ||
| background-color: inherit; | ||
|
|
||
| .wp-block-navigation__responsive-container-close { | ||
| display: none; | ||
| } | ||
| :not(.is-collapsed) > & { | ||
| &:not(.is-menu-open) { | ||
scruffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| display: block; | ||
| width: 100%; | ||
| position: relative; | ||
| z-index: auto; | ||
| background-color: inherit; | ||
|
|
||
| .wp-block-navigation__responsive-container-close { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -686,10 +684,8 @@ button.wp-block-navigation-item__content { | |
| font-size: inherit; | ||
| } | ||
|
|
||
| &:not(.always-shown) { | ||
| @include break-small { | ||
| display: none; | ||
| } | ||
| :not(.is-collapsed) > & { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
scruffian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| display: none; | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.