Skip to content

Commit e5a5b71

Browse files
getdavejeryj
authored andcommitted
Gate desktop container wrapper behind navigation overlay experiment
- Add is_overlay_experiment_enabled() helper to check experiment status - Make desktop container wrapper conditional on experiment being enabled - Maintain backward compatibility: without experiment, desktop navigation markup remains unchanged - Prevents CSS/layout issues for users without the experiment enabled - Add comprehensive comment explaining why this is gated
1 parent a5972fb commit e5a5b71

File tree

1 file changed

+32
-6
lines changed
  • packages/block-library/src/navigation

1 file changed

+32
-6
lines changed

packages/block-library/src/navigation/index.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ class WP_Navigation_Block_Renderer {
4141
*/
4242
private static $seen_menu_names = array();
4343

44+
/**
45+
* Returns whether the navigation overlay experiment is enabled.
46+
*
47+
* @since 6.5.0
48+
*
49+
* @return bool Returns whether the navigation overlay experiment is enabled.
50+
*/
51+
private static function is_overlay_experiment_enabled() {
52+
$gutenberg_experiments = get_option( 'gutenberg-experiments' );
53+
return $gutenberg_experiments && array_key_exists( 'gutenberg-customizable-navigation-overlays', $gutenberg_experiments );
54+
}
55+
4456
/**
4557
* Returns whether or not this is responsive navigation.
4658
*
@@ -712,14 +724,28 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
712724

713725
// Build the content markup with desktop and overlay containers.
714726
$content_markup = '';
727+
$is_overlay_experiment_enabled = static::is_overlay_experiment_enabled();
728+
715729
if ( $has_overlay && ! empty( $overlay_blocks_html ) ) {
716730
// Render both desktop and overlay blocks in separate containers.
717-
$content_markup = sprintf(
718-
'<div class="wp-block-navigation__desktop-container">%1$s</div>
719-
<div class="wp-block-navigation__overlay-container" aria-hidden="true">%2$s</div>',
720-
$inner_blocks_html,
721-
$overlay_blocks_html
722-
);
731+
// IMPORTANT: The desktop container wrapper is gated behind the experiment to ensure
732+
// backward compatibility. Without the experiment enabled, the desktop navigation
733+
// should not be wrapped in a container div, maintaining the exact same markup structure
734+
// as before this feature. This prevents any potential CSS or layout issues for users
735+
// who don't have the experiment enabled.
736+
if ( $is_overlay_experiment_enabled ) {
737+
$content_markup = sprintf(
738+
'<div class="wp-block-navigation__desktop-container">%1$s</div>
739+
<div class="wp-block-navigation__overlay-container" aria-hidden="true">%2$s</div>',
740+
$inner_blocks_html,
741+
$overlay_blocks_html
742+
);
743+
} else {
744+
// Experiment not enabled: Don't wrap desktop navigation to maintain backward compatibility.
745+
// Render desktop blocks without wrapper (maintains exact same markup as before this feature).
746+
// Note: UI prevents overlay selection when experiment is off, but handle gracefully if attribute exists.
747+
$content_markup = $inner_blocks_html;
748+
}
723749
} else {
724750
// No overlay selected, use existing behavior.
725751
$content_markup = $inner_blocks_html;

0 commit comments

Comments
 (0)