@@ -697,14 +697,10 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
697697 if ( ! empty ( $ attributes ['overlay ' ] ) ) {
698698 // Get blocks from the overlay template part.
699699 $ overlay_blocks = static ::get_overlay_blocks_from_template_part ( $ attributes ['overlay ' ], $ attributes );
700- // Check if overlay contains a navigation-overlay-close block.
701- $ has_custom_overlay_close_block = block_core_navigation_block_tree_has_block_type (
702- $ overlay_blocks ,
703- 'core/navigation-overlay-close ' ,
704- array ( 'core/navigation ' ) // Skip navigation blocks, as they cannot contain an overlay close block
705- );
706700 // Render template part blocks directly without navigation container wrapper.
707701 $ overlay_blocks_html = static ::get_template_part_blocks_html ( $ overlay_blocks );
702+ // Check if overlay contains a navigation-overlay-close block (detect in rendered HTML so it works with patterns).
703+ $ has_custom_overlay_close_block = block_core_navigation_overlay_html_has_close_block ( $ overlay_blocks_html );
708704 // Add Interactivity API directives to the overlay close block if present.
709705 if ( $ has_custom_overlay_close_block && $ is_interactive ) {
710706 $ tags = new WP_HTML_Tag_Processor ( $ overlay_blocks_html );
@@ -1094,6 +1090,28 @@ function block_core_navigation_get_inner_blocks_from_unstable_location( $attribu
10941090 }
10951091}
10961092
1093+ /**
1094+ * Checks if the overlay HTML contains a navigation-overlay-close block.
1095+ *
1096+ * Uses WP_HTML_Tag_Processor to detect the close button in rendered output,
1097+ * so it works when the overlay uses patterns (pattern content is rendered at
1098+ * output time, not in the block tree).
1099+ *
1100+ * @since 7.0.0
1101+ *
1102+ * @param string $html The rendered overlay HTML.
1103+ * @return bool True if a close button element is found.
1104+ */
1105+ function block_core_navigation_overlay_html_has_close_block ( $ html ) {
1106+ $ tags = new WP_HTML_Tag_Processor ( $ html );
1107+ return $ tags ->next_tag (
1108+ array (
1109+ 'tag_name ' => 'BUTTON ' ,
1110+ 'class_name ' => 'wp-block-navigation-overlay-close ' ,
1111+ )
1112+ );
1113+ }
1114+
10971115/**
10981116 * Add Interactivity API directives to the navigation-overlay-close block
10991117 * markup using the Tag Processor.
0 commit comments