Skip to content
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

Change Navigation block markup on front end only #30551

Merged
merged 6 commits into from
Jul 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Change markup on front end
tellthemachines committed Jun 24, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit eeb888f38f0c6ab6df9a94bf9a6accaa283690a7
6 changes: 2 additions & 4 deletions packages/block-library/src/navigation/edit.js
Original file line number Diff line number Diff line change
@@ -167,15 +167,13 @@ function Navigation( {
</PanelBody>
) }
</InspectorControls>
<nav { ...blockProps }>
<nav { ...innerBlocksProps }>
<ResponsiveWrapper
id={ clientId }
onToggle={ setResponsiveMenuVisibility }
isOpen={ isResponsiveMenuOpen }
isResponsive={ attributes.isResponsive }
>
<ul { ...innerBlocksProps }></ul>
</ResponsiveWrapper>
></ResponsiveWrapper>
</nav>
</>
);
9 changes: 9 additions & 0 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
@@ -174,7 +174,16 @@ function render_block_core_navigation( $attributes, $content, $block ) {
);

$inner_blocks_html = '';
$is_list_open = false;
foreach ( $block->inner_blocks as $inner_block ) {
if ($inner_block->name === "core/navigation-link" && $is_list_open === false) {
$is_list_open = true;
$inner_blocks_html .= '<ul class="wp-block-navigation__container">';
}
if ($inner_block->name !== "core/navigation-link" && $inner_block->name !== "core/spacer" && $is_list_open === true) {
$is_list_open = false;
$inner_blocks_html .= '</ul>';
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, much closer to expected html markup. If we go with this approach, children of ul, still need to be wrapped in an li. (For example the spacer div).

Screen Shot 2021-04-26 at 8 59 14 AM

$inner_blocks_html .= $inner_block->render();
}